Submission #1016418


Source Code Expand

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

const int maxn = 305, mod = (int) 1e9 + 7;
int n;
int c[maxn][maxn];
int p2[maxn * maxn];
int bas[maxn][maxn];
int cnt[maxn][maxn];

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int mul(int a, int b) {
  return (long long) a * b % mod;
}

pair<int, int> gcd(int a, int b) {
  if (!b) {
    return make_pair(1, 0);
  }
  pair<int, int> p = gcd(b, a % b);
  return make_pair(p.second, p.first - (a / b) * p.second);
}

int inv(int x) {
  int res = gcd(x, mod).first;
  if (res < 0) {
    res += mod;
  }
  return res;
}

void precalc() {
  p2[0] = 1;
  for (int i = 1; i < maxn * maxn; i++) {
    p2[i] = mul(p2[i - 1], 2);
  }
  for (int n = 0; n < maxn; n++) {
    bas[n][0] = 1;
    for (int k = 1; k <= n; k++) {
      int tomul = p2[n];
      add(tomul, mod - p2[k - 1]);
      bas[n][k] = mul(bas[n][k - 1], tomul);
    }
  }
  for (int n = 0; n < maxn; n++) {
    for (int k = 0; k < maxn; k++) {
      if (k > n) {
        cnt[n][k] = 0;
        continue;
      }
      if (k == 0) {
        cnt[n][k] = 1;
        continue;
      }
      cnt[n][k] = mul(cnt[n - 1][k], p2[k]);
      int tomul = p2[k];
      add(tomul, mod - 1);
      add(cnt[n][k], mul(cnt[n - 1][k - 1], mul(tomul, p2[k - 1])));
    }
  }
}

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &c[i][j]);
    }
  }
  return true;
}

int getRank() {
  for (int i = 0; i < n; i++) {
    int x = -1, y = -1;
    for (int j = i; j < n; j++) {
      for (int k = i; k < n; k++) {
        if (c[j][k]) {
          x = j;
          y = k;
        }
      }
    }
    if (x == -1) {
      return i;
    }
    for (int j = i; j < n; j++) {
      swap(c[i][j], c[x][j]);
    }
    for (int j = i; j < n; j++) {
      swap(c[j][i], c[j][y]);
    }
    for (int j = i + 1; j < n; j++) {
      if (!c[j][i]) {
        continue;
      }
      for (int k = i; k < n; k++) {
        c[j][k] ^= c[i][k];
      }
    }
    for (int j = i + 1; j < n; j++) {
      c[i][j] = 0;
    }
  }
  return n;
}

void solve() {
  int k = getRank();
  eprintf("k = %d\n", k);
  int res = 0;
  for (int l = 0; l <= n - k; l++) {
    int cur = cnt[n - k][l];
    cur = mul(mul(cur, mul(bas[n][k + l], inv(bas[l][l]))), p2[n * (n - k - l)]);
    add(res, cur);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Submission Info

Submission Time
Task H - AB=C Problem
User aid
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 3346 Byte
Status AC
Exec Time 29 ms
Memory 1664 KB

Compile Error

./Main.cpp: In function ‘int read()’:
./Main.cpp:104:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &c[i][j]);
                            ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1500 / 1500
Status
AC × 2
AC × 42
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 5 ms 1280 KB
001.txt AC 5 ms 1280 KB
002.txt AC 5 ms 1280 KB
003.txt AC 5 ms 1280 KB
004.txt AC 5 ms 1280 KB
005.txt AC 5 ms 1280 KB
006.txt AC 5 ms 1408 KB
007.txt AC 5 ms 1408 KB
008.txt AC 5 ms 1280 KB
009.txt AC 5 ms 1280 KB
010.txt AC 5 ms 1408 KB
011.txt AC 5 ms 1280 KB
012.txt AC 5 ms 1280 KB
013.txt AC 5 ms 1280 KB
014.txt AC 8 ms 1536 KB
015.txt AC 7 ms 1536 KB
016.txt AC 6 ms 1408 KB
017.txt AC 9 ms 1536 KB
018.txt AC 6 ms 1408 KB
019.txt AC 5 ms 1408 KB
020.txt AC 9 ms 1536 KB
021.txt AC 26 ms 1664 KB
022.txt AC 6 ms 1408 KB
023.txt AC 17 ms 1664 KB
024.txt AC 29 ms 1664 KB
025.txt AC 27 ms 1664 KB
026.txt AC 28 ms 1664 KB
027.txt AC 25 ms 1664 KB
028.txt AC 14 ms 1664 KB
029.txt AC 27 ms 1664 KB
030.txt AC 27 ms 1664 KB
031.txt AC 26 ms 1664 KB
032.txt AC 13 ms 1664 KB
033.txt AC 28 ms 1664 KB
034.txt AC 12 ms 1664 KB
035.txt AC 9 ms 1664 KB
036.txt AC 29 ms 1664 KB
037.txt AC 24 ms 1664 KB
038.txt AC 13 ms 1664 KB
039.txt AC 27 ms 1664 KB
example0.txt AC 5 ms 1280 KB
example1.txt AC 5 ms 1408 KB