fork(4) download
  1. #include <vector>
  2. #include <bitset>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. const int N = 1024;
  8.  
  9. int GetRank(vector<bitset<N>> matrix) {
  10. const int n = matrix.size();
  11. int r = 0;
  12. vector<bool> used(n);
  13.  
  14. for (int col = 0; col < n; ++col) {
  15. int pivot = -1;
  16. for (int row = 0; row < n; ++row) {
  17. if (!used[row] && matrix[row][col]) {
  18. pivot = row; break;
  19. }
  20. }
  21.  
  22. if (pivot == -1) { continue; }
  23. used[pivot] = true;
  24. ++r;
  25.  
  26. for (int r = 0; r < n; ++r) {
  27. if (r == pivot) { continue; }
  28. if (matrix[r][col]) {
  29. matrix[r] ^= matrix[pivot];
  30. }
  31. }
  32. }
  33. return r;
  34. }
  35.  
  36. int main() {
  37. int n=900;
  38.  
  39. srand(time(NULL));
  40.  
  41. for (int i = 0; i < 100; ++i) {
  42. int m = n + i;
  43. vector<bitset<N>> matrix(m);
  44. for (int i = 0; i < m; ++i) {
  45. for (int j = 0; j < m; ++j) {
  46. matrix[i][j] = rand() % 2;
  47. }
  48. }
  49.  
  50. cout << m << " "<< GetRank(matrix) << "\n";
  51. }
  52. }
  53.  
Success #stdin #stdout 1.51s 15464KB
stdin
Standard input is empty
stdout
900 496
901 527
902 496
903 527
904 496
905 527
906 496
907 527
908 496
909 527
910 496
911 527
912 496
913 527
914 496
915 527
916 496
917 527
918 496
919 527
920 496
921 527
922 496
923 527
924 496
925 527
926 496
927 527
928 496
929 527
930 496
931 527
932 496
933 527
934 496
935 527
936 496
937 527
938 496
939 527
940 496
941 527
942 496
943 527
944 496
945 527
946 496
947 527
948 496
949 527
950 496
951 527
952 496
953 527
954 496
955 527
956 496
957 527
958 496
959 527
960 496
961 527
962 496
963 527
964 496
965 527
966 496
967 527
968 496
969 527
970 496
971 527
972 496
973 527
974 496
975 527
976 496
977 527
978 496
979 527
980 496
981 527
982 496
983 527
984 496
985 527
986 496
987 527
988 496
989 527
990 496
991 527
992 496
993 527
994 496
995 527
996 496
997 527
998 496
999 527