Submission #1024078


Source Code Expand

#include <algorithm>

#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>

#include <vector>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const llint mod = 1e9 + 7;
const int MAXN = 321;

llint pot2[MAXN];
int dp[MAXN][MAXN][MAXN]; // rows, columns, rank

llint indep_vects(int dim, int k) {
  llint ans = 1;
  REP(i, k) {
    ans *= (pot2[dim] - pot2[i] + mod) % mod;
    ans %= mod;
  }
  return ans;
}

llint power_mod(llint b, llint e) {
  llint ans = 1;
  llint p2 = b;
  for (; e; e >>= 1) {
    if (e&1) ans = ans*p2 % mod;
    p2 = p2*p2 % mod;
  }
  return ans;
}

llint mod_inv(llint x) {
  return power_mod(x, mod-2);
}

llint k_subspaces(int dim, int k) {
  return (llint)dp[dim][dim][dim-k] * mod_inv( indep_vects(dim, dim-k) ) % mod;
}

int get_matrix_rank(int C[][MAXN], int n) {
  int rank = 0;

  REP(j, n) {
    int tmp_row = -1;
    FOR(i, rank, n) if (C[i][j] != 0) { tmp_row = i; break; }
    if (tmp_row == -1) {
      
    } else {
      REP(k, n) swap(C[rank][k], C[tmp_row][k]);
      assert(C[rank][j] == 1);

      REP(r2, n) if (r2 != rank)
        if (C[r2][j])
          REP(k, n)
            C[r2][k] ^= C[rank][k];
            
      ++rank;
    }
  }

  return rank;
}

int main(void) {
  pot2[0] = 1;
  for (int i = 1; i < MAXN; ++i) pot2[i] = (pot2[i-1] * 2) % mod;

  int n;
  static int C[MAXN][MAXN];
  scanf("%d", &n);
  REP(i, n) REP(j, n) scanf("%d", C[i]+j);

  //  TRACE(n);
  //  TRACE(pot2[0] _ pot2[10]);
  
  //  TRACE(power_mod(2, 0));
  //  TRACE(power_mod(2, 1));
  //  TRACE(power_mod(2, 2));
  //  TRACE(power_mod(2, 3));

  //  TRACE(indep_vects(n, 0));
  //  TRACE(indep_vects(n, 1));
  //  TRACE(indep_vects(n, 2));
  //  TRACE(indep_vects(n, 3));

  //  TRACE(mod_inv(5) _ 5 * mod_inv(5) % mod);

  memset(dp, 0, sizeof dp);
  REP(rows, MAXN-1) {
    dp[rows][0][0] = 1;

    REP(c, MAXN-1) REP(r, MAXN-1) {
      if (dp[rows][c][r] == 0) continue;

      dp[rows][c+1][r+1] += (pot2[rows] - pot2[r] + mod) % mod * (llint)dp[rows][c][r] % mod;
      dp[rows][c+1][r+1] %= mod;

      dp[rows][c+1][r] += pot2[r] * (llint)dp[rows][c][r] % mod;
      dp[rows][c+1][r] %= mod;
    }
  }

  int rankC = get_matrix_rank(C, n);
  //  TRACE(rankC);
  //  TRACE(dp[n][n][n]);

  //  TRACE(k_subspaces(n, 0));
  //  TRACE(k_subspaces(n, 1));
  //  TRACE(k_subspaces(n, 2));
  //  TRACE(k_subspaces(n, 3));

  int kerC = n - rankC;
  llint ans = 0;
  FOR(kerB, 0, kerC+1) {
    llint val = k_subspaces(kerC, kerB);
    val = val*indep_vects(n, n-kerB) % mod;
    val = val*power_mod(pot2[n], kerB) % mod;
    ans = (ans + val) % mod;

    //    TRACE(kerB _ val);
  }

  printf("%lld\n", ans);
  return 0;
}

Submission Info

Submission Time
Task H - AB=C Problem
User Zuza
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 2996 Byte
Status AC
Exec Time 282 ms
Memory 129792 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:83:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
./Main.cpp:84:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   REP(i, n) REP(j, n) 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 263 ms 129408 KB
001.txt AC 263 ms 129408 KB
002.txt AC 263 ms 129408 KB
003.txt AC 264 ms 129408 KB
004.txt AC 263 ms 129408 KB
005.txt AC 264 ms 129408 KB
006.txt AC 263 ms 129408 KB
007.txt AC 264 ms 129408 KB
008.txt AC 264 ms 129408 KB
009.txt AC 263 ms 129408 KB
010.txt AC 263 ms 129408 KB
011.txt AC 263 ms 129408 KB
012.txt AC 264 ms 129408 KB
013.txt AC 263 ms 129408 KB
014.txt AC 265 ms 129536 KB
015.txt AC 266 ms 129536 KB
016.txt AC 264 ms 129536 KB
017.txt AC 267 ms 129664 KB
018.txt AC 265 ms 129536 KB
019.txt AC 263 ms 129408 KB
020.txt AC 266 ms 129664 KB
021.txt AC 276 ms 129792 KB
022.txt AC 263 ms 129536 KB
023.txt AC 272 ms 129792 KB
024.txt AC 280 ms 129792 KB
025.txt AC 276 ms 129792 KB
026.txt AC 277 ms 129792 KB
027.txt AC 275 ms 129792 KB
028.txt AC 272 ms 129792 KB
029.txt AC 278 ms 129792 KB
030.txt AC 277 ms 129792 KB
031.txt AC 276 ms 129792 KB
032.txt AC 272 ms 129792 KB
033.txt AC 280 ms 129792 KB
034.txt AC 271 ms 129792 KB
035.txt AC 269 ms 129792 KB
036.txt AC 281 ms 129792 KB
037.txt AC 278 ms 129792 KB
038.txt AC 272 ms 129792 KB
039.txt AC 282 ms 129792 KB
example0.txt AC 264 ms 129408 KB
example1.txt AC 264 ms 129408 KB