답안 #110619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110619 2019-05-11T14:18:39 Z someone_aa Calvinball championship (CEOI15_teams) C++17
100 / 100
273 ms 760 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 11000;
const ll mod = 1000007LL;
ll dp[2][maxn];
ll a[maxn], n;
ll prefmax[maxn];


int main() {
    // dp[i][j] -> If we are given a sequence of arbitrary length and maximum element j,
    // on how many ways can we extend it if we can add exactly i elements
    cin>>n;
    prefmax[0] = 1LL;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        prefmax[i] = max(prefmax[i-1], a[i]);
    }

    for(int i=1;i<=n;i++) {
        dp[0][i] = 1LL;
    }

    ll result = 0LL;
    for(int i=n;i>=1;i--) {
        for(int j=1;j<=n;j++) {
            int d = n - i + 1;
            dp[d%2][j] = j*dp[(d-1)%2][j] + dp[(d-1)%2][j+1];
            dp[d%2][j] %= mod;
        }
        result += (a[i]-1)*(dp[(n-i)%2][prefmax[i-1]]);
        result %= mod;
    }
    cout<<(result+1)%mod;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 6 ms 428 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 572 KB Output is correct
2 Correct 51 ms 584 KB Output is correct
3 Correct 51 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 696 KB Output is correct
2 Correct 200 ms 760 KB Output is correct
3 Correct 273 ms 736 KB Output is correct