QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749929 | #9611. 木桶效应 | A_programmer | 12 | 1ms | 3724kb | C++17 | 2.9kb | 2024-11-15 11:31:42 | 2024-11-15 11:31:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int x[15], y[15], w[15], b[15], c[1024], mn[15];
int a[15][15], occ[15][55], bg[15][55];
ll f[55][1024], mi[55], fac[55], ifac[55];
ll fpow(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1) ans = ans * a % mod;
a = a * a % mod; b >>= 1;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= q; i++)
{
cin >> x[i] >> y[i] >> w[i];
b[i] = x[i];
}
for (int i = 0; i <= n; i++) mn[i] = n + 1;
fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
ifac[n] = fpow(fac[n], mod - 2); for (int i = n; i; i--) ifac[i - 1] = ifac[i] * i % mod;
sort(b + 1, b + q + 1, [&](int x, int y) { return x < y; });
int ln = unique(b + 1, b + q + 1) - b - 1, t = m - ln;
for (int i = 1; i <= q; i++) x[i] = lower_bound(b + 1, b + ln + 1, x[i]) - b;
for (int i = 1; i <= q; i++) b[i] = y[i];
sort(b + 1, b + q + 1, [&](int x, int y) { return x < y; });
int k = unique(b + 1, b + q + 1) - b - 1;
for (int i = 1; i <= q; i++)
{
y[i] = lower_bound(b + 1, b + k + 1, y[i]) - b - 1;
a[x[i]][y[i]] = w[i];
if (occ[x[i]][w[i]]) return cout << "0", 0;
else occ[x[i]][w[i]] = 1;
mn[y[i]] = min(mn[y[i]], w[i]);
for (int j = 1; j <= w[i]; j++) bg[x[i]][j] |= (1 << y[i]);
}
int K = 1 << k; f[0][0] = 1;
for (int i = 1; i <= n; i++) mi[i] = fpow(i, t);
for (int s = 1; s < K; s++) c[s] = c[s ^ (s & -s)] + 1;
for (int i = 1; i <= n; i++)
{
for (int s = 0; s < K; s++)
for (int l = n - k; l >= 0 && l >= i - c[s] - 1; l--)
for (int j = l - 1; j >= i - c[s] - 1 && j >= 0; j--)
(f[l][s] += f[j][s] * ifac[l - j]) %= mod;
for (int j = 0; j <= n - k; j++)
for (int l = 0; l < k; l++)
if (mn[l] >= i)
for (int s = 0; s < K; s++)
if ((s >> l) & 1)
{
f[j][s] += f[j][s ^ (1 << l)];
if (f[j][s] >= mod) f[j][s] -= mod;
}
for (int j = 0; j <= n - k; j++)
for (int s = 0; s < K; s++)
{
if (j + c[s] < i) { f[j][s] = 0; continue; }
(f[j][s] *= mi[j + c[s] - i + 1]) %= mod;
for (int l = 1; l <= ln; l++)
{
if (occ[l][i]) continue;
if (j + c[s] - i + 1 <= c[s & bg[l][i]]) { f[j][s] = 0; break; }
else (f[j][s] *= (j + c[s] - i + 1 - c[s & bg[l][i]])) %= mod;
}
}
}
cout << f[n - k][K - 1] * fac[n - k] % mod;
return 0;
}
详细
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 0ms
memory: 3588kb
input:
5 3 0
output:
21412920
result:
ok single line: '21412920'
Test #2:
score: 4
Accepted
time: 0ms
memory: 3580kb
input:
5 3 2 3 4 4 2 5 3
output:
847674
result:
ok single line: '847674'
Test #3:
score: 4
Accepted
time: 0ms
memory: 3676kb
input:
5 3 3 3 5 5 1 2 5 2 5 3
output:
168780
result:
ok single line: '168780'
Subtask #2:
score: 8
Accepted
Dependency #1:
100%
Accepted
Test #4:
score: 8
Accepted
time: 0ms
memory: 3656kb
input:
7 3 0
output:
160221085
result:
ok single line: '160221085'
Test #5:
score: 8
Accepted
time: 0ms
memory: 3680kb
input:
7 3 2 1 1 5 1 6 2
output:
598007855
result:
ok single line: '598007855'
Test #6:
score: 8
Accepted
time: 0ms
memory: 3724kb
input:
7 3 3 1 1 5 2 6 3 2 1 7
output:
950880222
result:
ok single line: '950880222'
Subtask #3:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 1ms
memory: 3720kb
input:
50 1 0
output:
0
result:
wrong answer 1st lines differ - expected: '263941435', found: '0'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%