#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], 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];
dp[1][1][0] = 1;
for (int i = 2; i <= nArr; ++i) {
int cur(i & 1), pre(!cur);
for (int j = 1; j < i; ++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((smaller || j + 1 <= a[i]) && (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 j = 1; j <= nArr; ++j)
res += dp[nArr & 1][j][0] + dp[nArr & 1][j][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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
214 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
592 KB |
Output is correct |
2 |
Correct |
57 ms |
604 KB |
Output is correct |
3 |
Correct |
60 ms |
628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
222 ms |
604 KB |
Output is correct |
2 |
Correct |
227 ms |
608 KB |
Output is correct |
3 |
Correct |
224 ms |
1320 KB |
Output is correct |