Submission #1361651
Source Code Expand
#include<cstdio> #include<algorithm> using namespace std; const long long mod = 1000000007; bool G[15][15]; int N; int M; void input(){ scanf("%d%d", &N, &M); for(int i = 0; i < M; ++i){ int x, y; scanf("%d%d", &x, &y); x--; y--; G[x][y] = true; } } long long dp[1 << 15]; inline long long f(int n){ return (1 << n) - 1; } inline int count(int v, int S){ int res = 0; for(int i = 0; i < N; ++i){ if((S >> i) & 1){ if(G[v][i]) res++; } } return res; } bool check(int S){ int x = (S & 1) ^ ((S & 2) >> 1); return x == 0; } long long solve(){ dp[0] = 1; int mask = (1 << N) - 1; for(int S = 1; S < (1 << N); ++S){ if(!check(S)) continue; for(int S2 = (S - 1) & S; ; S2 = (S2 - 1) & S){ if(!check(S2)) continue; long long coe = 1; for(int v = 0; v < N; ++v){ if((S >> v) & 1) continue; int cnt = count(v, S - S2); coe *= f(cnt); coe %= mod; } for(int v = 0; v < N; ++v){ int x = S - S2; if((x >> v) & 1){ int cnt = count(v, mask - S); coe *= (f(cnt) + 1); coe %= mod; } } dp[S] += dp[S2] * coe; dp[S] %= mod; if(S2 == 0) break; } } long long all = 1; for(int i = 0; i < M; ++i){ all *= 2; all %= mod; } long long ans = all - dp[mask]; ans %= mod; ans += mod; ans %= mod; return ans; } int main(){ input(); long long ans = solve(); printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Games on DAG |
User | wo01 |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 1483 Byte |
Status | AC |
Exec Time | 1808 ms |
Memory | 384 KB |
Compile Error
./Main.cpp: In function ‘void input()’: ./Main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &N, &M); ^ ./Main.cpp:16:24: 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 | 0 ms | 128 KB |
0_01.txt | AC | 1 ms | 128 KB |
0_02.txt | AC | 1 ms | 128 KB |
0_03.txt | AC | 1 ms | 128 KB |
1_00.txt | AC | 1 ms | 128 KB |
1_01.txt | AC | 1804 ms | 384 KB |
1_02.txt | AC | 1805 ms | 384 KB |
1_03.txt | AC | 1804 ms | 384 KB |
1_04.txt | AC | 1804 ms | 384 KB |
1_05.txt | AC | 1806 ms | 384 KB |
1_06.txt | AC | 1804 ms | 384 KB |
1_07.txt | AC | 1804 ms | 384 KB |
1_08.txt | AC | 1805 ms | 384 KB |
1_09.txt | AC | 1808 ms | 384 KB |
1_10.txt | AC | 1805 ms | 384 KB |
1_11.txt | AC | 1804 ms | 384 KB |
1_12.txt | AC | 1804 ms | 384 KB |
1_13.txt | AC | 1806 ms | 384 KB |
1_14.txt | AC | 1805 ms | 384 KB |
1_15.txt | AC | 1804 ms | 384 KB |
1_16.txt | AC | 1805 ms | 384 KB |
1_17.txt | AC | 1805 ms | 384 KB |
1_18.txt | AC | 1805 ms | 384 KB |
1_19.txt | AC | 1805 ms | 384 KB |
1_20.txt | AC | 1805 ms | 384 KB |
1_21.txt | AC | 5 ms | 128 KB |
1_22.txt | AC | 1805 ms | 384 KB |
1_23.txt | AC | 1805 ms | 384 KB |
1_24.txt | AC | 540 ms | 256 KB |
1_25.txt | AC | 2 ms | 128 KB |
1_26.txt | AC | 1805 ms | 384 KB |
1_27.txt | AC | 49 ms | 256 KB |
1_28.txt | AC | 1805 ms | 384 KB |
1_29.txt | AC | 162 ms | 256 KB |
1_30.txt | AC | 49 ms | 256 KB |
1_31.txt | AC | 1805 ms | 384 KB |
1_32.txt | AC | 162 ms | 256 KB |
1_33.txt | AC | 49 ms | 256 KB |
1_34.txt | AC | 540 ms | 256 KB |
1_35.txt | AC | 162 ms | 256 KB |