QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#114051#6410. Classical DP ProblemSoyTonyWA 1ms3672kbC++141.4kb2023-06-20 19:31:222023-06-20 19:31:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-20 19:31:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3672kb
  • [2023-06-20 19:31:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int maxn=5005;
const int mod=998244353;

inline int read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}

int n,k;
int a[maxn];
int b[maxn];
int f[maxn][maxn];
int ans;
int main(){
    n=read();
    for(int i=1;i<=n;++i){
        a[n-i+1]=read();
        ++b[1];
        if(a[n-i+1]<n) --b[a[n-i+1]+1];
    }
    for(int i=1;i<=n;++i) b[i]+=b[i-1];
    for(int i=1;i<=n;++i){
        if(i>a[i]){
            k=i-1;
            break;
        }
    }   
    f[0][0]=1;
    for(int i=0;i<k;++i){
        for(int j=0;j<=a[k+1];++j){
            f[i+1][j+1]=(f[i+1][j+1]+1ll*(a[k+1]-j)*f[i][j]%mod)%mod;
            f[i+1][j]=(f[i+1][j]+1ll*(a[i+1]-(a[k+1]-j))*f[i][j]%mod)%mod;
        }
    }
    ans=(ans+f[k][a[k+1]])%mod;
    for(int i=0;i<=n;++i){
        for(int j=0;j<=n;++j){
            f[i][j]=0;
        }
    }
    f[0][0]=1;
    for(int i=0;i<k;++i){
        for(int j=0;j<=b[k+1];++j){
            f[i+1][j+1]=(f[i+1][j+1]+1ll*(b[k+1]-j)*f[i][j]%mod)%mod;
            f[i+1][j]=(f[i+1][j]+1ll*(b[i+1]-(b[k+1]-j))*f[i][j]%mod)%mod;
        }
    }
    ans=(ans+f[k][b[k+1]])%mod;
    int fact=1;
    for(int i=1;i<=k;++i) fact=1ll*fact*i%mod;
    ans=(ans-fact+mod)%mod;
    printf("%d %d\n",k,ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3672kb

input:

1
1

output:

0 998244352

result:

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