Submission #563632

# Submission time Handle Problem Language Result Execution time Memory
563632 2022-05-17T19:12:57 Z piOOE Calvinball championship (CEOI15_teams) C++17
100 / 100
300 ms 468 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 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<int> dp(n + 1, 1);
    int ans = 0;
    for (int i = n - 1; i > -1; --i) {
        if (i) {
            int mx = *max_element(begin(a), begin(a) + i);
            ans = (ans + dp[mx] * 1LL * (a[i] - 1)) % mod;
        }
        vector<int> dpp(n + 1);
        for (int cnt = 1; cnt <= n; ++cnt) {
            dpp[cnt] = (dp[cnt] * 1LL * cnt + (cnt < n ? dp[cnt + 1] : 0)) % mod;
        }
        swap(dp, dpp);
    }
    cout << (ans + 1) % mod;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 212 KB Output is correct
3 Correct 0 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 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 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
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 3 ms 328 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 300 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 360 KB Output is correct
2 Correct 70 ms 340 KB Output is correct
3 Correct 66 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 340 KB Output is correct
2 Correct 276 ms 340 KB Output is correct
3 Correct 265 ms 468 KB Output is correct