QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831067 | #7. 主旋律 | ORzyzRO | 100 ✓ | 649ms | 4560kb | C++14 | 2.1kb | 2024-12-25 10:09:30 | 2024-12-25 10:09:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pr pair<int, int>
#define pb push_back
#define mid (l + r) / 2
#define ls num << 1
#define rs num << 1 | 1
inline int read() {
int x = 0, m = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') m = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getchar();
}
return x * m;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
write(-x);
return;
}
if (x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
const int N = 15, M = (1 << 15), mod = 1e9 + 7;
int add(int x, int y) {
return (x + y >= mod) ? (x + y - mod) : (x + y);
}
int sub(int x, int y) {
return (x - y < 0) ? (x - y + mod) : (x - y);
}
void Add(int &x, int y) {
x += y;
if (x >= mod) x -= mod;
}
void Sub(int &x, int y) {
x -= y;
if (x < 0) x += mod;
}
int d[N], f[M], g[M], Pow[N * N * 2], pop[M], h[M];
signed main() {
int n = read(), m = read();
for (int i = 1; i <= m; i++) {
int x = read() - 1, y = read() - 1;
d[x] |= (1 << y);
}
Pow[0] = 1;
for (int i = 1; i <= 2 * n * n; i++) Pow[i] = Pow[i - 1] * 2 % mod;
f[0] = 1;
for (int i = 0; i < (1 << n); i++) pop[i] = __builtin_popcount(i);
g[0] = sub(0, 1);
f[0] = h[0] = 1;
for (int i = 1; i < (1 << n); i++) {
int D = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) D += pop[d[j] & i];
}
f[i] = Pow[D];
for (int j = i; j; j = (j - 1) & i) {
int x = i ^ j;
D = 0;
for (int y = 0; y < n; y++) if ((j >> y) & 1) D += pop[d[y] & x];
Add(h[i], g[j] * Pow[D] % mod * h[x] % mod);
}
Sub(f[i], h[i]);
Add(h[i], f[i]);
int S = ((1 << n) - 1) ^ i;
for (int j = S; ; j = (j - 1) & S) {
Add(g[j ^ i], g[j] * sub(0, f[i]) % mod);
if (!j) break;
}
}
write(f[(1 << n) - 1]);
putchar('\n');
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3612kb
input:
5 15 4 3 4 2 2 5 2 1 1 2 5 1 3 2 4 1 1 4 5 4 3 4 5 3 2 3 1 5 3 1
output:
9390
result:
ok single line: '9390'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3552kb
input:
5 18 4 3 4 2 2 5 2 1 1 2 5 1 3 2 4 1 1 4 5 4 3 4 5 3 2 3 1 5 3 1 1 3 5 2 2 4
output:
100460
result:
ok single line: '100460'
Test #3:
score: 10
Accepted
time: 1ms
memory: 3624kb
input:
8 35 5 1 8 7 7 8 7 6 6 1 2 5 6 5 8 2 7 2 7 5 3 1 6 3 2 3 5 2 8 5 8 3 6 8 2 1 1 6 2 6 7 3 2 4 3 5 3 2 3 7 7 1 8 4 3 4 3 6 6 4 2 7 4 6 6 7 7 4 8 1
output:
299463717
result:
ok single line: '299463717'
Test #4:
score: 10
Accepted
time: 1ms
memory: 3624kb
input:
8 40 5 1 8 7 7 8 7 6 6 1 2 5 6 5 8 2 7 2 7 5 3 1 6 3 2 3 5 2 8 5 8 3 6 8 2 1 1 6 2 6 7 3 2 4 3 5 3 2 3 7 7 1 8 4 3 4 3 6 6 4 2 7 4 6 6 7 7 4 8 1 1 2 4 8 5 8 4 3 5 7
output:
21156439
result:
ok single line: '21156439'
Test #5:
score: 10
Accepted
time: 0ms
memory: 3564kb
input:
8 45 5 1 8 7 7 8 7 6 6 1 2 5 6 5 8 2 7 2 7 5 3 1 6 3 2 3 5 2 8 5 8 3 6 8 2 1 1 6 2 6 7 3 2 4 3 5 3 2 3 7 7 1 8 4 3 4 3 6 6 4 2 7 4 6 6 7 7 4 8 1 1 2 4 8 5 8 4 3 5 7 2 8 1 5 3 8 1 3 4 1
output:
426670664
result:
ok single line: '426670664'
Test #6:
score: 10
Accepted
time: 2ms
memory: 3896kb
input:
10 65 5 10 1 8 7 8 6 2 5 7 9 2 4 7 3 7 1 6 3 10 7 9 8 4 7 1 5 2 1 7 4 2 8 3 8 1 3 9 8 2 2 10 4 3 9 10 5 3 3 8 3 4 6 10 4 8 4 5 5 8 9 5 9 6 10 2 10 5 6 1 2 1 9 4 7 10 5 6 10 7 10 8 5 9 9 7 9 8 4 10 8 9 7 2 2 7 10 1 7 3 6 8 7 6 9 1 6 5 2 4 6 3 2 9 8 10 10 9 8 5 4 1 6 9 2 3 1 3 1 9
output:
931896041
result:
ok single line: '931896041'
Test #7:
score: 10
Accepted
time: 2ms
memory: 3596kb
input:
10 70 5 10 1 8 7 8 6 2 5 7 9 2 4 7 3 7 1 6 3 10 7 9 8 4 7 1 5 2 1 7 4 2 8 3 8 1 3 9 8 2 2 10 4 3 9 10 5 3 3 8 3 4 6 10 4 8 4 5 5 8 9 5 9 6 10 2 10 5 6 1 2 1 9 4 7 10 5 6 10 7 10 8 5 9 9 7 9 8 4 10 8 9 7 2 2 7 10 1 7 3 6 8 7 6 9 1 6 5 2 4 6 3 2 9 8 10 10 9 8 5 4 1 6 9 2 3 1 3 1 9 5 4 1 5 5 1 10 4 10 6
output:
303656759
result:
ok single line: '303656759'
Test #8:
score: 10
Accepted
time: 645ms
memory: 4560kb
input:
15 130 7 10 9 12 4 6 1 10 14 9 4 8 8 9 4 3 15 9 3 9 1 8 2 15 8 4 13 7 3 5 14 13 6 2 14 6 8 3 4 2 8 13 9 2 6 13 12 11 6 4 11 8 15 5 3 8 10 8 15 7 15 6 12 15 8 12 13 9 12 9 8 15 11 6 6 7 10 4 2 8 11 12 7 9 7 12 14 1 5 8 10 9 3 7 7 13 11 9 11 10 1 5 1 3 2 1 2 7 10 1 10 15 7 14 5 6 6 1 15 10 5 15 15 8 5...
output:
717458968
result:
ok single line: '717458968'
Test #9:
score: 10
Accepted
time: 645ms
memory: 4528kb
input:
15 140 7 10 9 12 4 6 1 10 14 9 4 8 8 9 4 3 15 9 3 9 1 8 2 15 8 4 13 7 3 5 14 13 6 2 14 6 8 3 4 2 8 13 9 2 6 13 12 11 6 4 11 8 15 5 3 8 10 8 15 7 15 6 12 15 8 12 13 9 12 9 8 15 11 6 6 7 10 4 2 8 11 12 7 9 7 12 14 1 5 8 10 9 3 7 7 13 11 9 11 10 1 5 1 3 2 1 2 7 10 1 10 15 7 14 5 6 6 1 15 10 5 15 15 8 5...
output:
459157220
result:
ok single line: '459157220'
Test #10:
score: 10
Accepted
time: 649ms
memory: 4560kb
input:
15 150 7 10 9 12 4 6 1 10 14 9 4 8 8 9 4 3 15 9 3 9 1 8 2 15 8 4 13 7 3 5 14 13 6 2 14 6 8 3 4 2 8 13 9 2 6 13 12 11 6 4 11 8 15 5 3 8 10 8 15 7 15 6 12 15 8 12 13 9 12 9 8 15 11 6 6 7 10 4 2 8 11 12 7 9 7 12 14 1 5 8 10 9 3 7 7 13 11 9 11 10 1 5 1 3 2 1 2 7 10 1 10 15 7 14 5 6 6 1 15 10 5 15 15 8 5...
output:
663282473
result:
ok single line: '663282473'