Submission #1005111


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

const int mod = 1e9 + 7;

int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}

int sub(int x, int y) {
  return add(x, mod - y);
}

int mul(ll x, ll y) {
  return x * y % mod;
}

int uul(int &x, int y) {
  return x = mul(x, y);
}

void udd(int &x, int y) {
  x = add(x, y);
}

int bin(int x, int to) {
  int y = 1;
  while (to) {
    if (to & 1)
      y = mul(x, y);
    x = mul(x, x);
    to >>= 1;
  }
  return y;
}

int inv(int x) {
  assert(x != 0);
  return bin(x, mod - 2);
}

const int M = 307;

bitset<M> c[M];

int n, k;
int d[M][M][M];
int pw[M];

void pre() {
  for (int i = 0; i < M; ++i)
    pw[i] = bin(2, i);

  for (int n = 0; n < M; ++n) {
    d[n][0][0] = 1;
    for (int k = 0; k + 1 < M; ++k)
      for (int r = 0; r + 1 < M; ++r) {
        int nx = pw[r];
        int ny = sub(pw[n], nx);
        int cur = d[n][k][r];
        udd(d[n][k + 1][r], mul(nx, cur));
        udd(d[n][k + 1][r + 1], mul(ny, cur));
      }
  }
}

void read() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      int x;
      cin >> x;
      c[i][j] = x;
    }
}

void gaub() {
  int last = 0;
  for (int i = 0; i < n; ++i) {
    int x = -1;
    for (int j = last; j < n; ++j)
      if (c[j][i]) {
        x = j;
      }

    if (x == -1)
      continue;

    swap(c[last], c[x]);
    for (int j = last + 1; j < n; ++j)
      if (c[j][i])
        c[j] ^= c[last];

    ++last;
  }

  k = last;

  cerr << "k = " << k << endl;
}


void kill() {
  int ans = 0;

  for (int m = k; m <= n; ++m) {
    int cnt = mul(d[n][n][m], d[m][n][k]);
    uul(cnt, bin(2, (n - m) * n));
    udd(ans, cnt);
  }

  uul(ans, inv(d[n][n][k]));


  cout << ans << endl;
}


int main() {
#ifdef LOCAL
  assert(freopen("h.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  pre();
  read();
  gaub();
  kill();
}

Submission Info

Submission Time
Task H - AB=C Problem
User Arterm
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 2092 Byte
Status AC
Exec Time 410 ms
Memory 113280 KB

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 403 ms 113280 KB
001.txt AC 404 ms 113280 KB
002.txt AC 403 ms 113280 KB
003.txt AC 401 ms 113280 KB
004.txt AC 402 ms 113280 KB
005.txt AC 404 ms 113280 KB
006.txt AC 405 ms 113280 KB
007.txt AC 403 ms 113280 KB
008.txt AC 403 ms 113280 KB
009.txt AC 404 ms 113280 KB
010.txt AC 402 ms 113280 KB
011.txt AC 403 ms 113280 KB
012.txt AC 402 ms 113280 KB
013.txt AC 403 ms 113280 KB
014.txt AC 404 ms 113280 KB
015.txt AC 405 ms 113280 KB
016.txt AC 403 ms 113280 KB
017.txt AC 405 ms 113280 KB
018.txt AC 401 ms 113280 KB
019.txt AC 401 ms 113280 KB
020.txt AC 405 ms 113280 KB
021.txt AC 409 ms 113280 KB
022.txt AC 403 ms 113280 KB
023.txt AC 408 ms 113280 KB
024.txt AC 408 ms 113280 KB
025.txt AC 410 ms 113280 KB
026.txt AC 409 ms 113280 KB
027.txt AC 410 ms 113280 KB
028.txt AC 410 ms 113280 KB
029.txt AC 410 ms 113280 KB
030.txt AC 409 ms 113280 KB
031.txt AC 409 ms 113280 KB
032.txt AC 409 ms 113280 KB
033.txt AC 408 ms 113280 KB
034.txt AC 409 ms 113280 KB
035.txt AC 408 ms 113280 KB
036.txt AC 408 ms 113280 KB
037.txt AC 409 ms 113280 KB
038.txt AC 408 ms 113280 KB
039.txt AC 409 ms 113280 KB
example0.txt AC 405 ms 113280 KB
example1.txt AC 402 ms 113280 KB