Submission #587974

#TimeUsernameProblemLanguageResultExecution timeMemory
587974BlagojceCalvinball championship (CEOI15_teams)C++11
100 / 100
259 ms560 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int mxn = 10004; const ll mod = 1000007; int a[mxn]; int n; ll DP1[mxn]; ll DP2[mxn]; int main(){ cin >> n; fr(i, 0, n){ cin >> a[i]; } int mx[n]; int c = 0; fr(i, 0, n){ c = max(c, a[i]); mx[i] = c; } ll ans = 1; fr(i, 0, n+1) DP1[i] = 1; for(int i = n-1; i >= 0; i --){ int nxt = 1; if(i > 0) nxt = mx[i-1]; ans += ((a[i]-1) * DP1[nxt]) % mod; ans %= mod; fr(j, 0, n+1){ DP2[j] = (DP1[j+1] + j*DP1[j]) % mod; } fr(j, 0, n+1){ DP1[j] = DP2[j]; } } cout<<ans<<endl; }
#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...