#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define ARRS ((ll)(2e6+500))
#define MAX ((ll)(1e6+100))
#define MOD ((ll)1e6+7)
#define mi(a,b) a=min((a),(b))
ll n,m,k,p,l,r,q;
ll a[20000];
ll f[2][10005][2];
int main(){
#ifdef KHOKHO
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
ios::sync_with_stdio(0);
cin>>n;
for(int i=0; i<n; i++)cin>>a[i];
ll N=0,P=1;
for(ll i=n; i>=0; i--){
for(ll c=n; c>=0; c--){
for(ll e=0; e<2; e++){
if(i==n){f[N][c][e]=1;continue;}
f[N][c][e]=0;
if(e)
f[N][c][e]=c*f[P][c][e]+f[P][c+1][e];
else {
if(a[i]==c+1){
f[N][c][e]+=c*f[P][c][1];
f[N][c][e]+=f[P][c+1][0];
}
else {
f[N][c][e]+=(a[i]-1)*f[P][c][1];
f[N][c][e]+=f[P][c][0];
}
}
f[N][c][e]%=MOD;
}
}
swap(N,P);
}
cout<<f[P][0][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
3 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
520 KB |
Output is correct |
2 |
Correct |
2 ms |
548 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
548 KB |
Output is correct |
2 |
Correct |
3 ms |
548 KB |
Output is correct |
3 |
Correct |
3 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
612 KB |
Output is correct |
2 |
Correct |
3 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
612 KB |
Output is correct |
2 |
Correct |
6 ms |
612 KB |
Output is correct |
3 |
Correct |
5 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
740 KB |
Output is correct |
2 |
Correct |
13 ms |
740 KB |
Output is correct |
3 |
Correct |
11 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
949 ms |
1020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
1020 KB |
Output is correct |
2 |
Correct |
249 ms |
1020 KB |
Output is correct |
3 |
Correct |
208 ms |
1020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
1020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |