QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#683657 | #6410. Classical DP Problem | SimonLJK | WA | 24ms | 199644kb | C++17 | 843b | 2024-10-27 22:32:44 | 2024-10-27 22:32:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=5009;
int n,m,len,x[N],y[N];
ll f[N][N],jc[N],ans;
void init(){
jc[0]=1;
for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
return;
}
void solve(){
int len=0;
while(x[len+1]>m) len++;
memset(f,0,sizeof(f));
f[0][0]=1;
for(int i=1;i<=m;i++)
for(int j=0;j<=min(i,len);j++)
f[i][j]=((j==0?0:f[i-1][j-1]*(len-(j-1)))+f[i-1][j]*(j+x[i]-len))%mod;
ans+=f[m][len];
return;
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cin>>n; init();
for(int i=n;i>=1;i--){
cin>>x[i];
y[x[i]+1]--;
}
y[1]=n;
for(int i=1;i<=n;i++) y[i]+=y[i-1];
m=1;
while(x[m+1]>m) m++;
solve();
for(int i=1;i<=n;i++) swap(x[i],y[i]);
solve();
ans=(ans-jc[m]+mod)%mod;
cout<<m<<" "<<ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 24ms
memory: 199644kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 19ms
memory: 199644kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Wrong Answer
time: 24ms
memory: 199596kb
input:
2 1 1
output:
1 1
result:
wrong answer 2nd numbers differ - expected: '2', found: '1'