#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][2][10000];
bool verify_input() {
int lm = -1;
rep(i, N) {
if (A[i] > lm+1) return false;
if (A[i] == lm+1) lm++;
}
return true;
}
signed main() {
cin >> N;
rep(i, N) cin >> A[i], A[i]--;
if (!verify_input()) {
cout << 0 << "\n";
return 0;
}
dp[0][0][0] = 1;
for (int i=1; i<N; i++) {
rep(k, 2) rep(s, i+1) dp[1][k][s] = 0;
rep(k, 2) {
rep(s, i+1) {
if (dp[0][k][s] == 0) continue;
if (k == 0) {
add(dp[1][1][s], (1LL*A[i]*dp[0][0][s])%MOD);
add(dp[1][0][max(s, A[i])], dp[0][0][s]);
}
else {
int stay = s+1, go = 1;
add(dp[1][1][s], (1LL*stay*dp[0][1][s])%MOD);
add(dp[1][1][s+1], (1LL*go*dp[0][1][s])%MOD);
}
}
}
swap(dp[0], dp[1]);
}
int s = 0;
rep(i, N) add(s, dp[0][1][i]);
cout << s+1 << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2212 KB |
Output is correct |
2 |
Correct |
0 ms |
2212 KB |
Output is correct |
3 |
Correct |
0 ms |
2212 KB |
Output is correct |
4 |
Correct |
0 ms |
2212 KB |
Output is correct |
5 |
Correct |
0 ms |
2212 KB |
Output is correct |
6 |
Correct |
0 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2212 KB |
Output is correct |
2 |
Correct |
0 ms |
2212 KB |
Output is correct |
3 |
Correct |
0 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2212 KB |
Output is correct |
2 |
Correct |
0 ms |
2212 KB |
Output is correct |
3 |
Correct |
0 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2212 KB |
Output is correct |
2 |
Correct |
0 ms |
2212 KB |
Output is correct |
3 |
Correct |
0 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2212 KB |
Output is correct |
2 |
Correct |
9 ms |
2212 KB |
Output is correct |
3 |
Correct |
9 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
2212 KB |
Output is correct |
2 |
Correct |
26 ms |
2212 KB |
Output is correct |
3 |
Correct |
26 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
933 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
2212 KB |
Output is correct |
2 |
Correct |
289 ms |
2212 KB |
Output is correct |
3 |
Correct |
313 ms |
2212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1000 ms |
2212 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |