#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 10005;
const int MOD = 1000007;
int dp[2][MAXN], dpj;
int A[MAXN], B[MAXN];
int Ans;
int N;
int main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin >> N;
for(int i = 1; i <= N; i++) cin >> A[i];
for(int i = 2, mx = 1; i <= N; i++) {
B[i] = mx;
upmax(mx, A[i]);
}
dpj = N;
dp[0][0] = 1;
for(int i = N; 1 < i; i--) {
if(1 == A[i]) continue;
for(; B[i] < dpj; dpj--) {
dp[1][0] = 1;
for(int i = 1; i <= N; i++)
dp[1][i] = (ll(dp[1][i-1]) * (dpj-1) + dp[0][i-1]) % MOD;
for(int i = 0; i <= N; i++) {
dp[0][i] = dp[1][i];
dp[1][i] = 0;
}
}
Ans = (ll(dp[0][N-i]) * (A[i]-1) + Ans) % MOD;
}
Ans++;
cout << (((Ans % MOD) + MOD) % MOD) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
584 KB |
Output is correct |
5 |
Correct |
2 ms |
584 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
584 KB |
Output is correct |
2 |
Correct |
2 ms |
584 KB |
Output is correct |
3 |
Correct |
3 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
584 KB |
Output is correct |
2 |
Correct |
2 ms |
648 KB |
Output is correct |
3 |
Correct |
3 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
712 KB |
Output is correct |
2 |
Correct |
2 ms |
772 KB |
Output is correct |
3 |
Correct |
2 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
784 KB |
Output is correct |
2 |
Correct |
5 ms |
784 KB |
Output is correct |
3 |
Correct |
5 ms |
788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
920 KB |
Output is correct |
2 |
Correct |
10 ms |
920 KB |
Output is correct |
3 |
Correct |
11 ms |
920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
935 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
221 ms |
1016 KB |
Output is correct |
2 |
Correct |
214 ms |
1016 KB |
Output is correct |
3 |
Correct |
221 ms |
1048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
919 ms |
1160 KB |
Output is correct |
2 |
Correct |
870 ms |
1244 KB |
Output is correct |
3 |
Correct |
913 ms |
1244 KB |
Output is correct |