#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll linf = ll(1e18);
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;
#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())
#define all(x) begin(x),end(x)
#if _LOCAL
#define assert(x) if (!(x)) __debugbreak()
#endif
typedef vector<ll> vll;
struct node
{
int best, l, r;
int mid;
node *lc, *rc;
};
vll h;
int n;
node* build_tree(int l, int r)
{
return 0;
}
ll solve(int l, int r)
{
if (l > r) return 0;
if (r < l) return 0;
if (l==r)
{
return h[l];
}
ll largest = 0;
repp(i, l, r + 1) largest = max(largest, h[i]);
ll ret = (r - l + 1) * largest;
vll lindex;
repp(i, l, r + 1) if (h[i] == largest) lindex.push_back(i);
int split = lindex[sz(lindex) / 2];
ll tot_len = r - l + 1;
ret = min(ret, (r - (split + 1) + 2) * largest + solve(l, split-1));
ret = min(ret, ((split - 1) - l + 2) * largest + solve(split + 1, r));
return ret;
}
vll minimum_costs(vi H, std::vector<int> L, std::vector<int> R)
{
h = vll(H.begin(), H.end());
n = sz(h);
build_tree(0, n - 1);
int q = sz(L);
vll ret(q);
rep(qu, q)
{
int l = L[qu];
int r = R[qu];
ret[qu] = solve(l, r);
}
return ret;
}
Compilation message
meetings.cpp: In function 'll solve(int, int)':
meetings.cpp:56:5: warning: unused variable 'tot_len' [-Wunused-variable]
56 | ll tot_len = r - l + 1;
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
301 ms |
604 KB |
Output is correct |
11 |
Correct |
1016 ms |
604 KB |
Output is correct |
12 |
Correct |
281 ms |
604 KB |
Output is correct |
13 |
Correct |
963 ms |
624 KB |
Output is correct |
14 |
Correct |
334 ms |
604 KB |
Output is correct |
15 |
Correct |
200 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
5587 ms |
1628 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
5587 ms |
1628 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
301 ms |
604 KB |
Output is correct |
11 |
Correct |
1016 ms |
604 KB |
Output is correct |
12 |
Correct |
281 ms |
604 KB |
Output is correct |
13 |
Correct |
963 ms |
624 KB |
Output is correct |
14 |
Correct |
334 ms |
604 KB |
Output is correct |
15 |
Correct |
200 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
5587 ms |
1628 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |