QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275845#6410. Classical DP ProblemwangqingxianWA 12ms199588kbC++141.7kb2023-12-05 09:55:422023-12-05 09:55:44

Judging History

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

  • [2023-12-05 09:55:44]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:199588kb
  • [2023-12-05 09:55:42]
  • 提交

answer

#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<bitset>
#include<queue>
#include<cassert>
#include<stdlib.h>
#include<cmath>
#include<set>
#define TIME (double)clock()/(double)CLOCKS_PER_SEC
#define ll long long
#define ld long double
#define For(i,l,r) for(int i=(l);i<=(r);++i)
#define rof(i,r,l) for(int i=(r);i>=(l);--i)
#define db double
#define mem0(a) memset(a,0,sizeof(a))
#define ull unsigned long long
#define lowbit(t) (t&-t)
#define uint unsigned int
#define int long long
#define x1 dlskjfakljflkasd
#define y1 sldkfjalfjkalskl
#define x2 sdalkfjaklfjsdlk
#define y2 sfjaofoiwjfwfwof
using namespace std;
const int N=5e3+10,inf=1e18,mod=998244353;
int n,a[N],k,f[N][N],g[N],tim=1,ans=0,temp[N];
void dp(){
    For(i,1,n)k=max(k,min(a[i],i));
    int t=a[k+1];
    f[0][0]=1;
    For(i,1,k){
        For(j,0,t){
            if(j)f[i][j]=f[i-1][j-1]*(t-j+1)%mod;
            f[i][j]=(f[i][j]+f[i-1][j]*(a[i]-(t-j))%mod)%mod;
        }
    }
    ans+=f[k][t];
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    For(i,1,n){
        cin>>a[i];
        temp[i]=a[i];
    }
    reverse(a+1,a+1+n);
    dp();
    mem0(a);
    For(i,1,temp[n])For(j,1,n){
        if(temp[j]>=i) a[i]++;
        else break;
    }
    mem0(f);
    dp();
    For(i,1,k)tim=tim*i%mod;
    cout<<k<<" "<<(ans-tim+mod)%mod<<endl;
    return 0;
}
/*
 翻转a
 (1)前k行每行一个
 (2)前k列每列一个
 方案至少满足其中一个
 
 容斥
 (1)的方案+(2)的方案-(1)(2)都满足的方案(k的阶乘)
 */

详细

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 199588kb

input:

3
1 2 3

output:

2 2

result:

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