#include <iostream>
#include <fstream>
#include <bitset>
#include <cassert>
#include <vector>
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF 1145141919
#define MOD 1000007
#define pb push_back
using namespace std;
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
int N;
int A[10000];
int dp[2][10000];
signed main() {
cin >> N;
rep(i, N) cin >> A[i], A[i]--;
int lm = 0;
for (int i=1; i<N; i++) {
rep(s, i+1) dp[1][s] = 0;
rep(s, i+1) {
add(dp[1][s], (1LL*(s+1)*dp[0][s])%MOD);
add(dp[1][s+1], dp[0][s]);
}
add(dp[1][lm], A[i]);
if (A[i] == lm+1) lm++;
swap(dp[0], dp[1]);
}
int s = 0;
rep(i, N) add(s, dp[0][i]);
cout << s+1 << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2132 KB |
Output is correct |
2 |
Correct |
0 ms |
2132 KB |
Output is correct |
3 |
Correct |
0 ms |
2132 KB |
Output is correct |
4 |
Correct |
0 ms |
2132 KB |
Output is correct |
5 |
Correct |
0 ms |
2132 KB |
Output is correct |
6 |
Correct |
0 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2132 KB |
Output is correct |
2 |
Correct |
0 ms |
2132 KB |
Output is correct |
3 |
Correct |
0 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2132 KB |
Output is correct |
2 |
Correct |
0 ms |
2132 KB |
Output is correct |
3 |
Correct |
0 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2132 KB |
Output is correct |
2 |
Correct |
0 ms |
2132 KB |
Output is correct |
3 |
Correct |
0 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2132 KB |
Output is correct |
2 |
Correct |
6 ms |
2132 KB |
Output is correct |
3 |
Correct |
6 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2132 KB |
Output is correct |
2 |
Correct |
13 ms |
2132 KB |
Output is correct |
3 |
Correct |
13 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
646 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
2132 KB |
Output is correct |
2 |
Correct |
206 ms |
2132 KB |
Output is correct |
3 |
Correct |
199 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
716 ms |
2132 KB |
Output is correct |
2 |
Correct |
713 ms |
2132 KB |
Output is correct |
3 |
Correct |
683 ms |
2132 KB |
Output is correct |