#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=10010, inf=2e9, MOD=1000007;
int n, A[MX], D[2][MX], mx[MX], ans=1;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>A[i];
for(int i=1; i<=n; i++) mx[i]=max(mx[i-1], A[i]);
for(int j=1; j<=n; j++) D[n&1][j]=1;
for(int i=n; i>=1; i--){
for(int j=1; j<A[i]; j++)
ans=(ans+D[i&1][max(mx[i-1], j)])%MOD;
for(int j=1; j<=n; j++)
D[(i&1)^1][j]=(1LL*D[i&1][j]*j+D[i&1][j+1])%MOD;
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
2 ms |
560 KB |
Output is correct |
6 |
Correct |
3 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
560 KB |
Output is correct |
2 |
Correct |
3 ms |
560 KB |
Output is correct |
3 |
Correct |
3 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
560 KB |
Output is correct |
2 |
Correct |
2 ms |
560 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
560 KB |
Output is correct |
2 |
Correct |
2 ms |
560 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
560 KB |
Output is correct |
2 |
Correct |
3 ms |
560 KB |
Output is correct |
3 |
Correct |
5 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
560 KB |
Output is correct |
2 |
Correct |
5 ms |
560 KB |
Output is correct |
3 |
Correct |
7 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
513 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
712 KB |
Output is correct |
2 |
Correct |
99 ms |
712 KB |
Output is correct |
3 |
Correct |
138 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
273 ms |
784 KB |
Output is correct |
2 |
Correct |
357 ms |
800 KB |
Output is correct |
3 |
Correct |
508 ms |
892 KB |
Output is correct |