#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int M = 1000007;
int add(int a, int b) {
a += b;
if (a >= M) return a - M;
if (a < 0) return a + M;
return a;
}
int mul(int a, int b) {
return a * (ll) b % M;
}
void addup(int &a, int b) {
a = add(a, b);
}
void mulup(int &a, int b) {
a = mul(a, b);
}
const int N = 10000 + 7;
int n, a[N], mx[N], ways[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mx[i] = max(mx[i - 1], a[i]);
}
for (int i = 1; i <= n; i++) {
ways[i] = 1;
}
int sol = 1;
for (int i = n; i >= 1; i--) {
int init = sol;
for (int pl = 1; pl < a[i]; pl++) {
addup(sol, ways[mx[i - 1]]);
}
for (int j = 1; j <= n; j++) {
ways[j] = add(mul(j, ways[j]), ways[j + 1]);
}
}
cout << sol << "\n";
}
Compilation message
teams.cpp: In function 'int main()':
teams.cpp:47:9: warning: unused variable 'init' [-Wunused-variable]
47 | int init = sol;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
340 KB |
Output is correct |
3 |
Correct |
12 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
968 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
230 ms |
340 KB |
Output is correct |
2 |
Correct |
225 ms |
392 KB |
Output is correct |
3 |
Correct |
250 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
951 ms |
468 KB |
Output is correct |
2 |
Correct |
946 ms |
468 KB |
Output is correct |
3 |
Execution timed out |
1014 ms |
472 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |