Submission #529152

#TimeUsernameProblemLanguageResultExecution timeMemory
529152codr0Calvinball championship (CEOI15_teams)C++14
10 / 100
821 ms716 KiB
// Code by Parsa Eslami #include <bits/stdc++.h> #define pii pair<int,int> #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORR(i,a,b) for(int i=a;i>=b;i--) #define S second #define F first #define pb push_back #define SZ(x) (int)x.size() #define all(x) x.begin(),x.end() #define err(x) cout<<#x<<": "<<x<<'\n'; using namespace std; const int MOD=1e6+7; const int N=1e4+5; int dp[2][N]; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; int ans=0; int mx[n+1]={}; int a[n+1]={}; FOR(i,1,n){ cin>>a[i]; mx[i]=max(mx[i-1],a[i]); } ans=a[n]; dp[(n%2)][0]=1; FOR(i,1,n){ dp[(n%2)][i]=(1LL*dp[(n%2)][i-1]*n)%MOD; } int ind=n-1; FORR(j,n-1,1){ FOR(i,0,n){ if(i==0) {dp[(j%2)][i]=1; continue;} dp[(j%2)][i]=(1LL*dp[(j+1)%2][i-1]+1LL*dp[(j%2)][i-1]*j)%MOD; } while(ind>0&&mx[ind-1]==j){ ans=(1LL*ans+1LL*(a[ind]-1)*dp[j][n-ind])%MOD; ind--; } } cout<<ans<<'\n'; 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...