#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int > pp;
typedef long long ll;
int const N=3e5+10,oo=1e9,M=1e6;
ll const OO=1e18;
double const eps=1e-6,PI=acos(-1);
int mod=M+7;
int n,aa[N],dp[2][10001][2],dp1[2][10001];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
int mx=0;
for(int i=0;i<n;i++)cin>>aa[i],mx=max(mx,aa[i]);
int f=0,an=0;
dp1[f][1]=1;
dp[f][1][0]=1;
for(int i=1,un=1;i<n;i++){
f=1-f;
un=max(un,aa[i]);
dp[f][un][0]=1;
for(int j=1;j<=i+1&&j<mx;j++){
dp1[f][j]=(dp1[!f][j]*1LL*j+dp1[!f][j-1])%mod;
dp[f][j][1]=(dp[!f][j][1]*1LL*j+dp[!f][j][0]*1LL*min(j,aa[i]-1)+dp[!f][j-1][1])%mod;
// cout<<j<<' '<<dp[f][j][1]<<' '<<dp[!f][j][0]<<endl;
dp1[!f][j-1]=0;
dp[!f][j-1][1]=dp[!f][j-1][0]=0;
}
// cout<<endl;
dp[f][mx][1]=(dp[!f][mx][1]*1LL*mx+dp[!f][mx][0]*1LL*min(mx,aa[i]-1)+dp[!f][mx-1][1])%mod;
dp1[!f][mx-1]=0;
dp[!f][mx][1]=dp[!f][mx-1][1]=0;
dp[!f][mx][0]=dp[!f][mx-1][0]=0;
}
for(int i=1;i<mx;i++){
an+=dp1[f][i];
an%=mod;
}
an+=dp[f][mx][1]+1;
an%=mod;
cout<<an<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
248 KB |
Output is correct |
5 |
Correct |
1 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1030 ms |
768 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |