#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=1e3+5, mod=1e6+7, Log=20;
const int phi=965495;
int fact[maxn];
int n;
int dp[maxn][maxn];
int gcd(int a, int b){
if(a>b){
swap(a, b);
}
int c;
while(a){
c=b%a;
b=a;
a=c;
}
return b;
}
inline int sum(int a, int b){
if(a+b>=mod){
return a+b-mod;
}
if(a+b<0){
return a+b+mod;
}
return a+b;
}
inline int mul(int a, int b){
return (ll)a*b%mod;
}
inline int pote(int a, int b){
int sol=1;
for(int i=0; i<Log; i++){
if((1<<i)&b){
sol=mul(sol, a);
}
a=mul(a, a);
}
return sol;
}
inline int dij(int a, int b){
return mul(a, pote(b, phi));
}
void precompute(){
fact[0]=1;
for(int i=1; i<maxn; i++){
fact[i]=mul(fact[i-1], i);
}
for(int i=0; i<maxn; i++){
dp[0][i]=1;
}
for(int i=1; i<maxn; i++){
for(int j=0; j<maxn; j++){
dp[i][j]=mul(j, dp[i-1][j]);
}
}
}
int a[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
precompute();
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i];
}
int sol=1;
int maksi=0;
for(int i=0; i<n; i++){
if(maksi>1 || a[i]>1){
sol=sum(sol, dp[n-i][maksi]);
}
maksi=max(maksi, a[i]);
}
cout << sol << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4172 KB |
Output is correct |
2 |
Correct |
4 ms |
4172 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4172 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4172 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4172 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
8524 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
8380 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
8396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |