Submission #65330

# Submission time Handle Problem Language Result Execution time Memory
65330 2018-08-07T11:50:48 Z bazsi700 Calvinball championship (CEOI15_teams) C++14
100 / 100
386 ms 1200 KB
#include <bits/stdc++.h>

using namespace std;
#define MOD 1000007
#define ll long long int

ll dp[10005];
ll dp2[10005];

void calc() {
    for(ll i = 1; i <= 10000; i++) {
        dp2[i] = (dp[i+1]+dp[i]*i)%MOD;
    }
    for(int i = 1; i <= 10000; i++) {
        dp[i] = dp2[i];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> arr(n);
    /*for(int i = 0; i < n; i++) {
        arr[i] = 1;
    }
    int x = 1;
    while(arr[0] == 1) {*/
    vector<int> cnt(n+1,0);
    ll mx = 0;
    for(int i = 0; i < n; i++) {
    //cout << arr[i] << " ";
        dp[i] = 1;
        cin >> arr[i];
        cnt[arr[i]]++;
        mx = max(arr[i],mx);
    }
    dp[n] = 1;
    ll ans = 1;
    for(ll i = n-1; i >= 0; i--) {
        if(arr[i] > 1) {
          //  cout << i << " " << arr[i] << " " << dp[arr[i]] << " " << dp[arr[i-1]] << " " << cnt[arr[i]] << endl;
            if(cnt[arr[i]] == 1) {
                mx--;
            }
            ans+= ((arr[i]-1)*dp[mx])%MOD;

        }
        calc();
        cnt[arr[i]]--;
    }
    cout << ans%MOD;
   /*   cout << x << " " << ans%MOD << "\n";
        bool did = false;
        for(int i = 0; i < n; i++) {
        //    cin >> arr[i];
            cnt[arr[i]]++;
        }
        for(int i = n-1; i > 0; i--) {
            if(cnt[arr[i]] > 1) {
                arr[i]++;
                did = true;
                for(int j = i+1; j < n; j++) {
                    arr[j] = 1;
                }
                break;
            }
        }
        x++;
        if(!did) {
        break;
        }
    }*/
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 716 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 764 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 8 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 772 KB Output is correct
2 Correct 21 ms 772 KB Output is correct
3 Correct 22 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 836 KB Output is correct
2 Correct 38 ms 836 KB Output is correct
3 Correct 35 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 361 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 996 KB Output is correct
2 Correct 168 ms 996 KB Output is correct
3 Correct 187 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 386 ms 1084 KB Output is correct
2 Correct 341 ms 1132 KB Output is correct
3 Correct 373 ms 1200 KB Output is correct