# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106477 |
2024-10-30T12:37:49 Z |
Octagons |
Nile (IOI24_nile) |
C++17 |
|
263 ms |
32700 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node {
ll a[3][3];
} t[(1 << 19)];
int n;
ll cd, dp[20];
vector<array<ll, 3>> v;
bool ok(int i, int j) {
if (i < 0 || j >= n)return false;
return (v[j][0] - v[i][0] <= cd);
}
ll pr(int i, int j) {
return v[i][1] + v[j][1];
}
ll clc(int l, int r) {
if (l == r)return v[l][2];
int sz = r-l+1;
dp[sz] = 0;
for (int j = sz-1, cur = r; j >= 0; j--, cur--) {
dp[j] = v[cur][2] + dp[j+1];
if (j+1 < sz && ok(cur, cur+1)) {
dp[j] = min(dp[j], pr(cur, cur+1) + dp[j+2]);
}
if (j+2 < sz && ok(cur, cur+2)) {
dp[j] = min(dp[j], dp[j+3] + pr(cur, cur+2) + v[cur+1][2]);
}
}
return dp[0];
}
void calc(int l, int r, int x) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i + j > r - l + 1) {
t[x].a[i][j] = 1e18;
continue;
}
t[x].a[i][j] = clc(l + i, r - j);
}
}
}
node merge(node &lef, node &rig, int m) {
node ret;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
ret.a[i][j] = lef.a[i][0] + rig.a[0][j];
if (ok(m, m+1)) {
ret.a[i][j] = min(ret.a[i][j], lef.a[i][1] + rig.a[1][j] + pr(m, m+1));
}
if (ok(m, m+2)) {
ret.a[i][j] = min(ret.a[i][j], lef.a[i][1] + rig.a[2][j] + pr(m, m+2) + v[m+1][2]);
}
if (ok(m-1, m+1)) {
ret.a[i][j] = min(ret.a[i][j], lef.a[i][2] + rig.a[1][j] + pr(m-1, m+1) + v[m][2]);
}
}
}
return ret;
}
void build(int l, int r, int x) {
if (l == r) {
calc(l, r, x);
return;
}
int m = (l + r) >> 1;
build(l, m, x * 2 + 1);
build(m+1, r, x * 2 + 2);
if (min(m-l+1, r-m) < 4) {
calc(l, r, x);
return;
}
t[x] = merge(t[x*2+1], t[x*2+2], m);
}
void upd(int l, int r, int x, int i) {
if (l == r)return;
int m = (l + r) >> 1;
if (i <= m) {
upd(l, m, x * 2 + 1, i);
} else {
upd(m+1, r, x * 2 + 2, i);
}
if (min(m-l+1, r-m) < 4) {
calc(l, r, x);
return;
}
t[x] = merge(t[x*2+1], t[x*2+2], m);
}
void init() {
cd = 0;
build(0, n - 1, 0);
}
vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int q = E.size();
vector<ll> ans(q);
n = W.size();
vector<pair<int, int>> qr(q);
for (int i = 0; i < q; i++) {
qr[i] = {E[i], i};
}
v.resize(n);
for (int i = 0; i < n; i++) {
v[i] = {W[i], B[i], A[i]};
}
sort(qr.begin(), qr.end());
sort(v.begin(), v.end());
init();
vector<pair<int, int>> a;
for (int i = 1; i < n; i++) {
a.push_back({v[i][0] - v[i-1][0], i});
if (i > 1)a.push_back({v[i][0] - v[i-2][0], i});
}
sort(a.begin(), a.end());
int cur = 0;
for (auto &[d, id] : qr) {
cd = d;
while (cur < a.size() && a[cur].first <= cd) {
upd(0, n-1, 0, a[cur++].second);
}
ans[id] = t[0].a[0][0];
}
return ans;
}
Compilation message
nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:127:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | while (cur < a.size() && a[cur].first <= cd) {
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2812 KB |
Output is correct |
2 |
Correct |
4 ms |
2640 KB |
Output is correct |
3 |
Correct |
4 ms |
2640 KB |
Output is correct |
4 |
Correct |
4 ms |
2640 KB |
Output is correct |
5 |
Correct |
4 ms |
2640 KB |
Output is correct |
6 |
Correct |
4 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
27580 KB |
Output is correct |
2 |
Correct |
180 ms |
29196 KB |
Output is correct |
3 |
Correct |
179 ms |
26820 KB |
Output is correct |
4 |
Correct |
185 ms |
29116 KB |
Output is correct |
5 |
Correct |
178 ms |
26820 KB |
Output is correct |
6 |
Correct |
179 ms |
26824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
26812 KB |
Output is correct |
2 |
Correct |
180 ms |
27104 KB |
Output is correct |
3 |
Correct |
199 ms |
26812 KB |
Output is correct |
4 |
Correct |
209 ms |
26816 KB |
Output is correct |
5 |
Correct |
200 ms |
27108 KB |
Output is correct |
6 |
Correct |
218 ms |
28360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2812 KB |
Output is correct |
2 |
Correct |
4 ms |
2640 KB |
Output is correct |
3 |
Correct |
4 ms |
2640 KB |
Output is correct |
4 |
Correct |
4 ms |
2640 KB |
Output is correct |
5 |
Correct |
4 ms |
2640 KB |
Output is correct |
6 |
Correct |
4 ms |
2640 KB |
Output is correct |
7 |
Correct |
4 ms |
2640 KB |
Output is correct |
8 |
Correct |
4 ms |
2640 KB |
Output is correct |
9 |
Correct |
6 ms |
2640 KB |
Output is correct |
10 |
Correct |
4 ms |
2996 KB |
Output is correct |
11 |
Correct |
4 ms |
2640 KB |
Output is correct |
12 |
Correct |
4 ms |
2820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2812 KB |
Output is correct |
2 |
Correct |
4 ms |
2640 KB |
Output is correct |
3 |
Correct |
4 ms |
2640 KB |
Output is correct |
4 |
Correct |
4 ms |
2640 KB |
Output is correct |
5 |
Correct |
4 ms |
2640 KB |
Output is correct |
6 |
Correct |
4 ms |
2640 KB |
Output is correct |
7 |
Correct |
185 ms |
27580 KB |
Output is correct |
8 |
Correct |
180 ms |
29196 KB |
Output is correct |
9 |
Correct |
179 ms |
26820 KB |
Output is correct |
10 |
Correct |
185 ms |
29116 KB |
Output is correct |
11 |
Correct |
178 ms |
26820 KB |
Output is correct |
12 |
Correct |
179 ms |
26824 KB |
Output is correct |
13 |
Correct |
189 ms |
26812 KB |
Output is correct |
14 |
Correct |
180 ms |
27104 KB |
Output is correct |
15 |
Correct |
199 ms |
26812 KB |
Output is correct |
16 |
Correct |
209 ms |
26816 KB |
Output is correct |
17 |
Correct |
200 ms |
27108 KB |
Output is correct |
18 |
Correct |
218 ms |
28360 KB |
Output is correct |
19 |
Correct |
4 ms |
2640 KB |
Output is correct |
20 |
Correct |
4 ms |
2640 KB |
Output is correct |
21 |
Correct |
6 ms |
2640 KB |
Output is correct |
22 |
Correct |
4 ms |
2996 KB |
Output is correct |
23 |
Correct |
4 ms |
2640 KB |
Output is correct |
24 |
Correct |
4 ms |
2820 KB |
Output is correct |
25 |
Correct |
186 ms |
26832 KB |
Output is correct |
26 |
Correct |
188 ms |
27836 KB |
Output is correct |
27 |
Correct |
217 ms |
27836 KB |
Output is correct |
28 |
Correct |
206 ms |
26812 KB |
Output is correct |
29 |
Correct |
201 ms |
26812 KB |
Output is correct |
30 |
Correct |
240 ms |
26812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
26812 KB |
Output is correct |
2 |
Correct |
180 ms |
27104 KB |
Output is correct |
3 |
Correct |
199 ms |
26812 KB |
Output is correct |
4 |
Correct |
209 ms |
26816 KB |
Output is correct |
5 |
Correct |
200 ms |
27108 KB |
Output is correct |
6 |
Correct |
218 ms |
28360 KB |
Output is correct |
7 |
Correct |
210 ms |
29932 KB |
Output is correct |
8 |
Correct |
210 ms |
29116 KB |
Output is correct |
9 |
Correct |
228 ms |
29952 KB |
Output is correct |
10 |
Correct |
238 ms |
29768 KB |
Output is correct |
11 |
Correct |
234 ms |
29940 KB |
Output is correct |
12 |
Correct |
244 ms |
29120 KB |
Output is correct |
13 |
Correct |
227 ms |
29116 KB |
Output is correct |
14 |
Correct |
216 ms |
29116 KB |
Output is correct |
15 |
Correct |
249 ms |
31164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
5 ms |
2812 KB |
Output is correct |
3 |
Correct |
4 ms |
2640 KB |
Output is correct |
4 |
Correct |
4 ms |
2640 KB |
Output is correct |
5 |
Correct |
4 ms |
2640 KB |
Output is correct |
6 |
Correct |
4 ms |
2640 KB |
Output is correct |
7 |
Correct |
4 ms |
2640 KB |
Output is correct |
8 |
Correct |
185 ms |
27580 KB |
Output is correct |
9 |
Correct |
180 ms |
29196 KB |
Output is correct |
10 |
Correct |
179 ms |
26820 KB |
Output is correct |
11 |
Correct |
185 ms |
29116 KB |
Output is correct |
12 |
Correct |
178 ms |
26820 KB |
Output is correct |
13 |
Correct |
179 ms |
26824 KB |
Output is correct |
14 |
Correct |
189 ms |
26812 KB |
Output is correct |
15 |
Correct |
180 ms |
27104 KB |
Output is correct |
16 |
Correct |
199 ms |
26812 KB |
Output is correct |
17 |
Correct |
209 ms |
26816 KB |
Output is correct |
18 |
Correct |
200 ms |
27108 KB |
Output is correct |
19 |
Correct |
218 ms |
28360 KB |
Output is correct |
20 |
Correct |
4 ms |
2640 KB |
Output is correct |
21 |
Correct |
4 ms |
2640 KB |
Output is correct |
22 |
Correct |
6 ms |
2640 KB |
Output is correct |
23 |
Correct |
4 ms |
2996 KB |
Output is correct |
24 |
Correct |
4 ms |
2640 KB |
Output is correct |
25 |
Correct |
4 ms |
2820 KB |
Output is correct |
26 |
Correct |
186 ms |
26832 KB |
Output is correct |
27 |
Correct |
188 ms |
27836 KB |
Output is correct |
28 |
Correct |
217 ms |
27836 KB |
Output is correct |
29 |
Correct |
206 ms |
26812 KB |
Output is correct |
30 |
Correct |
201 ms |
26812 KB |
Output is correct |
31 |
Correct |
240 ms |
26812 KB |
Output is correct |
32 |
Correct |
210 ms |
29932 KB |
Output is correct |
33 |
Correct |
210 ms |
29116 KB |
Output is correct |
34 |
Correct |
228 ms |
29952 KB |
Output is correct |
35 |
Correct |
238 ms |
29768 KB |
Output is correct |
36 |
Correct |
234 ms |
29940 KB |
Output is correct |
37 |
Correct |
244 ms |
29120 KB |
Output is correct |
38 |
Correct |
227 ms |
29116 KB |
Output is correct |
39 |
Correct |
216 ms |
29116 KB |
Output is correct |
40 |
Correct |
249 ms |
31164 KB |
Output is correct |
41 |
Correct |
213 ms |
30744 KB |
Output is correct |
42 |
Correct |
212 ms |
29260 KB |
Output is correct |
43 |
Correct |
239 ms |
29124 KB |
Output is correct |
44 |
Correct |
250 ms |
29116 KB |
Output is correct |
45 |
Correct |
256 ms |
29284 KB |
Output is correct |
46 |
Correct |
260 ms |
30652 KB |
Output is correct |
47 |
Correct |
253 ms |
30652 KB |
Output is correct |
48 |
Correct |
244 ms |
29124 KB |
Output is correct |
49 |
Correct |
263 ms |
32700 KB |
Output is correct |