Submission #527228

# Submission time Handle Problem Language Result Execution time Memory
527228 2022-02-17T03:59:05 Z joelau Calvinball championship (CEOI15_teams) C++14
100 / 100
413 ms 656 KB
#include <bits/stdc++.h>
using namespace std;

long long N, A[10005], dp[2][10005], most[10005], p = 1000007;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    most[0] = 0;
    for (long long i = 1; i <= N; ++i) {
        cin >> A[i];
        most[i] = max(most[i-1],A[i]);
    }
    for (long long i = 1; i <= N+1; ++i) dp[1][i] = 1;
    long long ans = 1;
    for (long long i = N; i > 0; --i) {
        for (long long j = 1; j <= i; ++j) dp[0][j] = (dp[1][j] * j + dp[1][j+1]) % p;
        ans = (ans + dp[1][most[i-1]] * min(most[i-1],A[i]-1)) % p;
        for (long long j = most[i-1]+1; j < A[i]; ++j) ans = (ans + dp[1][j]) % p;
        swap(dp[0],dp[1]);
    }
    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 484 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 480 KB Output is correct
2 Correct 7 ms 452 KB Output is correct
3 Correct 8 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 500 KB Output is correct
2 Correct 11 ms 460 KB Output is correct
3 Correct 10 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 394 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 460 KB Output is correct
2 Correct 112 ms 460 KB Output is correct
3 Correct 112 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 409 ms 604 KB Output is correct
2 Correct 375 ms 636 KB Output is correct
3 Correct 413 ms 656 KB Output is correct