# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
356674 |
2021-01-23T13:59:38 Z |
hamerin |
Wombats (IOI13_wombats) |
C++17 |
|
11630 ms |
197764 KB |
#include "wombats.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;
#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed
const int L = 15;
const int pinf = numeric_limits<int>::max() / 2;
const int ninf = numeric_limits<int>::min() / 2;
int R, C;
vector<vector<int>> H, V;
namespace DPHelper {
vector<vector<int>> base_get(int r) {
vector<vector<int>> ret(C, vector<int>(C, pinf));
for (int k = 0; k < C; k++) {
for (int i = 0; i < C - k; i++) {
if (k == 0)
ret[i][i] = 0;
else
ret[i][i + k] = ret[i + k][i] = ret[i + 1][i + k] + H[r][i];
}
}
if (r != R - 1) {
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
ret[i][j] += V[r][j];
}
return ret;
}
vector<vector<int>> mer(const vector<vector<int>>& lhs, const vector<vector<int>>& rhs) {
vector<vector<int>> ret(C, vector<int>(C, pinf));
vector<vector<int>> opt(C, vector<int>(C));
for (int k = 0; k < C; k++) {
for (int i = 0; i < C - k; i++) {
if (k == 0) {
for (int j = 0; j < C; j++) {
if (ret[i][i] > lhs[i][j] + rhs[j][i]) {
ret[i][i] = lhs[i][j] + rhs[j][i];
opt[i][i] = j;
}
}
} else {
for (int j = opt[i][i + k - 1]; j <= opt[i + 1][i + k]; j++) {
if (ret[i][i + k] > lhs[i][j] + rhs[j][i + k]) {
ret[i][i + k] = lhs[i][j] + rhs[j][i + k];
opt[i][i + k] = j;
}
}
for (int j = opt[i + k - 1][i]; j <= opt[i + k][i + 1]; j++) {
if (ret[i + k][i] > lhs[i + k][j] + rhs[j][i]) {
ret[i + k][i] = lhs[i + k][j] + rhs[j][i];
opt[i + k][i] = j;
}
}
}
}
}
return ret;
}
vector<vector<int>> base_solve(int s, int e) {
auto ret = base_get(s);
for (int r = s + 1; r <= e; r++)
ret = mer(ret, base_get(r));
return ret;
}
}; // namespace DPHelper
class SegTree {
public:
int N{};
vector<vector<vector<int>>> vl;
SegTree() = default;
SegTree(int N) {
this->N = N;
vl.resize(N << 2);
}
void init(int s, int e, int n) {
if (e - s < L) {
vl[n] = DPHelper::base_solve(s, e);
return;
}
int m = (s + e) >> 1, k = n << 1;
init(s, m, k);
init(m + 1, e, k | 1);
vl[n] = DPHelper::mer(vl[k], vl[k | 1]);
}
inline void init() {
init(0, N - 1, 1);
}
void update(int s, int e, int n, int p) {
if (e < p || p < s) return;
if (e - s < L) {
vl[n] = DPHelper::base_solve(s, e);
return;
}
int m = (s + e) >> 1, k = n << 1;
update(s, m, k, p);
update(m + 1, e, k | 1, p);
vl[n] = DPHelper::mer(vl[k], vl[k | 1]);
}
inline void update(int p) {
update(0, N - 1, 1, p);
}
int query(int V1, int V2) {
return vl[1][V1][V2];
}
};
SegTree ST;
void init(int r, int c, int h[5000][200], int v[5000][200]) {
R = r, C = c;
H.resize(R);
V.resize(R - 1);
for (int i = 0; i < R; i++) copy(h[i], h[i] + C - 1, back_inserter(H[i]));
for (int i = 0; i < R - 1; i++) copy(v[i], v[i] + C, back_inserter(V[i]));
ST = SegTree(R);
ST.init();
}
void changeH(int P, int Q, int W) {
H[P][Q] = W;
ST.update(P);
}
void changeV(int P, int Q, int W) {
V[P][Q] = W;
ST.update(P);
}
int escape(int V1, int V2) {
return ST.query(V1, V2);
}
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5152 KB |
Output is correct |
2 |
Correct |
10 ms |
5100 KB |
Output is correct |
3 |
Correct |
84 ms |
6788 KB |
Output is correct |
4 |
Correct |
7 ms |
5100 KB |
Output is correct |
5 |
Correct |
8 ms |
5100 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
79 ms |
1388 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
1616 KB |
Output is correct |
2 |
Correct |
270 ms |
1516 KB |
Output is correct |
3 |
Correct |
353 ms |
1388 KB |
Output is correct |
4 |
Correct |
356 ms |
1516 KB |
Output is correct |
5 |
Correct |
372 ms |
1388 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1287 ms |
1468 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
9324 KB |
Output is correct |
2 |
Correct |
13 ms |
9324 KB |
Output is correct |
3 |
Correct |
14 ms |
9324 KB |
Output is correct |
4 |
Correct |
53 ms |
10092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
332 ms |
1388 KB |
Output is correct |
2 |
Correct |
271 ms |
1516 KB |
Output is correct |
3 |
Correct |
363 ms |
1388 KB |
Output is correct |
4 |
Correct |
353 ms |
1388 KB |
Output is correct |
5 |
Correct |
344 ms |
1516 KB |
Output is correct |
6 |
Correct |
13 ms |
9324 KB |
Output is correct |
7 |
Correct |
13 ms |
9324 KB |
Output is correct |
8 |
Correct |
13 ms |
9324 KB |
Output is correct |
9 |
Correct |
53 ms |
10092 KB |
Output is correct |
10 |
Correct |
9 ms |
5100 KB |
Output is correct |
11 |
Correct |
7 ms |
5108 KB |
Output is correct |
12 |
Correct |
87 ms |
6764 KB |
Output is correct |
13 |
Correct |
7 ms |
5100 KB |
Output is correct |
14 |
Correct |
7 ms |
5100 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
85 ms |
1388 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1285 ms |
1492 KB |
Output is correct |
28 |
Correct |
2499 ms |
59004 KB |
Output is correct |
29 |
Correct |
2665 ms |
56256 KB |
Output is correct |
30 |
Correct |
2626 ms |
56512 KB |
Output is correct |
31 |
Correct |
2544 ms |
60448 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
1644 KB |
Output is correct |
2 |
Correct |
262 ms |
1516 KB |
Output is correct |
3 |
Correct |
354 ms |
1644 KB |
Output is correct |
4 |
Correct |
353 ms |
1536 KB |
Output is correct |
5 |
Correct |
343 ms |
1516 KB |
Output is correct |
6 |
Correct |
14 ms |
9324 KB |
Output is correct |
7 |
Correct |
12 ms |
9324 KB |
Output is correct |
8 |
Correct |
13 ms |
9324 KB |
Output is correct |
9 |
Correct |
53 ms |
10092 KB |
Output is correct |
10 |
Correct |
7 ms |
5100 KB |
Output is correct |
11 |
Correct |
7 ms |
5100 KB |
Output is correct |
12 |
Correct |
85 ms |
6796 KB |
Output is correct |
13 |
Correct |
7 ms |
5100 KB |
Output is correct |
14 |
Correct |
7 ms |
5100 KB |
Output is correct |
15 |
Correct |
3899 ms |
188064 KB |
Output is correct |
16 |
Correct |
11630 ms |
191492 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
87 ms |
2796 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1255 ms |
1644 KB |
Output is correct |
30 |
Correct |
2495 ms |
62624 KB |
Output is correct |
31 |
Correct |
9765 ms |
196764 KB |
Output is correct |
32 |
Correct |
9889 ms |
196768 KB |
Output is correct |
33 |
Correct |
2733 ms |
59784 KB |
Output is correct |
34 |
Correct |
10139 ms |
192780 KB |
Output is correct |
35 |
Correct |
2702 ms |
59924 KB |
Output is correct |
36 |
Correct |
10173 ms |
192928 KB |
Output is correct |
37 |
Correct |
2634 ms |
64424 KB |
Output is correct |
38 |
Correct |
10188 ms |
197764 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
10649 ms |
193120 KB |
Output is correct |