QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883741#6410. Classical DP ProblemwanggkWA 0ms3584kbC++141.9kb2025-02-05 18:34:502025-02-05 18:34:52

Judging History

This is the latest submission verdict.

  • [2025-02-05 18:34:52]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-02-05 18:34:50]
  • Submitted

answer

#include<bits/stdc++.h>
#define Spc putchar(' ')
#define End putchar('\n')
#define For(i,il,ir) for(int i=(il);i<=(ir);++i)
#define Fr(i,il,ir) for(int i=(il);i<(ir);++i)
#define Forr(i,ir,il) for(int i=(ir);i>=(il);--i)
#define ForE(u) for(int i=head[u];~i;i=e[i].nxt)
#define fi first
#define se second
#define mk make_pair
#define pb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
namespace _TvT_{
    template<typename T>
    inline void rd(T& x){
        bool f=0;x=0;char ch=getchar();
        while(ch<'0'||ch>'9'){ if(ch=='-') f=1; ch=getchar(); }
        while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        if(f) x=-x;
    }
    template<typename T,typename... Args>
    void rd(T& first,Args&... args){ rd(first),rd(args...); }
    int write_num[50];
    template<typename T>
    inline void write(T x){
        int len=0;
        if(x<0) putchar('-'),x=-x;
        do write_num[len++]=x%10ll; while(x/=10ll);
        while(len--) putchar(write_num[len]+'0');
    }
    template<typename T,typename... Args>
    void write(T first,Args... args){ write(first),Spc,write(args...); }
}using namespace _TvT_;
const int maxn=5005;
const ll mod=998244353;
void qadd(ll &x,ll y){ x=(x+y>=mod)?(x+y-mod):(x+y); }

int n,K;
int a[maxn],b[maxn];
ll f[maxn][maxn],res;

ll solve(int kk,int m)
{
    f[0][0]=1ll;
    For(i,0,kk) For(j,0,m) if(f[i][j])
        qadd(f[i+1][j+1],f[i][j]*(m-j)%mod),
        qadd(f[i+1][j],f[i][j]*(a[i]-m+j)%mod);
    return f[kk][m];
}

signed main()
{
    rd(n);
    Forr(i,n,1) rd(a[i]);
    for(K=1;K+1<=n && a[K+1]>=K+1;K++);

    res=solve(K,a[K+1]);

    For(i,1,n) b[a[i]]++; a[n]=b[n];
    Forr(i,n-1,1) a[i]=a[i+1]+b[i];
    res=(res+solve(K,a[K+1]))%mod;
    
    ll tmp=1ll;
    For(i,2,K) tmp=tmp*1ll*i%mod;
    res=(res-tmp+mod)%mod;
    write(K,res),End;
    return 0;
}

詳細信息

Test #1:

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

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3584kb

input:

1
1

output:

1 998244352

result:

wrong answer 2nd numbers differ - expected: '1', found: '998244352'