# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476794 | ntabc05101 | Calvinball championship (CEOI15_teams) | C++17 | 629 ms | 588 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define taskname ""
const int mxN = 10000;
const int mod = 1e6 + 7;
long long dp[2][mxN + 1];
#define dp(x) dp[(x) & 1]
int a[mxN + 1], mx[mxN + 1];
int main() {
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
else {
if (fopen(taskname".in", "r")) {
freopen(taskname".in", "r", stdin);
freopen(taskname".out", "w", stdout);
}
}
cin.tie(0)->sync_with_stdio(0);
int n; 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++) {
dp(0)[i] = 1;
}
long long res = 1;
for (int i = n - 1; i; i--) {
for (int j = 1; j <= n; j++) {
(dp(n - i)[j] = 1ll * j * dp(n - i - 1)[j]) %= mod;
(dp(n - i)[j] += dp(n - i - 1)[j + 1]) %= mod;
}
for (int j = a[i] - 1; j; j--) {
(res += dp(n - i)[max(mx[i - 1], j)]) %= mod;
}
}
(res += a[n] - 1) %= mod;
cout << res << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |