Submission #1417815
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = (int)1e9 + 7; void add(int &a, ll b) { a = (a + b) % MOD; } int fastsolve(vector<vector<int> > e) { int n = e.size(); vector<vector<int> > g(n); int all = 1; for (int i = 0; i < n; i++) { for (int to : e[i]) { g[to].push_back(i); all = 2 * all % MOD; } } vector<int> cov(1 << n); vector<int> cntEdges(1 << n); vector<vector<int> > cnt(1 << n, vector<int>(n)); for (int mask = 0; mask < (1 << n); mask++) { for (int i = 0; i < n; i++) { if (!(mask & (1 << i))) continue; for (int to : g[i]) { cov[mask] |= 1 << to; cntEdges[mask]++; cnt[mask][to]++; } } } vector<int> pw(1000); pw[0] = 1; for (int i = 1; i < 1000; i++) pw[i] = pw[i - 1] * 2 % MOD; vector<int> dp(1 << n); dp[0] = 1; int ans = 0; for (int mask = 0; mask < (1 << n); mask++) { if (dp[mask] == 0) continue; int omask = ((1 << n) - 1) ^ mask; for (int cmask = omask; cmask; cmask = (cmask - 1) & omask) { int rmask = cmask ^ omask; /*if ((cov[cmask] & rmask) != rmask) { continue; }*/ int ways = dp[mask]; for (int i = 0; i < n; i++) { if (rmask & (1 << i)) { ways = 1LL * ways * ((1 << cnt[cmask][i]) - 1) % MOD; } else if (mask & (1 << i)) { ways = 1LL * ways * (1 << cnt[cmask][i]) % MOD; } } if ((cmask & 3) == 3) add(ans, ways * 1LL * pw[cntEdges[rmask]]); add(dp[mask | cmask], ways); } } return (all - ans + MOD) % MOD; } int main() { #ifdef HOME freopen("in", "r", stdin); #endif int n, m; while (cin >> n >> m) { vector<pair<int, int> > ed(m); for (int i = 0; i < m; i++) { cin >> ed[i].first >> ed[i].second; ed[i].first--; ed[i].second--; } vector<vector<int> > e(n); for (int i = 0; i < m; i++) { e[ed[i].first].push_back(ed[i].second); } for (int i = 0; i < n; i++) { sort(e[i].begin(), e[i].end()); } printf("%d\n", fastsolve(e)); } #ifdef HOME cerr << clock() / (double)CLOCKS_PER_SEC << endl; #endif return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Games on DAG |
User | izban |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 2585 Byte |
Status | AC |
Exec Time | 432 ms |
Memory | 4096 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 | 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 | 8 ms | 3968 KB |
1_02.txt | AC | 8 ms | 3968 KB |
1_03.txt | AC | 432 ms | 3968 KB |
1_04.txt | AC | 415 ms | 3968 KB |
1_05.txt | AC | 432 ms | 3968 KB |
1_06.txt | AC | 150 ms | 3968 KB |
1_07.txt | AC | 425 ms | 3968 KB |
1_08.txt | AC | 432 ms | 3968 KB |
1_09.txt | AC | 421 ms | 3968 KB |
1_10.txt | AC | 428 ms | 3968 KB |
1_11.txt | AC | 303 ms | 3968 KB |
1_12.txt | AC | 431 ms | 3968 KB |
1_13.txt | AC | 430 ms | 3968 KB |
1_14.txt | AC | 431 ms | 4096 KB |
1_15.txt | AC | 342 ms | 3968 KB |
1_16.txt | AC | 302 ms | 3968 KB |
1_17.txt | AC | 431 ms | 3968 KB |
1_18.txt | AC | 149 ms | 3968 KB |
1_19.txt | AC | 431 ms | 3968 KB |
1_20.txt | AC | 15 ms | 3968 KB |
1_21.txt | AC | 3 ms | 384 KB |
1_22.txt | AC | 133 ms | 3968 KB |
1_23.txt | AC | 136 ms | 3968 KB |
1_24.txt | AC | 13 ms | 1792 KB |
1_25.txt | AC | 2 ms | 256 KB |
1_26.txt | AC | 282 ms | 3968 KB |
1_27.txt | AC | 7 ms | 640 KB |
1_28.txt | AC | 9 ms | 3968 KB |
1_29.txt | AC | 43 ms | 1024 KB |
1_30.txt | AC | 2 ms | 640 KB |
1_31.txt | AC | 407 ms | 3968 KB |
1_32.txt | AC | 43 ms | 1024 KB |
1_33.txt | AC | 5 ms | 640 KB |
1_34.txt | AC | 49 ms | 1792 KB |
1_35.txt | AC | 43 ms | 1024 KB |