fork(1) 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. uint64_t xorshift64(uint64_t* state)
  37. {
  38. uint64_t x = *state;
  39. x^= x << 13;
  40. x^= x >> 7;
  41. x^= x << 17;
  42. *state = x;
  43. return x;
  44. }
  45.  
  46. #include <random>
  47. int main() {
  48. int n=900;
  49.  
  50. uint64_t state = time(NULL);
  51. for (int i = 0; i < 100; ++i) {
  52. int m = n + i;
  53. vector<bitset<N>> matrix(m);
  54. for (int i = 0; i < m; ++i) {
  55. for (int j = 0; j < m; ++j) {
  56. matrix[i][j] = xorshift64(&state) % 2;
  57. }
  58. }
  59.  
  60. cout << m << " "<< GetRank(matrix) << "\n";
  61. }
  62. }
  63.  
Success #stdin #stdout 0.57s 15464KB
stdin
Standard input is empty
stdout
900 64
901 64
902 64
903 64
904 64
905 64
906 64
907 64
908 64
909 64
910 64
911 64
912 64
913 64
914 64
915 64
916 64
917 64
918 64
919 64
920 64
921 64
922 64
923 64
924 64
925 64
926 64
927 64
928 64
929 64
930 64
931 64
932 64
933 64
934 64
935 64
936 64
937 64
938 64
939 64
940 64
941 64
942 64
943 64
944 64
945 64
946 64
947 64
948 64
949 64
950 64
951 64
952 64
953 64
954 64
955 64
956 64
957 64
958 64
959 64
960 64
961 64
962 64
963 64
964 64
965 64
966 64
967 64
968 64
969 64
970 64
971 64
972 64
973 64
974 64
975 64
976 64
977 64
978 64
979 64
980 64
981 64
982 64
983 64
984 64
985 64
986 64
987 64
988 64
989 64
990 64
991 64
992 64
993 64
994 64
995 64
996 64
997 64
998 64
999 64