#include "wombats.h"
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
cerr << to_string(h);
if(sizeof ...(t)) cerr << ", ";
DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif
const int INF = 1e9 + 7, K = 15;
int h[5000][200], v[5000][200], dp[5000][200];
int R, C;
struct node {
int a[200][200];
node() { memset(a, 0x3f, sizeof a); }
void build(int tl, int tr) {
for(int s = 0; s < C; s++) {
for(int j = 0; j < C; j++)
dp[tl][j] = INF;
auto gogo = [&] (int row) {
for(int i = 0; i + 1 < C; i++)
dp[row][i + 1] = min(dp[row][i + 1], dp[row][i] + h[row][i]);
for(int i = C - 2; i >= 0; i--)
dp[row][i] = min(dp[row][i], dp[row][i + 1] + h[row][i]);
};
dp[tl][s] = 0;
gogo(tl);
for(int i = tl + 1; i <= tr; i++) {
for(int j = 0; j < C; j++)
dp[i][j] = dp[i - 1][j] + v[i - 1][j];
gogo(i);
}
for(int t = 0; t < C; t++)
a[s][t] = dp[tr][t];
}
}
void add(node& l, node& r) {
int aux[200][200];
for(int diff = -(C - 1); diff <= (C - 1); diff++) {
for(int s = 0; s < C; s++) {
int t = s + diff;
if(0 <= t && t < C) {
int lb = t - 1 >= 0 ? aux[s][t - 1] : 0;
int rb = s + 1 < C ? aux[s + 1][t] : C - 1;
a[s][t] = INF;
for(int k = lb; k <= rb; k++) {
if(l.a[s][k] + r.a[k][t] < a[s][t]) {
a[s][t] = l.a[s][k] + r.a[k][t];
aux[s][t] = k;
}
}
}
}
}
}
} t[350 * 4];
void upd(int pos, int v = 1, int tl = 0, int tr = R - 1) {
if(tr - tl <= K) {
t[v].build(tl, tr);
return;
}
int tm = (tl + tr) / 2;
if(pos < tm)
upd(pos, v * 2, tl, tm);
else
upd(pos, v * 2 + 1, tm, tr);
t[v].add(t[v * 2], t[v * 2 + 1]);
}
void build(int v = 1, int tl = 0, int tr = R - 1) {
if(tr - tl <= K) {
t[v].build(tl, tr);
return;
}
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm, tr);
t[v].add(t[v * 2], t[v * 2 + 1]);
}
void init(int _R, int _C, int _h[5000][200], int _v[5000][200]) {
memcpy(h, _h, sizeof h);
memcpy(v, _v, sizeof v);
R = _R, C = _C;
build();
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
if(P) upd(P - 1);
upd(P);
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
upd(P);
}
int escape(int V1, int V2) {
return t[1].a[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 |
100 ms |
235236 KB |
Output is correct |
2 |
Correct |
104 ms |
235244 KB |
Output is correct |
3 |
Correct |
164 ms |
236780 KB |
Output is correct |
4 |
Correct |
94 ms |
235212 KB |
Output is correct |
5 |
Correct |
97 ms |
235316 KB |
Output is correct |
6 |
Correct |
92 ms |
227264 KB |
Output is correct |
7 |
Correct |
92 ms |
227276 KB |
Output is correct |
8 |
Correct |
88 ms |
227288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
227284 KB |
Output is correct |
2 |
Correct |
94 ms |
227312 KB |
Output is correct |
3 |
Correct |
95 ms |
227204 KB |
Output is correct |
4 |
Correct |
88 ms |
227460 KB |
Output is correct |
5 |
Correct |
86 ms |
227452 KB |
Output is correct |
6 |
Correct |
93 ms |
227488 KB |
Output is correct |
7 |
Correct |
93 ms |
227408 KB |
Output is correct |
8 |
Correct |
101 ms |
227512 KB |
Output is correct |
9 |
Correct |
86 ms |
227392 KB |
Output is correct |
10 |
Correct |
93 ms |
227468 KB |
Output is correct |
11 |
Correct |
160 ms |
228428 KB |
Output is correct |
12 |
Correct |
99 ms |
227404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
227596 KB |
Output is correct |
2 |
Correct |
216 ms |
227704 KB |
Output is correct |
3 |
Correct |
306 ms |
227708 KB |
Output is correct |
4 |
Correct |
200 ms |
227620 KB |
Output is correct |
5 |
Correct |
269 ms |
227660 KB |
Output is correct |
6 |
Correct |
90 ms |
227236 KB |
Output is correct |
7 |
Correct |
88 ms |
227276 KB |
Output is correct |
8 |
Correct |
96 ms |
227220 KB |
Output is correct |
9 |
Correct |
918 ms |
227712 KB |
Output is correct |
10 |
Correct |
91 ms |
227276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
239068 KB |
Output is correct |
2 |
Correct |
97 ms |
239192 KB |
Output is correct |
3 |
Correct |
103 ms |
239116 KB |
Output is correct |
4 |
Correct |
160 ms |
240008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
227660 KB |
Output is correct |
2 |
Correct |
195 ms |
227716 KB |
Output is correct |
3 |
Correct |
304 ms |
227708 KB |
Output is correct |
4 |
Correct |
214 ms |
227640 KB |
Output is correct |
5 |
Correct |
256 ms |
227708 KB |
Output is correct |
6 |
Correct |
98 ms |
239120 KB |
Output is correct |
7 |
Correct |
105 ms |
239140 KB |
Output is correct |
8 |
Correct |
104 ms |
239248 KB |
Output is correct |
9 |
Correct |
132 ms |
239968 KB |
Output is correct |
10 |
Correct |
106 ms |
235208 KB |
Output is correct |
11 |
Correct |
98 ms |
235168 KB |
Output is correct |
12 |
Correct |
158 ms |
236776 KB |
Output is correct |
13 |
Correct |
112 ms |
235208 KB |
Output is correct |
14 |
Correct |
102 ms |
235212 KB |
Output is correct |
15 |
Correct |
96 ms |
227224 KB |
Output is correct |
16 |
Correct |
86 ms |
227276 KB |
Output is correct |
17 |
Correct |
93 ms |
227288 KB |
Output is correct |
18 |
Correct |
89 ms |
227504 KB |
Output is correct |
19 |
Correct |
94 ms |
227392 KB |
Output is correct |
20 |
Correct |
86 ms |
227456 KB |
Output is correct |
21 |
Correct |
87 ms |
227492 KB |
Output is correct |
22 |
Correct |
89 ms |
227408 KB |
Output is correct |
23 |
Correct |
96 ms |
227424 KB |
Output is correct |
24 |
Correct |
92 ms |
227408 KB |
Output is correct |
25 |
Correct |
181 ms |
228532 KB |
Output is correct |
26 |
Correct |
104 ms |
227456 KB |
Output is correct |
27 |
Correct |
932 ms |
227708 KB |
Output is correct |
28 |
Correct |
1696 ms |
239512 KB |
Output is correct |
29 |
Correct |
1477 ms |
237596 KB |
Output is correct |
30 |
Correct |
1503 ms |
237440 KB |
Output is correct |
31 |
Correct |
1539 ms |
240544 KB |
Output is correct |
32 |
Correct |
96 ms |
227216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
254 ms |
227708 KB |
Output is correct |
2 |
Correct |
202 ms |
227704 KB |
Output is correct |
3 |
Correct |
312 ms |
227704 KB |
Output is correct |
4 |
Correct |
219 ms |
227788 KB |
Output is correct |
5 |
Correct |
283 ms |
227636 KB |
Output is correct |
6 |
Correct |
92 ms |
239264 KB |
Output is correct |
7 |
Correct |
106 ms |
239096 KB |
Output is correct |
8 |
Correct |
120 ms |
239064 KB |
Output is correct |
9 |
Correct |
144 ms |
239924 KB |
Output is correct |
10 |
Correct |
94 ms |
235232 KB |
Output is correct |
11 |
Correct |
96 ms |
235284 KB |
Output is correct |
12 |
Correct |
178 ms |
236912 KB |
Output is correct |
13 |
Correct |
122 ms |
235232 KB |
Output is correct |
14 |
Correct |
117 ms |
235300 KB |
Output is correct |
15 |
Correct |
1898 ms |
239204 KB |
Output is correct |
16 |
Correct |
6804 ms |
242116 KB |
Output is correct |
17 |
Correct |
120 ms |
227316 KB |
Output is correct |
18 |
Correct |
128 ms |
227296 KB |
Output is correct |
19 |
Correct |
117 ms |
227228 KB |
Output is correct |
20 |
Correct |
113 ms |
227416 KB |
Output is correct |
21 |
Correct |
126 ms |
227420 KB |
Output is correct |
22 |
Correct |
110 ms |
227488 KB |
Output is correct |
23 |
Correct |
128 ms |
227420 KB |
Output is correct |
24 |
Correct |
111 ms |
227464 KB |
Output is correct |
25 |
Correct |
109 ms |
227472 KB |
Output is correct |
26 |
Correct |
111 ms |
227432 KB |
Output is correct |
27 |
Correct |
221 ms |
229820 KB |
Output is correct |
28 |
Correct |
110 ms |
227416 KB |
Output is correct |
29 |
Correct |
1075 ms |
227780 KB |
Output is correct |
30 |
Correct |
1860 ms |
243352 KB |
Output is correct |
31 |
Correct |
6644 ms |
247556 KB |
Output is correct |
32 |
Correct |
6197 ms |
247588 KB |
Output is correct |
33 |
Correct |
1491 ms |
240936 KB |
Output is correct |
34 |
Correct |
5461 ms |
244924 KB |
Output is correct |
35 |
Correct |
1557 ms |
240844 KB |
Output is correct |
36 |
Correct |
5443 ms |
244776 KB |
Output is correct |
37 |
Correct |
1569 ms |
245048 KB |
Output is correct |
38 |
Correct |
5665 ms |
248136 KB |
Output is correct |
39 |
Correct |
91 ms |
227236 KB |
Output is correct |
40 |
Correct |
5521 ms |
245056 KB |
Output is correct |