#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-1; j++){
dp[i][j]=sum(mul(j, dp[i-1][j]), dp[i-1][j+1]);
}
}
}
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++){
maksi=max(maksi, a[i]);
sol=sum(sol, mul(a[i]-1, dp[n-i-1][maksi-1]));
}
cout << sol << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
4172 KB |
Output is correct |
2 |
Correct |
12 ms |
4272 KB |
Output is correct |
3 |
Correct |
11 ms |
4172 KB |
Output is correct |
4 |
Correct |
13 ms |
4156 KB |
Output is correct |
5 |
Correct |
11 ms |
4260 KB |
Output is correct |
6 |
Correct |
12 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
4172 KB |
Output is correct |
2 |
Correct |
11 ms |
4172 KB |
Output is correct |
3 |
Correct |
11 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
4192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
4216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
8396 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
8396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
17 ms |
8368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |