답안 #856532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856532 2023-10-03T19:10:12 Z aymanrs Calvinball championship (CEOI15_teams) C++14
100 / 100
143 ms 604 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();
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 344 KB Output is correct
2 Correct 38 ms 344 KB Output is correct
3 Correct 42 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 604 KB Output is correct
2 Correct 139 ms 580 KB Output is correct
3 Correct 143 ms 604 KB Output is correct