# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37363 | cheater2k | Calvinball championship (CEOI15_teams) | C++14 | 736 ms | 2668 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;
const int N = 10005;
const int md = 1000007;
int n, a[N], b[N], dp[2][N], ans;
vector< pair<int,int> > vec[N];
void add(int &x, int y) {
x += y; while(x >= md) x -= md; if (x < 0) x += md;
}
int main() {
scanf("%d", &n);
int mx = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
int cur = min(a[i] - 1, mx);
b[i] = mx;
mx = max(mx, a[i]);
a[i] = cur;
vec[b[i]].push_back(make_pair(a[i], n - i));
}
// + a[i] * dp[n - i][b[i]]
dp[n & 1][0] = 1;
for (int i = 1; i <= n; ++i) dp[n & 1][i] = 1LL * dp[n & 1][i - 1] * n % md;
for (int ngroup = n - 1; ngroup >= 1; --ngroup) {
int t = ngroup & 1;
int cur = 1;
dp[t][0] = 1;
for (int i = 1; i <= n; ++i) {
cur = ((1LL * cur * ngroup) + dp[t ^ 1][i - 1]) % md;
dp[t][i] = cur;
//printf("%d %d %d\n", ngroup, i, dp[t][i]);
}
for (auto it : vec[ngroup]) {
add(ans, 1LL * it.first * dp[t][it.second] % md);
}
}
printf("%d\n", (ans + 1) % md);
}
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... |