Submission #856531

# Submission time Handle Problem Language Result Execution time Memory
856531 2023-10-03T19:09:55 Z aymanrs Calvinball championship (CEOI15_teams) C++14
100 / 100
147 ms 632 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
const int M = 1e6+7;
void solve(){
    int n;
    cin >> n;
    int a[n], b[n];
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        a[i]--;
        if(i) b[i]=max(b[i-1], a[i]);
        else b[0]=a[0];
    }
    long long dp[n];
    fill(dp,dp+n, 1);
    long long ans = 1;
    for(int i = n-1;i;i--){
        ans += a[i]*dp[b[i-1]];
        ans%=M;
        for(int j = 0;j < n-1;j++){
            dp[j] = ((j+1)*dp[j] + dp[j+1])%M;
        }
        dp[n-1]=0;
    }
    cout << ans << '\n';
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 344 KB Output is correct
2 Correct 33 ms 520 KB Output is correct
3 Correct 33 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 348 KB Output is correct
2 Correct 147 ms 600 KB Output is correct
3 Correct 127 ms 632 KB Output is correct