QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#274948 | #7875. Queue Sorting | WilliamHu | WA | 262ms | 6636kb | C++20 | 1.2kb | 2023-12-04 08:40:53 | 2023-12-04 08:40:54 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m, a[1010], f[510][510], cnt = 1;
int mod = 998244353, c[510][510];
signed main() {
cin>>n;
for(int i = 1;i <= n;i ++)
{
cin>>a[cnt];
m += a[cnt];
if(a[cnt])cnt ++;
}
c[0][0] = 1;
for(int i = 1;i <= m;i ++)
{
c[i][0] = 1;
for(int j = 1;j <= i;j ++)
{
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
//cout<<i<<' '<<j<<' '<<c[i][j]<<endl;
}
}
cnt -= 1;
f[1][0] = 1;
int tot = 0;
//for(int i = 1;i <= cnt;i ++)cout<<a[i]<<' ';
for(int i = 1;i < cnt;i ++)
{
f[i][0] = 1;
tot += a[i];
for(int j = 0;j <= m;j ++)
{
for(int k = 0;k <= tot;k ++)
{
for(int x = 0;x < a[i + 1];x ++)
{
if(j == 0)
{
f[i + 1][x + k + 1] = (f[i + 1][x + k + 1] + f[i][j]) % mod;
continue;
}
int w = a[i + 1] - x - 1;
if(j - k - 1 + w < 0)continue;
f[i + 1][x + k + 1] = (f[i + 1][x + k + 1] + f[i][j] * c[j - k - 1 + w][w] % mod) % mod;
//cout<<i<<' '<<j<<' '<<x+j+1<<' '<<w<<f[i +1][x + k +1]<<endl;
}
}
}
}
int ans = 0;
for(int i = 0;i <= m;i ++)ans = (ans + f[cnt][i]) % mod;
cout<<ans % mod;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5700kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 262ms
memory: 6636kb
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:
659156099
result:
wrong answer 1st numbers differ - expected: '507010274', found: '659156099'