# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
765813 |
2023-06-25T05:48:10 Z |
khshg |
Meetings (IOI18_meetings) |
C++14 |
|
5500 ms |
22112 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
#define mp make_pair
#define ff first
#define ss second
#define ar array
template<class T> using V = vector<T>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<ld>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;
#define sz(x) (int)((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define rep(a) F0R(_, a)
#define trav(a, x) for(auto& a : x)
template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); }
template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); }
const ll INF = 0x3f3f3f3f3f3f3f3f;
vl minimum_costs(vi H, vi L, vi R) {
int N = sz(H);
V<vpl> toL(N), toR(N);
F0R(i, N) {
if(i) toL[i] = toL[i - 1];
while(sz(toL[i]) && H[toL[i].bk.ff] <= H[i]) {
toL[i].pop_back();
}
toL[i].eb(i, 0);
}
R0F(i, N) {
if(i + 1 < N) toR[i] = toR[i + 1];
while(sz(toR[i]) && H[toR[i].bk.ff] <= H[i]) {
toR[i].pop_back();
}
toR[i].eb(i, 0);
}
F0R(i, N) {
reverse(all(toL[i]));
toL[i].eb(-1, 0);
F0R(j, sz(toL[i]) - 1) {
toL[i][j].ss = (toL[i][j].ff - toL[i][j + 1].ff) * H[toL[i][j].ff] + (j ? toL[i][j - 1].ss : 0);
}
reverse(all(toL[i]));
reverse(all(toR[i]));
toR[i].eb(N, 0);
F0R(j, sz(toR[i]) - 1) {
toR[i][j].ss = (toR[i][j + 1].ff - toR[i][j].ff) * H[toR[i][j].ff] + (j ? toR[i][j - 1].ss : 0);
}
}
int Q = sz(L);
vl ans(Q, INF);
F0R(q, Q) {
FOR(i, L[q], R[q] + 1) {
ll x = ub(all(toR[i]), mp((ll)R[q], INF)) - bg(toR[i]) - 1;
ll rsd = (x > 0 ? toR[i][x - 1].ss : 0LL) + 1LL * (R[q] - toR[i][x].ff + 1) * H[toR[i][x].ff];
ll y = lb(all(toL[i]), mp((ll)L[q], 0LL)) - bg(toL[i]);
ll lsd = (y + 1 < sz(toL[i]) ? toL[i][y + 1].ss : 0LL) + (toL[i][y].ff - L[q] + 1) * H[toL[i][y].ff];
ckmin(ans[q], lsd + rsd - (ll)H[i]);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
2 ms |
1748 KB |
Output is correct |
4 |
Correct |
2 ms |
1620 KB |
Output is correct |
5 |
Correct |
2 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
2 ms |
1748 KB |
Output is correct |
4 |
Correct |
2 ms |
1620 KB |
Output is correct |
5 |
Correct |
2 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
171 ms |
3116 KB |
Output is correct |
11 |
Correct |
482 ms |
3324 KB |
Output is correct |
12 |
Correct |
153 ms |
2736 KB |
Output is correct |
13 |
Correct |
411 ms |
2788 KB |
Output is correct |
14 |
Correct |
67 ms |
1492 KB |
Output is correct |
15 |
Correct |
134 ms |
2672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1618 ms |
3044 KB |
Output is correct |
3 |
Execution timed out |
5537 ms |
22112 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1618 ms |
3044 KB |
Output is correct |
3 |
Execution timed out |
5537 ms |
22112 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
2 ms |
1748 KB |
Output is correct |
4 |
Correct |
2 ms |
1620 KB |
Output is correct |
5 |
Correct |
2 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
171 ms |
3116 KB |
Output is correct |
11 |
Correct |
482 ms |
3324 KB |
Output is correct |
12 |
Correct |
153 ms |
2736 KB |
Output is correct |
13 |
Correct |
411 ms |
2788 KB |
Output is correct |
14 |
Correct |
67 ms |
1492 KB |
Output is correct |
15 |
Correct |
134 ms |
2672 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1618 ms |
3044 KB |
Output is correct |
18 |
Execution timed out |
5537 ms |
22112 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |