Submission #113015

#TimeUsernameProblemLanguageResultExecution timeMemory
113015ckodserCalvinball championship (CEOI15_teams)C++14
100 / 100
207 ms696 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define ld long double #define F first #define S second #define pii pair<ll,ll> using namespace :: std; const ll mod=1e6+7; const ll maxn=10010; ll a[maxn]; ll f[2][maxn]; ll mx[maxn]; inline void jam(ll &a,ll b){ a+=b; if(a>=mod)a-=mod; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll n; cin>>n; for(ll i=0;i<n;i++){ cin>>a[i]; } mx[0]=a[0]; for(ll i=1;i<n;i++){ mx[i]=max(mx[i-1],a[i]); } ll ans=1; for(ll i=0;i<maxn;i++){ f[0][i]=1; } for(ll i=n-1;i>=1;i--){ jam(ans,((a[i]-1)*f[(n-i-1)&1][mx[i-1]])%mod); bool no=(n-i)&1; bool la=(n-i-1)&1; for(ll j=0;j+1<maxn;j++){ f[no][j]=(f[la][j+1]+f[la][j]*j)%mod; } } cout<<ans; }
#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...