# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
460904 | kingfran1907 | Calvinball championship (CEOI15_teams) | C++14 | 486 ms | 476 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>
#define X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 1e4+2;
const int base = 31337;
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int logo = 18;
const int off = 1 << logo;
const int treesiz = off << 1;
int n;
int niz[maxn];
int dp[2][maxn];
int pref[maxn];
int mul(int a, int b) {
llint out = (llint) a * b;
return out % mod;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", niz+i);
}
pref[0] = niz[0];
for (int i = 1; i < n; i++) pref[i] = max(pref[i - 1], niz[i]);
int sol = 0;
for (int i = 1; i <= n; i++) dp[0][i] = 1;
int cnt = 1;
for (int i = n - 1; i > 0; i--) {
sol += mul(niz[i] - 1, dp[(n - i - 1) % 2][pref[i - 1]]);
sol %= mod;
for (int j = 1; j <= n; j++)
dp[cnt][j] = (dp[1 - cnt][j + 1] + mul(j, dp[1 - cnt][j])) % mod;
cnt = 1 - cnt;
}
printf("%d\n", sol + 1);
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... |