//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const ll INF = 1e18 + 5;
const ll mod = 1e6 + 7;
const int tx[] = {1, -1, 0, 0}, ty[] = {0, 0, 1, -1};
const ll bs = 31;
#define int ll
int n, a[N], b[N], cnt, res[N];
int dp[2][1005][1005];
void rec(int cur = 1, int len = 1) {
if (len == n) {
cnt++;
for (int i = 1; i <= n; i++) {
if (a[i] != b[i])
return;
}
cout << "CH ";
cout << cnt % mod;
exit(0);
}
for (int i = 1; i <= cur + 1; i++) {
b[len + 1] = i;
rec(max(cur, i), len + 1);
b[len + 1] = 0;
}
}
int calc(int id, int mx, int tp) {
// cout << id << " " << mx << " " << tp << "\n";
if (dp[tp][id][mx] != -1)
return dp[tp][id][mx];
if (id == 1)
return dp[tp][id][mx] = calc(id + 1, mx + 1, 0);
return dp[tp][id][mx] = (calc(id + 1, mx, 0) * mx % mod + calc(id + 1, mx + 1, 1)) % mod;
}
main() {
cin >> n;
memset(dp, -1, sizeof(dp));
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[0][n][i] = i;
dp[1][n][i] = 1;
}
b[1] = 1;
// rec();
int ans = 0;
int mx = 0;
for (int i = 1; i < n; i++) {
for (int j = 1; j < a[i]; j++) {
// cout << i + 1 << " ";
// cout << calc(i + 1, max(mx + 1, j + 1), 0) << "\n";
ans = (ans + calc(i + 1, max(mx + 1, j + 1), 0)) % mod;
}
mx = max(mx, a[i]);
}
cout << (ans + a[n]) % mod;
return 0;
}
/**
4
1 2 2 3
*/
Compilation message
teams.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16128 KB |
Output is correct |
2 |
Correct |
17 ms |
16128 KB |
Output is correct |
3 |
Correct |
17 ms |
16128 KB |
Output is correct |
4 |
Correct |
15 ms |
16128 KB |
Output is correct |
5 |
Correct |
15 ms |
16164 KB |
Output is correct |
6 |
Correct |
15 ms |
16128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
16124 KB |
Output is correct |
2 |
Incorrect |
14 ms |
16128 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
16188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
16128 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
16128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
16256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
16256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
43 ms |
32136 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
41 ms |
32120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
37 ms |
32128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |