#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,avx,mmx,popcnt,tune=native")
using namespace std;
const int mod = 1e6 + 7;
long long n, dp[2][10002][2], p[10002];
void add (long long &a, long long b) {
a += b;
if (a >= mod)
a-= mod;
}
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0][1] = 1;
for (int i = 0; i < n; i++) {
int k = (i & 1);
for (int j = 0; j <= n; j++)
dp[k ^ 1][j][0] = dp[k ^ 1][j][1] = 0;
for (int j = 0; j <= n; j++) {
///1 lmao
if (j > 0)
add(dp[k ^ 1][j][1], dp[k][j][1] * (p[i + 1] <= j));
if (j < n)
add(dp[k ^ 1][j + 1][1], dp[k][j][1] * (j + 1 == p[i + 1]));
///0 lmao
if (j > 0) {
add(dp[k ^ 1][j][0], 1ll * dp[k][j][1] * min(1ll * j, p[i + 1] - 1) % mod);
add(dp[k ^ 1][j][0], 1ll * dp[k][j][0] * j % mod);
}
if (j < n) {
add(dp[k ^ 1][j + 1][0], dp[k][j][1] * (j + 1 < p[i + 1]));
add(dp[k ^ 1][j + 1][0], dp[k][j][0]);
}
}
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
add(ans, dp[n & 1][i][0]);
add(ans, dp[n & 1][i][1]);
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
340 KB |
Output is correct |
3 |
Correct |
13 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1061 ms |
724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
532 KB |
Output is correct |
2 |
Correct |
267 ms |
536 KB |
Output is correct |
3 |
Correct |
244 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1027 ms |
728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |