#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int mxN = 1e4+5;
const int mod = 1e6+7;
int N, A[mxN];
int dp[2][mxN][2];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
FOR(i,1,N){
cin >> A[i];
}
FOR(j,0,N) FOR(x,0,1) dp[(N+1)&1][j][x] = 1;
RFOR(i,N,1){
int c = i&1, p = !c;
FOR(j,0,i-1){
dp[c][j][0] = 1LL * dp[p][j][0] * j % mod;
dp[c][j][0] += dp[p][j+1][0];
dp[c][j][0] %= mod;
if (j < A[i]) {
dp[c][j][1] = 1LL * dp[p][j][0] * j % mod;
dp[c][j][1] += dp[p][j+1][(j+1 == A[i])];
dp[c][j][1] %= mod;
} else {
dp[c][j][1] = 1LL * dp[p][j][0] * (A[i]-1) % mod;
dp[c][j][1] += dp[p][j][1];
dp[c][j][1] %= mod;
}
//TRACE(i _ j _ "|" _ dp[c][j][0] _ dp[c][j][1]);
}
}
cout << dp[1][0][1] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
432 KB |
Output is correct |
3 |
Correct |
9 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
512 KB |
Output is correct |
2 |
Correct |
95 ms |
512 KB |
Output is correct |
3 |
Correct |
104 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
387 ms |
636 KB |
Output is correct |
2 |
Correct |
380 ms |
736 KB |
Output is correct |
3 |
Correct |
386 ms |
632 KB |
Output is correct |