Submission #527110

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

int MOD = 1000007;

vector<int> seq;
vector<vector<vector<int> > > dp;

int recurse(int strict, int i, int maxN) {

    if (dp[strict][i][maxN] > -1) {
        return dp[strict][i][maxN];
    }

    if (i==0) {
        if (strict) return dp[strict][i][maxN] = seq[i];
        else return dp[strict][i][maxN] = (maxN + 1);
    }

    int poss = 0;

    if (strict) {
        poss += recurse(1, i-1, max(seq[i], maxN));
        poss %= MOD;
        if (seq[i]>1) poss += (seq[i]-1) * recurse(0, i-1, maxN);
        poss %= MOD;
    } else {
        poss += maxN * recurse(0, i-1, maxN);
        poss %= MOD;
        poss += recurse(0, i-1, maxN+1);
        poss %= MOD;
    }

    dp[strict][i][maxN] = poss;
    return poss;

}

int main() {

    int N;cin>>N;
    seq.assign(N, 0);
    dp.assign(2, vector<vector<int> >(N, vector<int>(N+1, -1)));

    for (int i = N-1; i >= 0; i--) {
        cin >> seq[i];
    }

    cout << recurse(1, N-1, 1) << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3276 KB Output is correct
2 Correct 4 ms 3276 KB Output is correct
3 Correct 4 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 12108 KB Output is correct
2 Correct 17 ms 12108 KB Output is correct
3 Correct 21 ms 12232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -