#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e6 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
int dp[2][10005][2];
signed main() {
int n;
cin >> n;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
dp[0][1][0] = 1;
for(int a=1; a<n; a++) {
for(int b=1; b<=a; b++) {
for(int c=0; c<2; c++) {
if(c) {
dp[1][b][1] = (dp[1][b][1] + b * dp[0][b][1]) % mod;
dp[1][b+1][1] = (dp[1][b+1][1] + dp[0][b][1]) % mod;
continue;
}
for(int i=1; i<=b+1; i++) {
if(!c && i > v[a+1]) break;
dp[1][max(b, i)][c|(i<v[a+1])] = (dp[1][max(b, i)][c|(i<v[a+1])] + dp[0][b][c]) % mod;
}
}
}
for(int b=1; b<=n; b++) {
for(int c=0; c<2; c++) {
dp[0][b][c] = dp[1][b][c];
dp[1][b][c] = 0;
}
}
}
long long ans = 0;
for(int i=1; i<=n; i++) ans = (ans + dp[0][i][1]) % mod;
cout << (ans + 1) % mod << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
75 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
348 KB |
Output is correct |
2 |
Correct |
41 ms |
348 KB |
Output is correct |
3 |
Correct |
577 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1034 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1022 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1039 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |