# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81796 | Just_Solve_The_Problem | Calvinball championship (CEOI15_teams) | C++11 | 822 ms | 924 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 <stdio.h>
using namespace std;
const int N = (int)1e4 + 7;
int mod = (int)1e6 + 7;
int a[N];
int dp[2][N];
int add(int a, int b) {
return (a + b) % mod;
}
int mult(long long a, long long b) {
return (a * b) % mod;
}
int n, mx;
int asd[N];
main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
asd[i] = asd[i - 1];
if (a[i] > mx) {
mx = a[i];
asd[i]++;
}
}
int ans = 1;
for (int i = 1; i <= n; i++) dp[n & 1][i] = 1;
ans = add(ans, mult(dp[n & 1][asd[n - 1]], a[n] - 1));
for (int i = n - 1; i >= 1; i--) {
for (int j = 0; j <= i; j++) {
dp[i & 1][j] = add(mult(dp[(i & 1) ^ 1][j], j), dp[(i & 1) ^ 1][j + 1]);
}
ans = add(ans, mult(dp[i & 1][asd[i - 1]], a[i] - 1));
}
printf("%d", ans);
}
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... |