Submission #573339

# Submission time Handle Problem Language Result Execution time Memory
573339 2022-06-06T12:32:50 Z vladislav11 Calvinball championship (CEOI15_teams) C++14
100 / 100
398 ms 720 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll MOD = 1e6 + 7;

int n;
vector<int> a;
ll dp[10100];
ll dp0[10100];

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    a.resize( n );

    for ( auto& el : a )
        cin >> el;

    for ( int i=1; i <= n; i++ )
        dp[i] = 1;

    ll ans = 1;

    vector<int> maxi( n+1, 0 );

    maxi[0] = 0;

    for ( int i=0; i<n; i++ )
        maxi[i+1] = max( maxi[i], a[i] );

    for ( int i=n-1; i >= 0; i-- )
    {
        for ( int j=1; j<a[i]; j++ )
            ans = ( ans + dp[ max( maxi[i], j ) ] ) % MOD;

        for ( int j=1; j<=n; j++ )
            dp0[j] = dp[j];

        for ( int j=1; j<=n; j++ )
            dp[j] = ( j*dp0[j] + ( j<n ? dp0[j+1] : 0 ) ) % MOD;
    }

    cout << ans;

    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 0 ms 328 KB Output is correct
6 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 1 ms 212 KB Output is correct
3 Correct 1 ms 324 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 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 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 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 456 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 340 KB Output is correct
2 Correct 59 ms 468 KB Output is correct
3 Correct 100 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 576 KB Output is correct
2 Correct 211 ms 568 KB Output is correct
3 Correct 393 ms 720 KB Output is correct