Submission #527151

# Submission time Handle Problem Language Result Execution time Memory
527151 2022-02-17T02:49:17 Z joelau Calvinball championship (CEOI15_teams) C++14
70 / 100
881 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;

long long N, A[10005], p = 1000007;
map<long long,long long> mp[10005];

long long dp (long long n, long long m) {
    if (n == N+1) return 1;
    if (mp[n].find(m) != mp[n].end()) return mp[n][m];
    return mp[n][m] = (dp(n+1,m) * m + dp(n+1,m+1)) % p;
}

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 720 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 8612 KB Output is correct
2 Correct 45 ms 8548 KB Output is correct
3 Correct 41 ms 8608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 324 ms 32188 KB Output is correct
2 Correct 288 ms 32076 KB Output is correct
3 Correct 305 ms 32108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 741 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 881 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 763 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -