QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#682245 | #7875. Queue Sorting | WedonotLikeStudying# | WA | 2ms | 8220kb | C++23 | 1.2kb | 2024-10-27 14:35:16 | 2024-10-27 14:35:16 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,j,k) for (int i=(j);i<=(k);++i)
#define dep(i,j,k) for (int i=(j);i>=(k);--i)
#define MAXN 500
#define MOD 998244353
using namespace std;
typedef long long LL;
LL dp[MAXN+5][MAXN+5],sum[MAXN+5][MAXN+5];
int a[MAXN+5];
LL nCr[MAXN+5][MAXN+5];
void init() {
nCr[0][0]=1;
rep(i,1,MAXN) nCr[i][0]=1;
rep(i,1,MAXN) {
rep(j,1,i) {
nCr[i][j]=(nCr[i-1][j-1]+nCr[i-1][j])%MOD;
}
}
}
void solve() {
init();
int n;
cin>>n;
rep(i,1,n) cin>>a[i];
int tot=0;
dep(i,n,1) {
if (!a[i]) {
rep(j,1,tot+1) dp[i][j]=dp[i+1][j];
rep(j,1,tot+1) sum[i][j]=sum[i+1][j];
continue;
}
tot+=a[i];
dp[i][tot+1]=1;
rep(j,a[i]+1,tot) {
dp[i][j]=(dp[i+1][j-a[i]]+nCr[j-1][a[i]-1]*sum[i+1][j-a[i]+1]%MOD)%MOD;
}
dep(j,tot+1,1) {
sum[i][j]=(sum[i][j+1]+dp[i][j])%MOD;
}
}
cout<<sum[1][1]<<"\n";
return;
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
// cin>>t;
t=1;
while (t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8220kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 7908kb
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:
955480983
result:
wrong answer 1st numbers differ - expected: '507010274', found: '955480983'