Submission #530741

#TimeUsernameProblemLanguageResultExecution timeMemory
530741Yazan_AlattarCalvinball championship (CEOI15_teams)C++14
100 / 100
595 ms716 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define F first #define S second #define pb push_back #define endl "\n" #define all(x) x.begin(), x.end() const int M = 10007; const ll inf = 2e9; const ll mod = 1e6 + 7; const double pi = acos(-1); const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0}; const int block = 320; ll n, a[M], pref[M], ans = 1; vector <ll> dp(M), old(M); ll getDp(int j){ return (dp[j] - dp[j - 1] + mod) % mod; } ll getOld(int j){ return (old[j] - old[j - 1] + mod) % mod; } int main(){ cin >> n; for(int i = 1; i <= n; ++i) cin >> a[i], pref[i] = max(pref[i - 1], a[i]); for(int i = n; i; --i){ for(ll j = 1; j <= i; ++j){ if(i == n) dp[j] = j; else{ dp[j] = dp[j - 1]; dp[j] = (dp[j] + getOld(j + 1)) % mod; dp[j] = (dp[j] + getOld(j) * j) % mod; } } ll add = getDp(pref[i - 1]) * min(pref[i - 1], a[i] - 1); if(a[i] > pref[i - 1]) add = (add + dp[a[i] - 1] - dp[pref[i - 1]] + mod) % mod; ans = (ans + add) % mod; swap(old, dp); for(int i = 0; i <= n; ++i) dp[i] = 0; } cout << ans << endl; 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...