Submission #48005809
Source Code Expand
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int P = 1e9 + 7;
void add(int &a, int b) {a += b; a >= P ? a -= P : 0;}
void sub(int &a, int b) {a -= b; a < 0 ? a += P : 0;}
int n, m;
int g[20], f[1 << 15];
int main() {
n = read(); m = read();
for(int i = 1; i <= m; i++) {
int u = read() - 1, v = read() - 1;
g[u] |= (1 << v);
}
f[0] = 1;
for(int i = 0; i < (1 << n); i++) {
int t = ((1 << n) - 1) ^ i;
for(int s = t; s; s = (s - 1) & t) {
if((s & 1) && (s >> 1 & 1))continue;
int coef = 1;
for(int j = 0; j < n; j++) {
if(s >> j & 1)continue;
int v = __builtin_popcount(g[j] & s);
coef = 1ll * coef * ((1 << v) - (~i >> j & 1)) % P;
}
add(f[i | s], 1ll * coef * f[i] % P);
}
}
printf("%d\n", f[(1 << n) - 1]);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Games on DAG |
| User | thebighead |
| Language | C++ 20 (gcc 12.2) |
| Score | 1600 |
| Code Size | 1254 Byte |
| Status | AC |
| Exec Time | 679 ms |
| Memory | 3976 KiB |
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 | 3656 KiB |
| 0_01.txt | AC | 1 ms | 3852 KiB |
| 0_02.txt | AC | 1 ms | 3564 KiB |
| 0_03.txt | AC | 1 ms | 3564 KiB |
| 1_00.txt | AC | 1 ms | 3788 KiB |
| 1_01.txt | AC | 672 ms | 3784 KiB |
| 1_02.txt | AC | 671 ms | 3760 KiB |
| 1_03.txt | AC | 672 ms | 3800 KiB |
| 1_04.txt | AC | 670 ms | 3856 KiB |
| 1_05.txt | AC | 673 ms | 3976 KiB |
| 1_06.txt | AC | 678 ms | 3908 KiB |
| 1_07.txt | AC | 671 ms | 3712 KiB |
| 1_08.txt | AC | 670 ms | 3744 KiB |
| 1_09.txt | AC | 671 ms | 3972 KiB |
| 1_10.txt | AC | 671 ms | 3912 KiB |
| 1_11.txt | AC | 669 ms | 3928 KiB |
| 1_12.txt | AC | 670 ms | 3784 KiB |
| 1_13.txt | AC | 670 ms | 3780 KiB |
| 1_14.txt | AC | 670 ms | 3796 KiB |
| 1_15.txt | AC | 670 ms | 3712 KiB |
| 1_16.txt | AC | 671 ms | 3748 KiB |
| 1_17.txt | AC | 669 ms | 3908 KiB |
| 1_18.txt | AC | 671 ms | 3688 KiB |
| 1_19.txt | AC | 675 ms | 3748 KiB |
| 1_20.txt | AC | 671 ms | 3792 KiB |
| 1_21.txt | AC | 3 ms | 3572 KiB |
| 1_22.txt | AC | 670 ms | 3764 KiB |
| 1_23.txt | AC | 672 ms | 3788 KiB |
| 1_24.txt | AC | 216 ms | 3848 KiB |
| 1_25.txt | AC | 1 ms | 3676 KiB |
| 1_26.txt | AC | 672 ms | 3720 KiB |
| 1_27.txt | AC | 22 ms | 3804 KiB |
| 1_28.txt | AC | 679 ms | 3720 KiB |
| 1_29.txt | AC | 67 ms | 3836 KiB |
| 1_30.txt | AC | 21 ms | 3820 KiB |
| 1_31.txt | AC | 670 ms | 3792 KiB |
| 1_32.txt | AC | 66 ms | 3816 KiB |
| 1_33.txt | AC | 21 ms | 3632 KiB |
| 1_34.txt | AC | 214 ms | 3680 KiB |
| 1_35.txt | AC | 66 ms | 3816 KiB |