Submission #65330

#TimeUsernameProblemLanguageResultExecution timeMemory
65330bazsi700Calvinball championship (CEOI15_teams)C++14
100 / 100
386 ms1200 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...