QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#197694#6410. Classical DP Problemucup-team870#WA 19ms199292kbC++141.3kb2023-10-02 18:36:202023-10-02 18:36:21

Judging History

你现在查看的是最新测评结果

  • [2023-10-02 18:36:21]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:199292kb
  • [2023-10-02 18:36:20]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
typedef long long ll;
const int mo=998244353;
ll dp[5005][5005];
int a[5005],b[5005],now[5005],k;
int cal(int n){
    int s=0;
    For(i,1,n) if (b[i]>k) ++s;
    if (b[n-k+1]>k) return -1;
    //now
    int x=1;
    For(i,1,k){
        while(b[x]<i) ++x;
        now[i]=n-x+1; 
    }
    //dp
    memset(dp,0,sizeof(dp)); dp[0][0]=1;
    For(i,0,k-1) For(j,0,min(s,i)){
        dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*(s-j))%mo;
        dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(now[i+1]-s+j))%mo;
    }
    return dp[k][s];
}
int main(){
    IOS
    int n; cin>>n;
    For(i,1,n) cin>>a[i];
    //cal k
    for(int i=n-1;i>=0;--i){
        ++k;
        if (k>=a[i]) break;
    }
    //1
    For(i,1,n) b[i]=a[i];
    ll s1=cal(n);
    //2
    int m=a[n],x=n;
    For(i,1,m){
        while(a[x]>=m-i+1)--x;
        b[i]=n-x;
    }
    ll s2=cal(m);
    //ans
    //cout<<k<<endl;
    //For(i,1,m) cout<<b[i]<<' '; cout<<endl;
    //cout<<s1<<' '<<s2<<endl;
    ll jc=1;
    For(i,1,k) jc=jc*i%mo;
    if (s1==-1&&s2==-1) cout<<jc;
    else if (s1==-1) cout<<s2;
    else if (s2==-1) cout<<s1;
    else cout<<(s1+s2-jc+mo)%mo;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 19ms
memory: 199292kb

input:

3
1 2 3

output:

6

result:

wrong answer 1st numbers differ - expected: '2', found: '6'