Submission #563630

# Submission time Handle Problem Language Result Execution time Memory
563630 2022-05-17T19:05:44 Z piOOE Calvinball championship (CEOI15_teams) C++17
70 / 100
32 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)
#define sz(x) ((int)size(x))
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

const int mod = 1'000'007;

int add(int a, int b) {
    return a + b < mod ? a + b : a + b - mod;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    //cnt, len
    for (int cnt = n; cnt > -1; --cnt) {
        dp[cnt][0] = 1;
        for (int len = 1; len <= n; ++len) {
            dp[cnt][len] = (dp[cnt][len - 1] * cnt + (cnt < n ? dp[cnt + 1][len - 1] : 0)) % mod;
        }
    }
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        ans = (ans + dp[cnt][n - i - 1] * (a[i] - 1)) % mod;
        cnt = max(cnt, a[i]);
    }
    cout << (ans + 1) % mod;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 3 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4200 KB Output is correct
2 Correct 10 ms 4288 KB Output is correct
3 Correct 10 ms 4284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -