# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
808996 |
2023-08-05T13:37:29 Z |
jakobrs |
Wombats (IOI13_wombats) |
C++17 |
|
51 ms |
18152 KB |
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#ifndef EVAL
#include <iostream>
#endif
#include "wombats.h"
#define entire(a) std::begin((a)), std::end((a))
const int64_t INF = 2'000'000'000'000;
struct Matrix {
int64_t a1 = 0, a2 = INF, b1 = INF, b2 = 0;
Matrix operator*(const Matrix &rhs) const {
return {
.a1 = std::min(a1 + rhs.a1, b1 + rhs.a2),
.a2 = std::min(b2 + rhs.a2, a2 + rhs.a1),
.b1 = std::min(a1 + rhs.b1, b1 + rhs.b2),
.b2 = std::min(b2 + rhs.b2, a2 + rhs.b1),
};
}
};
template <typename T>
struct SegmentTree {
std::vector<T> values;
int offset;
SegmentTree() : values(), offset() {}
explicit SegmentTree(int sz) : values(2 * sz), offset(sz) {}
void update(int i, T value) {
i += offset;
values[i] = value;
propagate(i);
}
void propagate(int i) {
while (i /= 2) values[i] = values[2 * i] * values[2 * i + 1];
}
T query(int l, int r) {
l += offset;
r += offset;
T left, right;
while (l < r) {
if (l & 1) left = left * values[l++];
if (r & 1) right = values[--r] * right;
l >>= 1;
r >>= 1;
}
return left * right;
}
};
std::vector<std::vector<int>> h, v;
int r, c;
SegmentTree<Matrix> st;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
h.reserve(R);
v.reserve(R);
for (int i = 0; i < R; i++) {
h.emplace_back(entire(H[i]));
v.emplace_back(entire(V[i]));
}
r = R;
c = C;
int o = 1;
while (o < 2 * R) o *= 2;
st = SegmentTree<Matrix>(o);
for (int i = 0; i < R; i++) {
st.update(2 * i, {
.a1 = 0,
.a2 = H[i][0],
.b1 = H[i][0],
.b2 = 0,
});
if (i + 1 < R) {
st.update(2 * i + 1, {
.a1 = V[i][0],
.a2 = INF,
.b1 = INF,
.b2 = V[i][1],
});
}
}
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
st.update(2 * P, {
.a1 = 0,
.a2 = h[P][0],
.b1 = h[P][0],
.b2 = 0,
});
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
st.update(2 * P + 1, {
.a1 = v[P][0],
.a2 = INF,
.b1 = INF,
.b2 = v[P][1],
});
}
int escape(int V1, int V2) {
auto res = st.query(0, 2 * r);
if (V1 == 0 && V2 == 0)
return res.a1;
else if (V1 == 0 && V2 == 1)
return res.b1;
else if (V1 == 1 && V2 == 0)
return res.a2;
else if (V1 == 1 && V2 == 1)
return res.b2;
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:132:1: warning: control reaches end of non-void function [-Wreturn-type]
132 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
13396 KB |
Output is correct |
2 |
Incorrect |
8 ms |
13396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
17364 KB |
Output is correct |
2 |
Correct |
10 ms |
17252 KB |
Output is correct |
3 |
Correct |
11 ms |
17364 KB |
Output is correct |
4 |
Correct |
51 ms |
18152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |