#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 10004;
const int MOD = 1000007;
ll dp[2][MAXN][2];
int a[MAXN], pref[MAXN], nArr;
ll powermod(ll a, int exponent) {
ll res(1);
while(exponent > 0) {
if(exponent & 1)
res = res * a % MOD;
a = a * a % MOD;
exponent >>= 1;
}
return res;
}
void process() {
cin >> nArr;
for (int i = 1; i <= nArr; ++i) {
cin >> a[i];
pref[i] = max(pref[i - 1], a[i]);
}
dp[1][1][0] = 1;
for (int i = 2; i <= nArr; ++i) {
int cur(i & 1), pre(!cur);
for (int j = 1; j <= pref[i - 1]; ++j) {
for (int smaller = 0; smaller < 2; ++smaller) {
if(!dp[pre][j][smaller])
continue;
if(!smaller) {
dp[cur][j][1] = (dp[cur][j][1] + dp[pre][j][smaller] * min(j, a[i] - 1)) % MOD;
dp[cur][j][0] = (dp[cur][j][0] + dp[pre][j][smaller] * (j >= a[i])) % MOD;
} else {
dp[cur][j][smaller] = (dp[cur][j][smaller] + dp[pre][j][smaller] * j) % MOD;
}
if(pref[i] > j && (dp[cur][j + 1][smaller | (j + 1 < a[i])] += dp[pre][j][smaller]) >= MOD)
dp[cur][j + 1][smaller | (j + 1 < a[i])] -= MOD;
dp[pre][j][smaller] = 0;
}
}
}
ll res(0);
for (int i = 1; i <= pref[nArr]; ++i)
res += dp[nArr & 1][i][0] + dp[nArr & 1][i][1];
cout << res % MOD << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
process();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |