Submission #1111917

#TimeUsernameProblemLanguageResultExecution timeMemory
1111917Ghulam_JunaidCalvinball championship (CEOI15_teams)C++17
0 / 100
187 ms1016 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e4 + 10; const ll mod = 1e6 + 7; ll n, ans, a[N], dp[2][N]; int main(){ cin >> n; ll mx = 0; vector<pair<int, int>> vec; vector<int> vals; for (ll i=1; i<=n; i++){ cin >> a[i]; if (i < n) vec.push_back({i + 1, mx + 1}); mx = max(mx, a[i]); } vec.push_back({n, a[n]}); for (ll i=n; i>0; i--){ for (ll j=1; j<=n; j++){ if (i==n){ dp[i % 2][j] = dp[i % 2][j-1] + 1; continue; } dp[i % 2][j] = (j-1) * dp[(i+1) % 2][j] + dp[(i+1) % 2][j+1]; dp[i % 2][j] %= mod; } while (vec.size() and vec.back().first == i){ vals.push_back(dp[i % 2][vec.back().second]); vec.pop_back(); } } reverse(vals.begin(), vals.end()); mx = 0; for (ll i=1; i<n; i++){ ans += (a[i] - 1) * vals.back(); vals.pop_back(); ans %= mod; mx = max(mx, a[i]); } ans += vals.back(); ans %= mod; 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...