Submission #1361786
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; inline void add(int &a, int b) { a += b; if (a >= md) { a -= md; } } inline int mul(int a, int b) { return (long long) a * b % md; } const int N = 1234567; int who[N]; int mask[N]; int kb[N]; int g[N]; int deg[N]; int ans; void dfs(int v, int ways) { if (v == 1) { int rm0 = deg[0]; int rm1 = deg[1]; int z = 0; while (true) { int cur0 = kb[mask[0] & who[z]]; int cur1 = kb[mask[1] & who[z]]; add(ans, mul(ways, 1 << (rm0 - cur0 + rm1 - cur1))); if (cur0 == 0 || cur1 == 0) { break; } rm0 -= cur0; rm1 -= cur1; ways = mul(ways, (1 << cur0) - 1); ways = mul(ways, (1 << cur1) - 1); z++; } return; } g[v] = 0; int rm = deg[v]; while (true) { int cur = kb[mask[v] & who[g[v]]]; who[g[v]] ^= (1 << v); dfs(v - 1, mul(ways, 1 << (rm - cur))); who[g[v]] ^= (1 << v); if (cur == 0) { break; } rm -= cur; ways = mul(ways, (1 << cur) - 1); g[v]++; } } int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { int x, y; scanf("%d %d", &x, &y); x--; y--; mask[x] |= (1 << y); } if (mask[0] & 2) { mask[0] ^= 2; } kb[0] = 0; for (int i = 1; i < (1 << n); i++) { kb[i] = kb[i & (i - 1)] + 1; } for (int i = 0; i < n; i++) { deg[i] = kb[mask[i]]; } for (int z = 0; z <= n; z++) { who[z] = 0; } ans = 0; dfs(n - 1, 1); int total = 1; for (int i = 0; i < m; i++) { add(total, total); } int res = total; add(res, md - ans); printf("%d\n", res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Games on DAG |
User | tourist |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 1774 Byte |
Status | AC |
Exec Time | 2095 ms |
Memory | 8448 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:65:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d", &n, &m); ^ ./Main.cpp:68:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d", &x, &y); ^
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 | 2 ms | 6400 KB |
0_01.txt | AC | 3 ms | 8448 KB |
0_02.txt | AC | 3 ms | 8448 KB |
0_03.txt | AC | 3 ms | 8448 KB |
1_00.txt | AC | 2 ms | 6400 KB |
1_01.txt | AC | 3 ms | 8448 KB |
1_02.txt | AC | 3 ms | 8448 KB |
1_03.txt | AC | 2095 ms | 8448 KB |
1_04.txt | AC | 1109 ms | 8448 KB |
1_05.txt | AC | 2094 ms | 8448 KB |
1_06.txt | AC | 260 ms | 8448 KB |
1_07.txt | AC | 480 ms | 8448 KB |
1_08.txt | AC | 2001 ms | 8448 KB |
1_09.txt | AC | 840 ms | 8448 KB |
1_10.txt | AC | 873 ms | 8448 KB |
1_11.txt | AC | 720 ms | 8448 KB |
1_12.txt | AC | 1491 ms | 8448 KB |
1_13.txt | AC | 1056 ms | 8448 KB |
1_14.txt | AC | 1714 ms | 8448 KB |
1_15.txt | AC | 486 ms | 8448 KB |
1_16.txt | AC | 417 ms | 8448 KB |
1_17.txt | AC | 1808 ms | 8448 KB |
1_18.txt | AC | 107 ms | 8448 KB |
1_19.txt | AC | 1739 ms | 8448 KB |
1_20.txt | AC | 3 ms | 8448 KB |
1_21.txt | AC | 3 ms | 8448 KB |
1_22.txt | AC | 6 ms | 8448 KB |
1_23.txt | AC | 30 ms | 8448 KB |
1_24.txt | AC | 3 ms | 8448 KB |
1_25.txt | AC | 3 ms | 8448 KB |
1_26.txt | AC | 156 ms | 8448 KB |
1_27.txt | AC | 3 ms | 8448 KB |
1_28.txt | AC | 3 ms | 8448 KB |
1_29.txt | AC | 24 ms | 8448 KB |
1_30.txt | AC | 3 ms | 8448 KB |
1_31.txt | AC | 551 ms | 8448 KB |
1_32.txt | AC | 28 ms | 8448 KB |
1_33.txt | AC | 3 ms | 8448 KB |
1_34.txt | AC | 5 ms | 8448 KB |
1_35.txt | AC | 12 ms | 8448 KB |