QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883452 | #6410. Classical DP Problem | jianhe | WA | 22ms | 202992kb | C++14 | 754b | 2025-02-05 16:26:31 | 2025-02-05 16:26:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=5050,mod=998244353;
ll n,a[N],t[N],k,ans,jc=1,dp[N][N];
ll solve(){
memset(dp,0,sizeof dp);dp[0][0]=1;
for(int i=1;i<=k;i++)
for(int j=0;j<=a[k+1];j++){
dp[i][j]=dp[i-1][j]*(a[i]-a[k+1]+j)%mod;
if(j) (dp[i][j]+=dp[i-1][j-1]*(a[k+1]-j+1))%=mod;
}
return dp[k][a[k+1]];
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;for(int i=n;i;i--) cin>>a[i],t[a[i]]++;
for(int i=1;i<n;i++) if(a[i+1]<=i){k=i;break;}
ans=solve();for(int i=2;i<=k;i++) jc=jc*i%mod;
for(int i=n;i;i--) t[i]+=t[i+1],a[i]=t[i];
cout<<k<<" "<<((ans+solve()-jc)%mod+mod)%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 21ms
memory: 202992kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: -100
Wrong Answer
time: 22ms
memory: 202728kb
input:
1 1
output:
0 998244352
result:
wrong answer 1st numbers differ - expected: '1', found: '0'