QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#273273 | #7875. Queue Sorting | ucup-team093# | AC ✓ | 59ms | 4780kb | C++20 | 1.1kb | 2023-12-02 22:43:28 | 2023-12-02 22:43:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 510, P = 998244353;
int c[N][N];
int main() {
for(int i = 0; i < N; i ++) {
c[i][0] = 1;
for(int j = 1; j <= i; j ++)
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % P;
}
int n, len = 0, sum = 0;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i ++) {
cin >> a[i];
if(a[i] == 0) {
n --;
i --;
}
}
len = accumulate(a.begin(), a.end(), 0);
vector<int> dp(len + 1, 0);
for(int i = 1; i <= len; i ++)
dp[i] = (P + c[i][a[0]] - c[i - 1][a[0]]) % P;
sum = a[0];
for(int i = 1; i < n; i ++) {
vector<int> tmp(len + 1, 0);
for(int j = 1; j <= len; j ++) {
for(int k = 0, uk = min(j - sum, a[i]); k <= uk; k ++)
for(int l = j; l <= len; l ++)
tmp[l] = (tmp[l] + dp[j] * (long long)(P + c[l - j][a[i] - k] - (l > j ? c[l - j - 1][a[i] - k] : 0))) % P;
}
swap(tmp, dp);
sum += a[i];
}
cout << dp[len];
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4624kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 56ms
memory: 4780kb
input:
300 0 5 2 2 1 0 3 2 2 5 2 1 1 2 1 3 2 3 2 0 0 0 0 1 2 2 3 0 2 2 3 2 0 2 3 0 6 0 0 2 0 1 3 2 1 1 1 3 4 0 1 0 4 1 1 1 1 1 1 2 3 2 1 2 3 2 3 0 5 3 3 2 0 1 1 0 2 1 1 2 0 0 2 1 1 3 2 2 1 2 1 3 0 3 0 1 2 2 0 5 0 2 2 0 0 0 1 2 1 4 2 1 1 0 3 0 2 0 3 1 1 2 0 2 1 1 0 2 0 1 2 2 3 3 1 1 1 1 0 1 3 3 1 0 2 2 4 2 ...
output:
507010274
result:
ok 1 number(s): "507010274"
Test #3:
score: 0
Accepted
time: 59ms
memory: 4560kb
input:
500 1 1 0 2 1 0 2 3 2 0 0 2 0 2 1 1 0 0 1 1 1 2 1 1 1 0 1 1 2 2 1 4 0 2 1 0 2 3 1 0 1 1 0 2 1 2 2 1 0 0 3 1 4 1 1 2 1 1 0 1 3 1 2 0 0 0 2 1 2 0 0 3 2 1 1 1 1 1 2 1 0 1 0 0 0 1 0 0 2 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 0 1 0 0 0 2 1 1 0 1 1 0 1 1 0 0 1 0 3 1 3 0 0 2 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 2 0 0 ...
output:
7590964
result:
ok 1 number(s): "7590964"
Test #4:
score: 0
Accepted
time: 52ms
memory: 4776kb
input:
200 3 1 0 3 2 1 0 3 1 1 2 3 3 1 6 2 1 3 2 1 1 2 1 2 1 5 2 2 3 4 0 4 2 1 2 2 0 2 3 1 2 3 6 3 2 3 2 2 4 2 7 2 1 5 1 9 0 4 4 8 3 3 3 1 3 0 2 2 8 1 3 5 4 3 0 6 1 6 1 3 4 2 2 1 1 4 4 4 1 0 4 3 4 3 3 0 3 2 0 0 3 4 0 3 1 3 2 4 3 2 0 3 2 2 3 2 2 2 1 2 2 1 0 2 0 3 1 3 5 1 3 3 6 5 3 2 2 2 3 6 2 0 5 2 2 2 2 1 ...
output:
507844569
result:
ok 1 number(s): "507844569"
Test #5:
score: 0
Accepted
time: 12ms
memory: 4596kb
input:
100 4 8 2 5 4 4 3 0 2 7 2 3 4 4 1 2 3 4 4 4 3 3 3 3 3 2 4 1 3 5 5 1 4 6 1 1 1 3 2 3 2 1 0 1 4 4 2 4 2 5 3 5 1 6 2 3 3 1 4 4 4 1 4 4 3 4 2 0 2 3 6 1 3 3 5 4 1 1 2 3 0 3 2 2 1 3 3 2 5 6 3 2 3 3 5 4 2 3 4 4
output:
989550242
result:
ok 1 number(s): "989550242"
Test #6:
score: 0
Accepted
time: 1ms
memory: 4612kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 1ms
memory: 4620kb
input:
500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 1ms
memory: 4628kb
input:
10 2 1 3 3 2 3 1 1 3 1
output:
165452340
result:
ok 1 number(s): "165452340"
Test #9:
score: 0
Accepted
time: 1ms
memory: 4588kb
input:
20 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0
output:
2
result:
ok 1 number(s): "2"
Test #10:
score: 0
Accepted
time: 1ms
memory: 4628kb
input:
20 0 0 1 0 0 0 0 1 0 0 0 0 0 0 2 0 1 0 0 0
output:
28
result:
ok 1 number(s): "28"
Test #11:
score: 0
Accepted
time: 1ms
memory: 4616kb
input:
10 1 1 1 1 1 1 1 1 1 1
output:
16796
result:
ok 1 number(s): "16796"
Test #12:
score: 0
Accepted
time: 17ms
memory: 4600kb
input:
300 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
431279497
result:
ok 1 number(s): "431279497"
Test #13:
score: 0
Accepted
time: 6ms
memory: 4568kb
input:
2 232 268
output:
929717758
result:
ok 1 number(s): "929717758"
Test #14:
score: 0
Accepted
time: 0ms
memory: 4508kb
input:
1 500
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 13ms
memory: 4564kb
input:
3 155 180 165
output:
911108550
result:
ok 1 number(s): "911108550"
Extra Test:
score: 0
Extra Test Passed