#include <bits/stdc++.h>
using namespace std;
#define FOR(v, s, e) for (int v = s; v < e; v++)
#define FOR_REV(v, s, e) for (int v = e - 1; v >= s; v--)
#define int long long
#define MOD 1000007
int n, ans;
int val[10005], cmax[10005];
int dp[2][10005];
int32_t main() {
cin >> n;
cmax[n - 1] = 1;
FOR_REV(i, 0, n) {
cin >> val[i];
if (i != 0)
cmax[i - 1] = max(cmax[i], val[i]);
}
FOR(i, 0, n) {
dp[0][i] = 1;
}
bool flag = false;
FOR(i, 0, n) {
ans = (ans + (val[i] - 1) * dp[flag][cmax[i] - 1]) % MOD;
FOR(j, 0, n - 1) {
dp[1 - flag][j] = ((j + 1) * dp[flag][j] + dp[flag][j + 1]) % MOD;
}
flag = 1 - flag;
}
cout << (ans + 1) % MOD;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
216 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
1 ms |
216 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
216 KB |
Output is correct |
2 |
Correct |
1 ms |
216 KB |
Output is correct |
3 |
Correct |
1 ms |
216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
216 KB |
Output is correct |
2 |
Correct |
1 ms |
276 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
468 KB |
Output is correct |
2 |
Correct |
45 ms |
472 KB |
Output is correct |
3 |
Correct |
45 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
600 KB |
Output is correct |
2 |
Correct |
191 ms |
620 KB |
Output is correct |
3 |
Correct |
186 ms |
600 KB |
Output is correct |