Submission #1366227
Source Code Expand
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <cmath> using namespace std; #define mp make_pair #define pb push_back #define ll long long #define maxN 16 #define mod 1000000007 int n, m, x, y, i, limit; int adj[maxN], pre[1 << maxN]; ll dp[1 << maxN]; bool us[1 << maxN]; ll poww[maxN * maxN]; int any(int conf) { int i; int ans = 0; for (i = 0; i < n; i++) { if (conf & (1 << i)) { ans += pre[adj[i] & conf]; } } return poww[ans]; } int solve(int conf) { int act, act2, i; ll aux; if (us[conf]) return dp[conf]; us[conf] = true; dp[conf] = 1; for (act = conf; act > 0; act = (act - 1) & conf) { act2 = conf ^ act; aux = 1; if ((act & 3) != 3 && (act & 3) != 0) continue; for (i = 0; i < n; i++) { if (act & (1 << i)) { aux *= poww[ pre[adj[i] & act2] ] + mod - 1; aux %= mod; } } for (i = 0; i < n; i++) { if (act2 & (1 << i)) { aux *= poww[ pre[adj[i] & act] ]; aux %= mod; } } if (aux == 0) continue; if (act & 3) dp[conf] += aux * solve(act); else dp[conf] += aux * any(act); dp[conf] %= mod; } dp[conf] %= mod; return dp[conf]; } int main() { // freopen("test.in","r",stdin); scanf("%d%d", &n, &m); poww[0] = 1; for (i = 1; i <= n * n; i++) poww[i] = (poww[i - 1] * 2) % mod; for (i = 1; i <= m; i++) { scanf("%d%d", &x, &y); x--; y--; adj[x] |= 1 << y; } limit = 1 << n; for (i = 0; i < limit; i++) pre[i] = __builtin_popcount(i); cout << (poww[m] + mod - solve(limit - 1)) % mod; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Games on DAG |
User | atatomir |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 1954 Byte |
Status | AC |
Exec Time | 117 ms |
Memory | 512 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:83:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &n, &m); ^ ./Main.cpp:88:30: 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 | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 3 ms | 384 KB |
1_02.txt | AC | 3 ms | 384 KB |
1_03.txt | AC | 117 ms | 512 KB |
1_04.txt | AC | 112 ms | 512 KB |
1_05.txt | AC | 117 ms | 512 KB |
1_06.txt | AC | 40 ms | 512 KB |
1_07.txt | AC | 112 ms | 512 KB |
1_08.txt | AC | 117 ms | 512 KB |
1_09.txt | AC | 113 ms | 512 KB |
1_10.txt | AC | 115 ms | 512 KB |
1_11.txt | AC | 81 ms | 512 KB |
1_12.txt | AC | 116 ms | 512 KB |
1_13.txt | AC | 115 ms | 512 KB |
1_14.txt | AC | 117 ms | 512 KB |
1_15.txt | AC | 91 ms | 512 KB |
1_16.txt | AC | 81 ms | 512 KB |
1_17.txt | AC | 117 ms | 512 KB |
1_18.txt | AC | 40 ms | 512 KB |
1_19.txt | AC | 117 ms | 512 KB |
1_20.txt | AC | 4 ms | 384 KB |
1_21.txt | AC | 2 ms | 256 KB |
1_22.txt | AC | 34 ms | 512 KB |
1_23.txt | AC | 36 ms | 512 KB |
1_24.txt | AC | 4 ms | 384 KB |
1_25.txt | AC | 1 ms | 256 KB |
1_26.txt | AC | 74 ms | 512 KB |
1_27.txt | AC | 3 ms | 256 KB |
1_28.txt | AC | 3 ms | 384 KB |
1_29.txt | AC | 13 ms | 384 KB |
1_30.txt | AC | 1 ms | 256 KB |
1_31.txt | AC | 108 ms | 512 KB |
1_32.txt | AC | 13 ms | 384 KB |
1_33.txt | AC | 2 ms | 256 KB |
1_34.txt | AC | 13 ms | 384 KB |
1_35.txt | AC | 13 ms | 384 KB |