Submission #1032834

#TimeUsernameProblemLanguageResultExecution timeMemory
1032834AmirAli_H1Meetings (IOI18_meetings)C++17
19 / 100
293 ms186964 KiB
// In the name of Allah #include <bits/stdc++.h> #include "meetings.h" using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = (1 << 20) + 4; const int maxs = 5000 + 4; int n, q; ll A[maxn]; pii Q[maxn]; int mx[maxs][maxs]; ll dp[maxs][maxs]; vector<ll> res; void solve1() { for (int ln = 1; ln <= n; ln++) { for (int l = 0, r = ln; r <= n; l++, r++) { if (ln == 1) mx[l][r] = l; else { if (A[l] >= A[mx[l + 1][r]]) mx[l][r] = l; else mx[l][r] = mx[l + 1][r]; } } } for (int ln = 0; ln <= n; ln++) { for (int l = 0, r = ln; r <= n; l++, r++) { if (ln == 0) dp[l][r] = 0; else { int j = mx[l][r]; dp[l][r] = min(dp[l][j] + (r - j) * A[j], dp[j + 1][r] + (j + 1 - l) * A[j]); } } } for (int i = 0; i < q; i++) { int l = Q[i].F, r = Q[i].S; res[i] = dp[l][r]; } } void solve2() { } vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R) { n = len(H); q = len(L); for (int i = 0; i < n; i++) A[i] = H[i]; for (int i = 0; i < q; i++) Q[i] = Mp(L[i], R[i] + 1); res.resize(q); if (n < maxs) solve1(); else solve2(); return res; }
#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...