Submission #67690083
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#define INF 0x7f7f7f7f
const int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int cnt[3123][3123];
int cost[3123][3123];
struct rc_s {
int r, c;
} q[3123 * 3123];
int main(void) {
int H, W, K;
int i, j;
int qs = 0, qe = 0;
uint64_t ans = 0;
memset(cost, 0x7f, sizeof(cost));
if (scanf("%d%d%d", &H, &W, &K) != 3) return 1;
for (i = 0; i < K; i++) {
int R, C;
if (scanf("%d%d", &R, &C) != 2) return 1;
cnt[R][C] = 4;
cost[R][C] = 0;
q[qe++] = (struct rc_s){ R, C };
}
while (qs < qe) {
struct rc_s cur = q[qs++];
for (i = 0; i < 4; i++) {
int nr = cur.r + d[i][0], nc = cur.c + d[i][1];
/* 1 <= R_i, 1 <= C_i なので、範囲外チェック不要 (外周が番兵になる) */
/* 外周は盤内と高々1個しか隣接しないので、こちらも考慮不要 */
if (++cnt[nr][nc] == 2) {
int best = INF, best2 = INF;
for (j = 0; j < 4; j++) {
int r2 = nr + d[j][0], c2 = nc + d[j][1];
int hoge = cost[r2][c2];
if (hoge < best) {
best2 = best;
best = hoge;
} else if (hoge < best2) {
best2 = hoge;
}
}
cost[nr][nc] = best2 + 1;
q[qe++] = (struct rc_s){ nr, nc };
}
}
}
for (i = 1; i <= H; i++) {
for (j = 1; j <= W; j++) {
if (cost[i][j] < INF) ans += cost[i][j];
}
}
printf("%" PRIu64 "\n", ans);
return 0;
}
/*
要は、移動を1方向ブロックできる
ゴールに行けるところの周囲をチェックする
周囲2箇所からゴールに行ける → そこもゴールに行ける
そのときのコストは、周囲のコストの小さくない方 + 1
2箇所できたとき、それ以降にもっと有利な(低コストで行ける)条件は出てこない
ベストのところをブロックするしかない
→まずゴールをキューに入れ、順に処理すればおk
*/
Submission Info
Submission Time |
|
Task |
F - No Passage |
User |
mikecat |
Language |
C (gcc 12.2.0) |
Score |
525 |
Code Size |
1974 Byte |
Status |
AC |
Exec Time |
267 ms |
Memory |
146656 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
525 / 525 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_00.txt |
AC |
16 ms |
39808 KiB |
00_sample_01.txt |
AC |
16 ms |
39828 KiB |
00_sample_02.txt |
AC |
16 ms |
39828 KiB |
01_test_00.txt |
AC |
16 ms |
39748 KiB |
01_test_01.txt |
AC |
16 ms |
39792 KiB |
01_test_02.txt |
AC |
16 ms |
40000 KiB |
01_test_03.txt |
AC |
16 ms |
39980 KiB |
01_test_04.txt |
AC |
16 ms |
39924 KiB |
01_test_05.txt |
AC |
15 ms |
39700 KiB |
01_test_06.txt |
AC |
15 ms |
39952 KiB |
01_test_07.txt |
AC |
15 ms |
40024 KiB |
01_test_08.txt |
AC |
15 ms |
39912 KiB |
01_test_09.txt |
AC |
15 ms |
40112 KiB |
01_test_10.txt |
AC |
16 ms |
40880 KiB |
01_test_11.txt |
AC |
16 ms |
40520 KiB |
01_test_12.txt |
AC |
16 ms |
39956 KiB |
01_test_13.txt |
AC |
16 ms |
40560 KiB |
01_test_14.txt |
AC |
17 ms |
40956 KiB |
01_test_15.txt |
AC |
16 ms |
40396 KiB |
01_test_16.txt |
AC |
17 ms |
40248 KiB |
01_test_17.txt |
AC |
19 ms |
43600 KiB |
01_test_18.txt |
AC |
19 ms |
40808 KiB |
01_test_19.txt |
AC |
18 ms |
40492 KiB |
01_test_20.txt |
AC |
21 ms |
40284 KiB |
01_test_21.txt |
AC |
20 ms |
44504 KiB |
01_test_22.txt |
AC |
34 ms |
50504 KiB |
01_test_23.txt |
AC |
81 ms |
74512 KiB |
01_test_24.txt |
AC |
141 ms |
107728 KiB |
01_test_25.txt |
AC |
218 ms |
141592 KiB |
01_test_26.txt |
AC |
22 ms |
40652 KiB |
01_test_27.txt |
AC |
21 ms |
40360 KiB |
01_test_28.txt |
AC |
21 ms |
40300 KiB |
01_test_29.txt |
AC |
23 ms |
44624 KiB |
01_test_30.txt |
AC |
16 ms |
40296 KiB |
01_test_31.txt |
AC |
35 ms |
51808 KiB |
01_test_32.txt |
AC |
68 ms |
69572 KiB |
01_test_33.txt |
AC |
78 ms |
73416 KiB |
01_test_34.txt |
AC |
267 ms |
146648 KiB |
01_test_35.txt |
AC |
258 ms |
146656 KiB |
01_test_36.txt |
AC |
14 ms |
39812 KiB |
01_test_37.txt |
AC |
14 ms |
39716 KiB |
01_test_38.txt |
AC |
15 ms |
39980 KiB |
01_test_39.txt |
AC |
21 ms |
39724 KiB |
01_test_40.txt |
AC |
14 ms |
39728 KiB |