QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272938 | #7875. Queue Sorting | ucup-team266# | WA | 67ms | 11348kb | C++20 | 1.7kb | 2023-12-02 20:12:24 | 2023-12-02 20:12:24 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353;
int a[505];
int f[505];
int g[505];
ll C[1010][1010];
ll func(int x,int y)
{
if(!x) return (y==0);
return C[x+y-1][x-1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i=0;i<1010;i++)
C[i][0]=C[i][i]=1;
for(int i=2;i<1010;i++)
for(int j=1;j<i;j++)
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
int s=0;
f[0]=1;
for(int i=1;i<=n;i++) if(a[i])
{
if(!s)
{
s+=a[i];
f[0]=0;
f[s+1]=1;
continue;
}
memset(g,0,sizeof(g));
for(int c=0;c<a[i];c++)
for(int j=1;j<=s+1;j++)
for(int k=1;k<j;k++)
{
ll ways=(func(j-k+1,a[i]-c)-func(j-k,a[i]-c)+mod)%mod;
g[c+k+1]=(g[c+k+1]+f[j]*ways)%mod;
}
for(int j=1;j<=s+1;j++)
g[a[i]+j]=(g[a[i]+j]+f[j])%mod;
memcpy(f,g,sizeof(g));
s+=a[i];
// for(int i=1;i<=s+1;i++)
// cout<<f[i]<<" ";
// cout<<endl;
}
ll ans=0;
for(int i=1;i<=s+1;i++)
ans=(ans+f[i])%mod;
cout<<ans<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 10820kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 67ms
memory: 11348kb
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:
652883587
result:
wrong answer 1st numbers differ - expected: '507010274', found: '652883587'