#include <bits/stdc++.h>
#define fin std::cin
#define fout std::cout
// std::ifstream fin("calvinball.in");
// std::ofstream fout("calvinball.out");
const long long mod = 1000007;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
int n;
fin >> n;
std::vector <int> v(n), max(n);
for(int i = 0; i < n; i ++)
fin >> v[i];
max[0] = 0;
for(int i = 1; i < n; i ++)
max[i] = std::max(max[i-1], v[i-1]);
long long dp[2][n+1], current = 0, next = 1;
for(int i = 0; i < n; i ++)
dp[current][i] = 1;
long long ans = 0;
for(int i = n-1; i >= 0; i--, current ^= 1, next ^= 1) {
ans = ans + (v[i] - 1) * dp[current][max[i]];
ans %= mod;
for(int j = 0; j < i; j ++)
dp[next][j] = (j * dp[current][j] + dp[current][j+1]) % mod;
}
fout << (1 + ans) % mod << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 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 |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
332 KB |
Output is correct |
2 |
Correct |
22 ms |
332 KB |
Output is correct |
3 |
Correct |
25 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
520 KB |
Output is correct |
2 |
Correct |
106 ms |
540 KB |
Output is correct |
3 |
Correct |
111 ms |
588 KB |
Output is correct |