#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
const int maxr = 5010, maxc = 210;
const int maxblock = sqrt(maxr) + 10;
void precalculate();
int h[maxr][maxc], v[maxr][maxc], dp[maxblock][maxc][maxc];
int r, c, block_size;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
/* ... */
block_size = 1000;
r = R;
c = C;
for (int i = 0; i < R - 1; i ++)
for (int j = 0; j < C; j ++)
v[i][j] = V[i][j];
for (int i = 0; i < R; i ++)
for (int j = 0; j < C - 1; j ++)
h[i][j] = H[i][j];
precalculate();
}
const int inf = 2e9 + 10;
int fp[2][maxc];
void fix_row(int i)
{
for (int j = 1; j < c; j ++)
{
fp[i & 1][j] = min(fp[i & 1][j], fp[i & 1][j - 1] + h[i][j - 1]);
}
for (int j = c - 2; j >= 0; j --)
{
fp[i & 1][j] = min(fp[i & 1][j], fp[i & 1][j + 1] + h[i][j]);
}
}
void calc_block(int bl)
{
int st = bl * block_size;
int en = (bl + 1) * block_size - 1;
en = min(en, r - 1);
for (int d = 0; d < c; d ++)
{
for (int j = 0; j < c; j ++)
{
fp[0][j] = fp[1][j] = inf;
}
fp[st & 1][d] = 0;
fix_row(st);
for (int i = st + 1; i <= en; i ++)
{
for (int j = 0; j < c; j ++)
{
fp[i & 1][j] = fp[(i - 1) & 1][j] + v[i - 1][j];
}
fix_row(i);
}
for (int j = 0; j < c; j ++)
{
dp[bl][d][j] = fp[en & 1][j];
}
}
}
void precalculate()
{
for (int bl = 0; bl <= (r - 1) / block_size; bl ++)
{
/// cout << "calc block " << endl;
calc_block(bl);
}
///exit(0);
}
void changeH(int P, int Q, int W) {
/* ... */
h[P][Q] = W;
calc_block(P / block_size);
}
void changeV(int P, int Q, int W) {
/* ... */
v[P][Q] = W;
calc_block(P / block_size);
}
int arr[maxc], temp[maxc];
int escape(int V1, int V2)
{
int v1 = V1, v2 = V2;
for (int j = 0; j < c; j ++)
arr[j] = dp[0][v1][j];
for (int bl = 1; bl <= (r - 1) / block_size; bl ++)
{
int t = bl * block_size;
for (int j = 0; j < c; j ++)
{
arr[j] = arr[j] + v[t - 1][j];
}
for (int j = 1; j < c; j ++)
{
arr[j] = min(arr[j], arr[j - 1] + h[t][j - 1]);
}
for (int j = c - 2; j >= 0; j --)
{
arr[j] = min(arr[j], arr[j + 1] + h[t][j]);
}
for (int j = 0; j < c; j ++)
temp[j] = inf;
for (int j = 0; j < c; j ++)
{
for (int d = 0; d < c; d ++)
temp[j] =min(temp[j], arr[d] + dp[bl][d][j]);
}
for (int j = 0; j < c; j ++)
arr[j] = temp[j];
}
return arr[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;
| ^~~
wombats.cpp: In function 'void init(int, int, int (*)[200], int (*)[200])':
wombats.cpp:22:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
22 | for (int i = 0; i < R; i ++)
| ^~~
wombats.cpp:26:6: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
26 | precalculate();
| ^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
5 ms |
14940 KB |
Output is correct |
3 |
Correct |
67 ms |
16492 KB |
Output is correct |
4 |
Correct |
4 ms |
14940 KB |
Output is correct |
5 |
Correct |
5 ms |
14940 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
62 ms |
9604 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
722 ms |
8704 KB |
Output is correct |
2 |
Correct |
714 ms |
8540 KB |
Output is correct |
3 |
Correct |
730 ms |
8720 KB |
Output is correct |
4 |
Correct |
724 ms |
8700 KB |
Output is correct |
5 |
Correct |
718 ms |
8708 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
3607 ms |
8724 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
19804 KB |
Output is correct |
2 |
Correct |
15 ms |
19804 KB |
Output is correct |
3 |
Correct |
17 ms |
19804 KB |
Output is correct |
4 |
Correct |
52 ms |
20816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
730 ms |
8708 KB |
Output is correct |
2 |
Correct |
705 ms |
8700 KB |
Output is correct |
3 |
Correct |
736 ms |
8708 KB |
Output is correct |
4 |
Correct |
730 ms |
8704 KB |
Output is correct |
5 |
Correct |
712 ms |
8540 KB |
Output is correct |
6 |
Correct |
15 ms |
19804 KB |
Output is correct |
7 |
Correct |
14 ms |
20048 KB |
Output is correct |
8 |
Correct |
14 ms |
20048 KB |
Output is correct |
9 |
Correct |
53 ms |
20816 KB |
Output is correct |
10 |
Correct |
5 ms |
14940 KB |
Output is correct |
11 |
Correct |
4 ms |
14952 KB |
Output is correct |
12 |
Correct |
69 ms |
16468 KB |
Output is correct |
13 |
Correct |
4 ms |
14936 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
58 ms |
9868 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
3611 ms |
8720 KB |
Output is correct |
28 |
Execution timed out |
20038 ms |
20324 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
720 ms |
8700 KB |
Output is correct |
2 |
Correct |
702 ms |
8924 KB |
Output is correct |
3 |
Correct |
726 ms |
8708 KB |
Output is correct |
4 |
Correct |
727 ms |
8796 KB |
Output is correct |
5 |
Correct |
713 ms |
8724 KB |
Output is correct |
6 |
Correct |
14 ms |
19800 KB |
Output is correct |
7 |
Correct |
14 ms |
19804 KB |
Output is correct |
8 |
Correct |
15 ms |
19804 KB |
Output is correct |
9 |
Correct |
48 ms |
20820 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
6 ms |
14940 KB |
Output is correct |
12 |
Correct |
68 ms |
16376 KB |
Output is correct |
13 |
Correct |
4 ms |
14936 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
2719 ms |
20064 KB |
Output is correct |
16 |
Execution timed out |
20030 ms |
20428 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |