Submission #679885

#TimeUsernameProblemLanguageResultExecution timeMemory
679885peijarCalvinball championship (CEOI15_teams)C++17
100 / 100
368 ms676 KiB
#include <bits/stdc++.h> #define int long long using namespace std; namespace std { template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { out << "["; for (int i = 0; i < (int)vec.size(); ++i) { out << vec[i]; if (i + 1 < (int)vec.size()) out << ", "; } return out << "]"; } } // namespace std void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const int MOD = 1e6 + 7; const int MAXN = 1e4 + 1; int fact[MAXN]; int DP[2][MAXN]; void init() { fact[0] = 1; for (int i = 1; i < MAXN; i++) fact[i] = i * fact[i - 1] % MOD; } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int &x : a) { cin >> x; } int ret = 0; vector<int> prefMax(n + 1); for (int i = 1; i < n; ++i) prefMax[i + 1] = max(prefMax[i], a[i]); for (int i = 1; i <= n; ++i) DP[0][i] = 1; for (int i = n - 1; i >= 1; --i) { int maxVu = prefMax[i]; int restant = n - i - 1; for (int val = 1; val < a[i]; ++val) { ret += DP[restant % 2][max(val, maxVu)]; dbg(i, val, ret); if (ret >= MOD) ret -= MOD; } int p = (restant + 1) % 2; for (int vu = 1; vu <= n; ++vu) { DP[p][vu] = vu * DP[!p][vu] % MOD; if (vu < n) { DP[p][vu] += DP[!p][vu + 1]; if (DP[p][vu] >= MOD) DP[p][vu] -= MOD; } } } cout << ret + 1 << 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...