Submission #2412099
Source Code Expand
#include <iostream> #include <vector> #include <cstring> using namespace std; int N, M; vector <int> G[20]; bool Matrix[20][20]; int DP[15000005]; int Conf[20]; const int MOD = 1000000007; int Cnt[(1 << 15) + 5]; void precalcCnt() { int lim = (1 << N); for(int i = 1; i < lim; i++) for(int j = 0; j < N; j++) if((i & (1 << j)) != 0) { Cnt[i] = 1 + Cnt[(i ^ (1 << j))]; break; } } void Read() { cin >> N >> M; for(int i = 1; i <= M; i++) { int x, y; cin >> x >> y; --x;--y; G[x].push_back(y); //G[y].push_back(x); Conf[x] |= (1 << y); Matrix[x][y] = 1; } memset(DP, -1, sizeof(DP)); } inline void Add(int& x, int y) { x += y; if(x >= MOD) x -= MOD; } int Solve(int conf) { if(DP[conf] != -1) return DP[conf]; vector <int> V; bool X[20]; int C[20]; for(int i = 0; i < N; i++) { X[i] = 0; C[i] = 0; if((conf & (1 << i)) != 0) V.push_back(i), X[i] = 1; } if(X[0] != X[1]) return 0; for(int i = 0; i < V.size(); i++) { for(int j = 0; j < V.size(); j++) if(Matrix[V[i]][V[j]] == 1) { C[V[i]] |= (1 << V[j]); } } int sz = V.size(); int ans = 1; for(int c = 1; c < (1 << sz) - 1; c++) { int mask1 = 0, mask2 = 0; int nb = 1; for(int j = 0; j < sz; j++) { if((c & (1 << j)) != 0) { mask1 = (mask1 ^ (1 << V[j])); } else mask2 = (mask2 ^ (1 << V[j])); } for(int j = 0; j < sz; j++) { if((c & (1 << j)) != 0) { int m = (Conf[V[j]] & mask2); int pw = (1 << Cnt[m]) - 1; nb = (1LL * nb * pw) % MOD; } else { int m = (Conf[V[j]] & mask1); int pw = (1 << Cnt[m]); nb = (1LL * nb * pw) % MOD; } } nb = (1LL * nb * Solve(mask1)) % MOD; Add(ans, nb); } DP[conf] = ans; return ans; } int main() { Read(); precalcCnt(); int ans = Solve((1 << N) - 1); int p = 1; for(int i = 1; i <= M; i++) p = (1LL * p * 2) % MOD; ans = (p - ans) % MOD; if(ans < 0) ans += MOD; cout << ans << '\n'; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Games on DAG |
User | alex99 |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 2627 Byte |
Status | AC |
Exec Time | 1580 ms |
Memory | 59136 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1600 / 1600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 16 ms | 58880 KB |
0_01.txt | AC | 16 ms | 58880 KB |
0_02.txt | AC | 16 ms | 58880 KB |
0_03.txt | AC | 16 ms | 58880 KB |
1_00.txt | AC | 16 ms | 58880 KB |
1_01.txt | AC | 1570 ms | 59008 KB |
1_02.txt | AC | 1573 ms | 59008 KB |
1_03.txt | AC | 1572 ms | 59008 KB |
1_04.txt | AC | 1571 ms | 59008 KB |
1_05.txt | AC | 1570 ms | 59008 KB |
1_06.txt | AC | 1572 ms | 59008 KB |
1_07.txt | AC | 1577 ms | 59008 KB |
1_08.txt | AC | 1573 ms | 59008 KB |
1_09.txt | AC | 1572 ms | 59008 KB |
1_10.txt | AC | 1570 ms | 59008 KB |
1_11.txt | AC | 1571 ms | 59008 KB |
1_12.txt | AC | 1572 ms | 59008 KB |
1_13.txt | AC | 1571 ms | 59008 KB |
1_14.txt | AC | 1579 ms | 59008 KB |
1_15.txt | AC | 1573 ms | 59008 KB |
1_16.txt | AC | 1572 ms | 59008 KB |
1_17.txt | AC | 1573 ms | 59008 KB |
1_18.txt | AC | 1576 ms | 59008 KB |
1_19.txt | AC | 1572 ms | 59008 KB |
1_20.txt | AC | 1571 ms | 59008 KB |
1_21.txt | AC | 21 ms | 58880 KB |
1_22.txt | AC | 1571 ms | 59136 KB |
1_23.txt | AC | 1580 ms | 59008 KB |
1_24.txt | AC | 510 ms | 58880 KB |
1_25.txt | AC | 17 ms | 58880 KB |
1_26.txt | AC | 1573 ms | 59008 KB |
1_27.txt | AC | 64 ms | 58880 KB |
1_28.txt | AC | 1572 ms | 59008 KB |
1_29.txt | AC | 171 ms | 59008 KB |
1_30.txt | AC | 64 ms | 58880 KB |
1_31.txt | AC | 1570 ms | 59008 KB |
1_32.txt | AC | 171 ms | 58880 KB |
1_33.txt | AC | 64 ms | 58880 KB |
1_34.txt | AC | 510 ms | 58880 KB |
1_35.txt | AC | 171 ms | 58880 KB |