Submission #529296

#TimeUsernameProblemLanguageResultExecution timeMemory
529296radalCalvinball championship (CEOI15_teams)C++14
100 / 100
426 ms496 KiB
#include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define X first #define Y second #define pb push_back #define endl '\n' #define debug(x) cerr << #x << " : " << x << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pll; constexpr int N = 1e4+20,mod = 1e6+7,inf = 1e9+10; inline int mkay(int a,int b){ if (a+b >= mod) return a+b-mod; if (a+b < 0) return a+b+mod; return a+b; } inline int poww(int a,int k){ if (k < 0) return 0; int z = 1; while (k){ if (k&1) z = 1ll*z*a%mod; a = 1ll*a*a%mod; k >>= 1; } return z; } int a[N],mx[N]; int dp[2][N],n; int main(){ ios :: sync_with_stdio(0); cin.tie(0); cin >> n; rep(i,1,n+1){ cin >> a[i]; mx[i] = max(mx[i-1],a[i]); } int ans = 1; bool f = (n&1); f = 1-f; rep(j,0,n+1){ dp[f][j] = 1; } repr(i,n,1){ int d = (i&1); int g = 1ll*(a[i]-1)*dp[1-d][mx[i-1]]%mod; ans = mkay(ans,g); rep(j,0,i+1){ dp[d][j] = mkay(dp[1-d][j+1],1ll*dp[1-d][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...