#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cout << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 5e3 + 10;
const int maxm = 200 + 10;
const int sq = 100;
const int inf = 1e9;
int n, m, h[maxn][maxm], v[maxn][maxm], dp[maxn][maxm], val[50][maxm][maxm], seg[210][maxm][maxm], ptrdp[maxm][maxm];
void change(int v, int l, int r, int idx){
if (l + 1 == r){
//debug(v, l, r);
for (int i = 0; i < m; i++){
for (int j = 0; j < m; j++){
seg[v][i][j] = val[l][i][j];
// debug(i, j, seg[v][i][j]);
}
}
return;
}
int mid = (l + r) >> 1;
if (idx < mid){
change(v << 1, l, mid, idx);
}
else{
change(v << 1 | 1, mid, r, idx);
}
//debug(v, l, r);
int ptr = mid * sq - 1;
for (int shib = m-1; shib >= 1-m; shib--){
for (int i = 0; i < m; i++){
int j = i - shib;
if (j < 0 || j >= m) continue;
int l = (j? ptrdp[i][j-1]: 0);
int r = (i+1 < m? ptrdp[i+1][j]: m-1);
//debug(i, j, l, r);
ptrdp[i][j] = l;
seg[v][i][j] = seg[v << 1][i][l] + seg[v << 1 | 1][l][j] + ::v[ptr][l];
for (int k = l+1; k <= r; k++){
int tmp = seg[v << 1][i][k] + seg[v << 1 | 1][k][j] + ::v[ptr][k];
if (tmp < seg[v][i][j]){
seg[v][i][j] = tmp;
ptrdp[i][j] = k;
}
}
//debug(seg[v][i][j], ptrdp[i][j]);
}
}
}
inline void update(int r){
for (int i = 1; i < m; i++){
dp[r][i] = min(dp[r][i], dp[r][i-1] + h[r][i-1]);
}
for (int i = m-2; ~i; i--){
dp[r][i] = min(dp[r][i], dp[r][i+1] + h[r][i]);
}
}
inline void build(int blc){
for (int i = 0; i < m; i++){
for (int j = 0; j < m; j++){
if (i == j) dp[blc*sq][j] = 0;
else dp[blc*sq][j] = inf;
}
update(blc*sq);
int idx = min((blc+1)*sq, n) - 1;
for (int j = blc*sq+1; j <= idx; j++){
for (int k = 0; k < m; k++){
dp[j][k] = dp[j-1][k] + v[j-1][k];
}
update(j);
}
for (int j = 0; j < m; j++){
val[blc][i][j] = dp[idx][j];
}
}
change(1, 0, (n-1)/sq+1, blc);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R, m = C;
for (int i = 0; i < n; i++){
for (int j = 0; j < m-1; j++){
h[i][j] = H[i][j];
}
}
for (int i = 0; i < n-1; i++){
for (int j = 0; j < m; j++){
v[i][j] = V[i][j];
}
}
for (int i = 0; i <= (n-1)/sq; i++){
build(i);
}
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
build(P/sq);
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
build(P/sq);
}
int escape(int V1, int V2) {
return seg[1][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 |
6 ms |
13012 KB |
Output is correct |
2 |
Correct |
6 ms |
13116 KB |
Output is correct |
3 |
Correct |
57 ms |
14704 KB |
Output is correct |
4 |
Correct |
6 ms |
13116 KB |
Output is correct |
5 |
Correct |
8 ms |
13012 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
53 ms |
1384 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
754 ms |
900 KB |
Output is correct |
2 |
Correct |
728 ms |
908 KB |
Output is correct |
3 |
Correct |
747 ms |
908 KB |
Output is correct |
4 |
Correct |
748 ms |
900 KB |
Output is correct |
5 |
Correct |
734 ms |
896 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
3711 ms |
920 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
21204 KB |
Output is correct |
2 |
Correct |
11 ms |
21204 KB |
Output is correct |
3 |
Correct |
10 ms |
21332 KB |
Output is correct |
4 |
Correct |
37 ms |
22592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
745 ms |
920 KB |
Output is correct |
2 |
Correct |
727 ms |
896 KB |
Output is correct |
3 |
Correct |
751 ms |
908 KB |
Output is correct |
4 |
Correct |
753 ms |
924 KB |
Output is correct |
5 |
Correct |
735 ms |
896 KB |
Output is correct |
6 |
Correct |
12 ms |
21204 KB |
Output is correct |
7 |
Correct |
12 ms |
21200 KB |
Output is correct |
8 |
Correct |
11 ms |
21312 KB |
Output is correct |
9 |
Correct |
37 ms |
22712 KB |
Output is correct |
10 |
Correct |
6 ms |
13140 KB |
Output is correct |
11 |
Correct |
6 ms |
13140 KB |
Output is correct |
12 |
Correct |
56 ms |
15816 KB |
Output is correct |
13 |
Correct |
6 ms |
13140 KB |
Output is correct |
14 |
Correct |
6 ms |
13116 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
55 ms |
2780 KB |
Output is correct |
26 |
Correct |
1 ms |
440 KB |
Output is correct |
27 |
Correct |
3699 ms |
984 KB |
Output is correct |
28 |
Correct |
4359 ms |
37580 KB |
Output is correct |
29 |
Correct |
4293 ms |
31308 KB |
Output is correct |
30 |
Correct |
4279 ms |
31288 KB |
Output is correct |
31 |
Correct |
4439 ms |
39204 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
739 ms |
892 KB |
Output is correct |
2 |
Correct |
724 ms |
916 KB |
Output is correct |
3 |
Correct |
746 ms |
912 KB |
Output is correct |
4 |
Correct |
762 ms |
904 KB |
Output is correct |
5 |
Correct |
731 ms |
896 KB |
Output is correct |
6 |
Correct |
11 ms |
21204 KB |
Output is correct |
7 |
Correct |
10 ms |
21316 KB |
Output is correct |
8 |
Correct |
11 ms |
21332 KB |
Output is correct |
9 |
Correct |
39 ms |
22572 KB |
Output is correct |
10 |
Correct |
6 ms |
13056 KB |
Output is correct |
11 |
Correct |
6 ms |
13140 KB |
Output is correct |
12 |
Correct |
57 ms |
15884 KB |
Output is correct |
13 |
Correct |
6 ms |
13044 KB |
Output is correct |
14 |
Correct |
6 ms |
13040 KB |
Output is correct |
15 |
Correct |
1812 ms |
55416 KB |
Output is correct |
16 |
Correct |
17145 ms |
56612 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
440 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
54 ms |
2792 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
3698 ms |
992 KB |
Output is correct |
30 |
Correct |
4324 ms |
37492 KB |
Output is correct |
31 |
Correct |
16953 ms |
54092 KB |
Output is correct |
32 |
Correct |
17029 ms |
54120 KB |
Output is correct |
33 |
Correct |
4289 ms |
31320 KB |
Output is correct |
34 |
Correct |
16758 ms |
45356 KB |
Output is correct |
35 |
Correct |
4251 ms |
31276 KB |
Output is correct |
36 |
Correct |
16682 ms |
45244 KB |
Output is correct |
37 |
Correct |
4363 ms |
39156 KB |
Output is correct |
38 |
Correct |
17069 ms |
54808 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
17006 ms |
45460 KB |
Output is correct |