QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518175 | #7. 主旋律 | complexor | 0 | 141ms | 6344kb | C++20 | 2.4kb | 2024-08-13 17:12:15 | 2024-08-13 17:12:15 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long LL;
typedef std::pair<int, int> pii;
typedef std::pair<LL, LL> pll;
typedef std::pair<LL, int> pli;
#define e_b emplace_back
#define MP std::make_pair
#define fi first
#define se second
int read()
{
LL s = 0; int f = 1;
char c = getchar();
while (!(c >= '0' && c <= '9'))
f ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9')
s = s * 10 + (c ^ 48), c = getchar();
return f ? s : -s;
}
const int MAXN = 200005, inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1e9 + 7;
auto fplus = [](int x, int y){ return x + y >= MOD ? x + y - MOD : x + y; };
auto fminus = [](int x, int y){ return x >= y ? x - y : x + MOD - y; };
auto Fplus = [](int &x, int y){ return x = fplus(x, y); };
auto Fminus = [](int &x, int y){ return x = fminus(x, y); };
int fpow(int x, int y)
{
int res = 1;
for (; y; y >>= 1, x = (LL)x * x % MOD)
if (y & 1) res = (LL)res * x % MOD;
return res;
}
template<typename T>
T& Fmin(T &x, T y){ return x = x < y ? x : y; };
template<typename T>
T& Fmax(T &x, T y){ return x = x < y ? y : x; };
int n, m, e[1 << 15][15], f[1 << 15], dp[1 << 15], cnt[1 << 15];
int pw[1000];
int main()
{
n = read(), m = read();
pw[0] = 1;
for (int i = 1; i <= m; i++)
{
pw[i] = fplus(pw[i - 1], pw[i - 1]);
int u = read() - 1, v = read() - 1;
e[1 << u][v]++;
}
for (int s = 1; s < (1 << n); s++)
{
int j = s & -s;
if (j != s) for (int i = 0; i < n; i++) e[s][i] = e[s ^ j][i] + e[j][i];
}
for (int s = 1; s < (1 << 15); s++)
{
for (int t = (s - 1) & s; ; t = (t - 1) & s)
{
int tt = s ^ t;
int j = std::__lg(tt & -tt);
cnt[tt] = cnt[tt ^ (1 << j)] + e[s][j];
if (t & (s & -s)) Fminus(f[s], (LL)dp[t] * f[tt] % MOD);
if (!t) break;
}
dp[s] = pw[cnt[s]];
for (int t = (s - 1) & s; ; t = (t - 1) & s)
{
int tt = s ^ t;
Fminus(dp[s], (LL)f[tt] * pw[cnt[s] - cnt[tt]] % MOD);
// cnt[tt] = 0;
if (!t) break;
}
memset(cnt, 0, sizeof cnt);
Fplus(f[s], dp[s]);
// printf("%d: %d %d\n", s, f[s], dp[s]);
}
printf("%d\n", dp[(1 << n) - 1]);
printf("%lf\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 136ms
memory: 4260kb
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 0.139117
result:
wrong output format Extra information in the output file
Test #2:
score: 0
Wrong Answer
time: 139ms
memory: 4432kb
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 0.139047
result:
wrong output format Extra information in the output file
Test #3:
score: 0
Wrong Answer
time: 140ms
memory: 4444kb
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 0.140008
result:
wrong output format Extra information in the output file
Test #4:
score: 0
Wrong Answer
time: 140ms
memory: 4312kb
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 0.140445
result:
wrong output format Extra information in the output file
Test #5:
score: 0
Wrong Answer
time: 140ms
memory: 4256kb
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 0.137022
result:
wrong output format Extra information in the output file
Test #6:
score: 0
Wrong Answer
time: 140ms
memory: 4424kb
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 0.137996
result:
wrong output format Extra information in the output file
Test #7:
score: 0
Wrong Answer
time: 136ms
memory: 4444kb
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 0.138703
result:
wrong output format Extra information in the output file
Test #8:
score: 0
Wrong Answer
time: 141ms
memory: 6300kb
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 0.138937
result:
wrong output format Extra information in the output file
Test #9:
score: 0
Wrong Answer
time: 141ms
memory: 6340kb
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 0.138891
result:
wrong output format Extra information in the output file
Test #10:
score: 0
Wrong Answer
time: 141ms
memory: 6344kb
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 0.138387
result:
wrong output format Extra information in the output file