QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269220 | #6410. Classical DP Problem | Terk | WA | 0ms | 3424kb | C++14 | 539b | 2023-11-29 14:01:49 | 2023-11-29 14:01:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+10,mod=998244353;
int n,k,t;
int Rem[N],Gy[N][N];
int main(){
cin>>n;
for(int i=n;i>0;i--) cin>>Rem[i];
for(int i=1;i<=n;i++) if(Rem[i]>=i) k=i;
t=Rem[k+1];
Gy[0][0]=1;
for(int i=1;i<=k;i++){
for(int j=0;j<=t;j++){
if(j) Gy[i][j]=(Gy[i][j]+1ll*Gy[i-1][j-1]*(t-(j-1))%mod)%mod;
Gy[i][j]=(Gy[i][j]+1ll*Gy[i-1][j]*(n-t)%mod)%mod;
}
}
int res=1;
for(int i=1;i<=k;i++) res=1ll*res*i%mod;
cout<<k<<' '<<(2ll*Gy[k][t]-res+mod)%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3388kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3380kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3424kb
input:
2 1 1
output:
1 1
result:
wrong answer 2nd numbers differ - expected: '2', found: '1'