QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768745 | #7875. Queue Sorting | xingrin | AC ✓ | 50ms | 9712kb | C++14 | 2.7kb | 2024-11-21 14:10:42 | 2024-11-21 14:10:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
// using ll=long double;
using pii=pair<ll,ll>;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N = 510, mod = 998244353;
ll f[N][N];
ll a[N];
ll len[N];
ll c[N][N];
ll sumc[N][N];
void init()
{
for(int i=0;i<=500;i++)
{
for(int j=0;j<=i;j++)
{
if(!j) c[i][j] = 1;
else c[i][j] = (c[i-1][j-1] + c[i-1][j])%mod;
}
}
for(int i=0;i<=500;i++)
{
for(int j=0;j<=i;j++)
{
if(!j) sumc[i][j] = c[i][j];
else sumc[i][j] = (sumc[i][j-1] + c[i][j])%mod;
}
}
}
void solve()
{
ll n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i], len[i] = len[i-1] + a[i];
int flag = 1;
f[0][0] = 1;
for(int i=1;i<=n;i++)
{
if(flag)
{
f[i][0] = 1;
if(len[i]) flag = 0;
continue;
}
for(int j =0;j<len[i-1];j++)
{
f[i][j] += f[i-1][j];
f[i][j]%=mod;
if(a[i] == 0) continue;
for(int k=j+1; k<len[i]; k++)
{
if(k-j<=a[i] && k-j-1 <= len[i-1]-j-1)
{
f[i][k] += f[i-1][j] * sumc[k-j-1][k-j-1]%mod;
f[i][k]%=mod;
}
else if(k-j>a[i] && k-j-1<=len[i-1]-j-1)
{
// cout<<11111<<endl;
ll dlt = (k-j) - a[i];
f[i][k] += f[i-1][j] * (sumc[k-j-1][k-j-1] - sumc[k-j-1][dlt-1])%mod;
f[i][k]%=mod;
f[i][k] = (f[i][k] + mod)%mod;
}
else if(k-j<=a[i] && k-j-1>len[i-1]-j-1)
{
ll dlt = (k-j-1) - (len[i-1] - j-1);
f[i][k] += f[i-1][j] * sumc[k-j-1][k-j-1-dlt]%mod;
f[i][k]%=mod;
}
else
{
ll dlt1 = (k-j) - a[i];
ll dlt2 = (k-j-1) - (len[i-1] - j-1);
if(dlt1 >= k-j-dlt2) continue;
f[i][k] += f[i-1][j] * (sumc[k-j-1][k-j-1-dlt2] - sumc[k-j-1][dlt1-1])%mod;
f[i][k]%=mod;
f[i][k] = (f[i][k] + mod)%mod;
}
}
}
}
ll ans = 0;
// cout<<f[2][0]<<' '<<f[2][1]<<' '<<f[2][2]<<' '<<f[2][3]<<endl;
for(int i=0;i<=500;i++)
{
ans = (ans + f[n][i])%mod;
}
cout<<ans;
}
int main(){
IOS;
int t=1;
init();
// cin>>t;
while(t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9136kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 39ms
memory: 8848kb
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: 50ms
memory: 9648kb
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: 26ms
memory: 8900kb
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: 8ms
memory: 9372kb
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: 2ms
memory: 9280kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 2ms
memory: 9712kb
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: 0ms
memory: 8328kb
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: 0ms
memory: 8812kb
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: 2ms
memory: 8232kb
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: 0ms
memory: 9520kb
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: 14ms
memory: 8916kb
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: 0ms
memory: 8424kb
input:
2 232 268
output:
929717758
result:
ok 1 number(s): "929717758"
Test #14:
score: 0
Accepted
time: 2ms
memory: 8480kb
input:
1 500
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 2ms
memory: 8464kb
input:
3 155 180 165
output:
911108550
result:
ok 1 number(s): "911108550"
Extra Test:
score: 0
Extra Test Passed