#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[2][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++){
}
}
int a[maxn];
int pref[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;
bool tren=1;
for(int i=0; i<maxn; i++){
dp[1][i]=1;
}
pref[0]=1;
for(int i=0; i<n; i++){
pref[i+1]=max(pref[i], a[i]);
}
for(int i=n-1; i>-1; i--){
sol=sum(sol, mul(a[i]-1, dp[tren^1][pref[i]]));
for(int j=0; j<maxn-1; j++){
dp[tren][j]=sum(mul(j, dp[tren^1][j]), dp[tren^1][j+1]);
}
tren^=1;
}
cout << sol << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
204 KB |
Output is correct |
3 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
204 KB |
Output is correct |
2 |
Correct |
10 ms |
332 KB |
Output is correct |
3 |
Correct |
22 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
460 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |