Submission #90737

# Submission time Handle Problem Language Result Execution time Memory
90737 2018-12-24T08:02:27 Z FutymyClone Calvinball championship (CEOI15_teams) C++14
100 / 100
175 ms 1232 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e4 + 5;
const int mod = 1e6 + 7;

int n, a[N], f[N];
vector <int> dp, dp2;

int readInt(){
    char c;
    int ans = 0;
    while (1) {
        c = getchar();
        if (c == ' ' || c == '\n') return ans;
        ans = (ans << 3) + (ans << 1) + (c - '0');
    }
}

int main(){
    n = readInt();
    for (int i = 1; i <= n; i++) a[i] = readInt(), f[i] = max(f[i - 1], a[i]);
    dp.assign(n + 2, 0); dp2.assign(n + 2, 0);
    int ans = 0;
    for (int i = 0; i <= n + 1; i++) dp[i] = 1;
    ans += a[n];
    for (int i = 1; i < n; i++) {
        int val = min(n, f[n - i - 1] + n - i);
        for (int j = val; j >= 1; j--) {
            dp2[j] = 1LL * dp[j] * j % mod + dp[j + 1];
            if (dp2[j] >= mod) dp2[j] -= mod;
        }
        //cout << ans << " " << f[n - i - 1] << " " << dp2[f[n - i - 1]] << "\n";
        ans += 1LL * (a[n - i] - 1) * dp2[f[n - i - 1]] % mod;
        if (ans >= mod) ans -= mod;
        dp.swap(dp2);
    }

    if (ans >= mod) ans -= mod;
    printf("%d", ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 556 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 788 KB Output is correct
2 Correct 2 ms 788 KB Output is correct
3 Correct 2 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 796 KB Output is correct
2 Correct 2 ms 800 KB Output is correct
3 Correct 2 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 808 KB Output is correct
2 Correct 3 ms 816 KB Output is correct
3 Correct 4 ms 944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 952 KB Output is correct
2 Correct 32 ms 1000 KB Output is correct
3 Correct 45 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 1232 KB Output is correct
2 Correct 118 ms 1232 KB Output is correct
3 Correct 175 ms 1232 KB Output is correct