Submission #1589851
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b) for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
const int maxn = 200 + 5;
const int maxp = (1 << 15) + 5;
const int oo = 0x3f3f3f3f;
const int mod = 1e9 + 7;
template<typename T> T read() {
T n(0), f(1);
char ch = getchar();
for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48;
return n * f;
}
inline bool chk(int s) {
return (s & 3) == 0 || (s & 3) == 3;
}
int n, m;
LL dp[maxp], pw[maxn];
int to[maxn], cnt[maxn][maxp];
int main() {
#ifdef Wearry
freopen("data.txt", "r", stdin);
freopen("ans.txt", "w", stdout);
#endif
scanf("%d%d", &n, &m);
for(int i = 0; i < m; ++i) {
static int u, v;
scanf("%d%d", &u, &v); -- u, -- v;
to[u] |= 1 << v;
}
pw[0] = 1;
for(int i = 1; i <= m; ++i) pw[i] = (pw[i-1] << 1) % mod;
int all = 1 << n;
for(int i = 0; i < n; ++i) {
for(int s = 0; s < all; ++s) {
cnt[i][s] = __builtin_popcount(to[i] & s);
}
}
dp[0] = 1;
for(int s = 1; s < all; ++s) if(chk(s)) {
for(int sub = s; sub; sub = (sub-1) & s) if(chk(sub)) {
int res = s ^ sub, delta = dp[res];
for(int i = 0; i < n; ++i) if(sub >> i & 1)
delta = 1LL * delta * pw[cnt[i][res]] % mod;
for(int i = 0; i < n; ++i) if(res >> i & 1)
delta = 1LL * delta * (pw[cnt[i][sub]]-1) % mod;
(dp[s] += delta) %= mod;
}
}
//cerr << dp[all-1] << endl;
printf("%lld\n", (mod + pw[m] - dp[all-1]) % mod);
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Games on DAG |
User |
Wearry |
Language |
C++14 (GCC 5.4.1) |
Score |
1600 |
Code Size |
2121 Byte |
Status |
AC |
Exec Time |
475 ms |
Memory |
2432 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:44: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:47:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &u, &v); -- u, -- v;
^
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 |
469 ms |
2432 KB |
1_02.txt |
AC |
469 ms |
2432 KB |
1_03.txt |
AC |
469 ms |
2432 KB |
1_04.txt |
AC |
469 ms |
2432 KB |
1_05.txt |
AC |
468 ms |
2432 KB |
1_06.txt |
AC |
469 ms |
2432 KB |
1_07.txt |
AC |
469 ms |
2432 KB |
1_08.txt |
AC |
468 ms |
2432 KB |
1_09.txt |
AC |
469 ms |
2432 KB |
1_10.txt |
AC |
468 ms |
2432 KB |
1_11.txt |
AC |
469 ms |
2432 KB |
1_12.txt |
AC |
469 ms |
2432 KB |
1_13.txt |
AC |
468 ms |
2432 KB |
1_14.txt |
AC |
469 ms |
2432 KB |
1_15.txt |
AC |
469 ms |
2432 KB |
1_16.txt |
AC |
468 ms |
2432 KB |
1_17.txt |
AC |
469 ms |
2432 KB |
1_18.txt |
AC |
468 ms |
2432 KB |
1_19.txt |
AC |
468 ms |
2432 KB |
1_20.txt |
AC |
475 ms |
2432 KB |
1_21.txt |
AC |
3 ms |
384 KB |
1_22.txt |
AC |
468 ms |
2432 KB |
1_23.txt |
AC |
469 ms |
2432 KB |
1_24.txt |
AC |
150 ms |
1280 KB |
1_25.txt |
AC |
2 ms |
256 KB |
1_26.txt |
AC |
469 ms |
2432 KB |
1_27.txt |
AC |
16 ms |
512 KB |
1_28.txt |
AC |
469 ms |
2432 KB |
1_29.txt |
AC |
49 ms |
768 KB |
1_30.txt |
AC |
16 ms |
512 KB |
1_31.txt |
AC |
469 ms |
2432 KB |
1_32.txt |
AC |
49 ms |
768 KB |
1_33.txt |
AC |
16 ms |
512 KB |
1_34.txt |
AC |
150 ms |
1280 KB |
1_35.txt |
AC |
49 ms |
768 KB |