#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1000007;
int n;
int niz[100005];
int tren[100005];
int dp[10005];
int dpp[10005];
int add(int a, int b){
return (a+b)%MOD;
}
int mul(int a, int b){
return ((ll)a*b)%MOD;
}
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout<<fixed;
cin >> n;
for(int i=1; i<=n; i++){
cin >> niz[i];
tren[i] = max(niz[i], tren[i-1]);
}
for(int i=1; i<=n; i++){
dpp[i] = 1;
}
int res = 0;
for(int i=n; i>=1; i--){
for(int j=1; j<=n; j++){
dp[j] = add(mul(j, dpp[j]), dpp[j+1]);
}
res = add(res, mul(niz[i]-1, dpp[tren[i-1]]));
for(int j=1; j<=n; j++){
dpp[j] = dp[j];
}
}
cout << res+1 << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
332 KB |
Output is correct |
2 |
Correct |
94 ms |
332 KB |
Output is correct |
3 |
Correct |
92 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
361 ms |
488 KB |
Output is correct |
2 |
Correct |
366 ms |
460 KB |
Output is correct |
3 |
Correct |
361 ms |
508 KB |
Output is correct |