#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 = 3505;
const int MOD = 1000007;
int dp[MAXN][MAXN];
int A[MAXN];
int Ans;
int N;
int main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin >> N;
if(3500 < N) return -1;
for(int i = 1; i <= N; i++) cin >> A[i];
for(int i = 1; i <= N; i++) dp[0][i] = 1;
for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++)
dp[i][j] = (ll(dp[i-1][j]) * j + dp[i-1][j+1]) % MOD;
for(int i = 2, mx = 1; i <= N; i++) {
if(1 == A[i]) continue;
Ans = (ll(dp[N-i][mx]) * (A[i]-1) + Ans) % MOD;
upmax(mx, A[i]);
}
Ans++;
cout << (((Ans % MOD) + MOD) % MOD) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
3 ms |
480 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
3 ms |
480 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1000 KB |
Output is correct |
2 |
Correct |
2 ms |
1004 KB |
Output is correct |
3 |
Correct |
2 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3564 KB |
Output is correct |
2 |
Correct |
5 ms |
3564 KB |
Output is correct |
3 |
Correct |
5 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
8572 KB |
Output is correct |
2 |
Correct |
10 ms |
8572 KB |
Output is correct |
3 |
Correct |
10 ms |
8572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
8572 KB |
Execution failed because the return code was nonzero |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
8572 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
8572 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |