Submission #1111919

# Submission time Handle Problem Language Result Execution time Memory
1111919 2024-11-13T10:37:24 Z Ghulam_Junaid Calvinball championship (CEOI15_teams) C++17
100 / 100
202 ms 1052 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const ll N = 1e4 + 10;
const ll mod = 1e6 + 7;
ll n, ans, a[N], dp[2][N];

int main(){
    cin >> n;

    ll mx = 0;
    vector<pair<ll, ll>> vec;
    vector<ll> vals;
    for (ll i=1; i<=n; i++){
        cin >> a[i];
        if (i < n)
            vec.push_back({i + 1, mx + 1});
        mx = max(mx, a[i]);
    }
    vec.push_back({n, a[n]});

    for (ll i=n; i>0; i--){
        for (ll j=1; j<=n; j++){
            if (i==n){
                dp[i % 2][j] = dp[i % 2][j-1] + 1;
                continue;
            }
            dp[i % 2][j] = (j-1) * dp[(i+1) % 2][j] + dp[(i+1) % 2][j+1];
            dp[i % 2][j] %= mod;
        }
        while (vec.size() and vec.back().first == i){
            vals.push_back(dp[i % 2][vec.back().second]);
            vec.pop_back();
        }
    }
 
    mx = 0;
    for (ll i=1; i<n; i++){
        ans += (a[i] - 1) * vals.back();
        vals.pop_back();
        ans %= mod;
        mx = max(mx, a[i]);
    }
    ans += vals.back();
    ans %= mod;
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 3 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 592 KB Output is correct
2 Correct 43 ms 592 KB Output is correct
3 Correct 48 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 964 KB Output is correct
2 Correct 202 ms 1052 KB Output is correct
3 Correct 170 ms 1000 KB Output is correct