Submission #1030822
Source Code Expand
#include <iostream> #include <cstdint> #include <cassert> #include <cstring> uint32_t N, RK; uint32_t C[300][300]; uint64_t pows[301]; bool zero[300]; const uint64_t MOD = 1000000007; uint64_t memo[301][301]; uint64_t solve(int r, int rank) { if (memo[r][rank] != -1) { return memo[r][rank]; } if (r == N) { uint64_t ans = 1; for (int i = rank + 1; i <= N; ++i) { ans = (ans * pows[N]) % MOD; } return memo[r][rank] = ans; } else { uint64_t a = (pows[N] - pows[rank] + MOD) % MOD; uint64_t indep = (a * solve(r + 1, rank + 1)) % MOD; uint64_t depen = 0; int nz = 0; if (zero[r]) { for (int i = 0; i < r; ++i) { if (zero[i]) { ++nz; } } depen = pows[nz - r + rank] * solve(r + 1, rank) % MOD; } #ifdef DEBUG std::cout << "f(" << r << ", " << rank << ") = " << (indep + depen) << " = " << a << " * f(" << (r + 1) << ", " << (rank + 1) << ")"; if (zero[r]) { std::cout << " + " << pows[nz] << " * f(" << (r + 1) << ", " << rank << ")" << std::endl; } else { std::cout << std::endl; } #endif return memo[r][rank] = (indep + depen) % MOD; } } int main() { memset(memo, -1, sizeof memo); std::cin >> N; RK = N; pows[0] = 1; for (int i = 0; i <= N; ++i) { pows[i + 1] = (2 * pows[i]) % MOD; } for (int r = 0; r < N; ++r) { for (int c = 0; c < N; ++c) { std::cin >> C[r][c]; } } for (int c = 0; c < N; ++c) { int r = 0; for (; r < N; ++r) { int t = 0; for (; t < c && C[r][t] == 0; ++t); if (t == c && C[r][t] == 1) { break; } } if (r == N) { zero[c] = 1; --RK; } else { std::swap(C[r], C[c]); for (int r2 = c + 1; r2 < N; ++r2) { if (C[r2][c] == 1) { for (int c2 = 0; c2 < N; ++c2) { if (c2 < c) { assert(C[r2][c2] == 0); } else { C[r2][c2] ^= C[c][c2]; } } } } } } std::cout << solve(0, 0) << std::endl; }
Submission Info
Submission Time | |
---|---|
Task | H - AB=C Problem |
User | gfarina |
Language | C++14 (GCC 5.4.1) |
Score | 1500 |
Code Size | 2176 Byte |
Status | AC |
Exec Time | 35 ms |
Memory | 1280 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1500 / 1500 | ||||
Status |
|
|
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 | 3 ms | 896 KB |
001.txt | AC | 3 ms | 896 KB |
002.txt | AC | 3 ms | 896 KB |
003.txt | AC | 3 ms | 896 KB |
004.txt | AC | 3 ms | 896 KB |
005.txt | AC | 3 ms | 896 KB |
006.txt | AC | 3 ms | 896 KB |
007.txt | AC | 3 ms | 896 KB |
008.txt | AC | 3 ms | 896 KB |
009.txt | AC | 3 ms | 896 KB |
010.txt | AC | 3 ms | 896 KB |
011.txt | AC | 3 ms | 896 KB |
012.txt | AC | 3 ms | 896 KB |
013.txt | AC | 3 ms | 896 KB |
014.txt | AC | 6 ms | 1152 KB |
015.txt | AC | 7 ms | 1152 KB |
016.txt | AC | 4 ms | 1024 KB |
017.txt | AC | 16 ms | 1152 KB |
018.txt | AC | 4 ms | 1024 KB |
019.txt | AC | 3 ms | 1024 KB |
020.txt | AC | 9 ms | 1152 KB |
021.txt | AC | 29 ms | 1280 KB |
022.txt | AC | 5 ms | 1024 KB |
023.txt | AC | 31 ms | 1280 KB |
024.txt | AC | 28 ms | 1280 KB |
025.txt | AC | 30 ms | 1280 KB |
026.txt | AC | 29 ms | 1280 KB |
027.txt | AC | 31 ms | 1280 KB |
028.txt | AC | 34 ms | 1280 KB |
029.txt | AC | 30 ms | 1280 KB |
030.txt | AC | 30 ms | 1280 KB |
031.txt | AC | 31 ms | 1280 KB |
032.txt | AC | 34 ms | 1280 KB |
033.txt | AC | 29 ms | 1280 KB |
034.txt | AC | 35 ms | 1280 KB |
035.txt | AC | 20 ms | 1280 KB |
036.txt | AC | 28 ms | 1280 KB |
037.txt | AC | 24 ms | 1280 KB |
038.txt | AC | 34 ms | 1280 KB |
039.txt | AC | 27 ms | 1280 KB |
example0.txt | AC | 3 ms | 896 KB |
example1.txt | AC | 3 ms | 1024 KB |