結果

問題 No.402 最も海から遠い場所
ユーザー bal4ubal4u
提出日時 2019-07-19 11:35:36
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,564 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 30,328 KB
実行使用メモリ 117,468 KB
最終ジャッジ日時 2023-08-26 21:15:15
合計ジャッジ時間 3,216 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 3 ms
6,196 KB
testcase_14 AC 2 ms
6,064 KB
testcase_15 AC 11 ms
11,744 KB
testcase_16 AC 14 ms
14,004 KB
testcase_17 AC 156 ms
61,096 KB
testcase_18 AC 334 ms
109,248 KB
testcase_19 AC 209 ms
109,228 KB
testcase_20 AC 260 ms
117,468 KB
testcase_21 AC 205 ms
109,280 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.402 最も海から遠い場所
// 2019.7.19 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
}

#define INF 0x33333333
#define QMAX 20000000
int H, W;
int a[3005][3005];
int q[QMAX+5][2], top, end;
int mv[8][2] = {{-1,-1},{-1,0},{-1,1},{0,1},{0,-1},{1,-1},{1,0},{1,1}};
char map[3005];

void bfs() {
	int i, r, c, v;
	
	while (top != end) {
		int e = end;
		while (top != e) {
			r = q[top][0], c = q[top++][1], v = a[r][c]+1;
//			printf("(%d,%d) v=%d, e=%d, end=%d\n", r, c, v, e, end);
			for (i = 0; i < 8; i++) {
				int rr = r + mv[i][0], cc = c + mv[i][1];
				if (a[rr][cc] > v) {
					a[rr][cc] = v, q[end][0] = rr, q[end++][1] = cc;
				}
			}
		}
	}
}
	
int main()
{
	int r, c, ans;

	H = in()+1, W = in()+1;
	for (c = 2; c <= W; c++) {
		q[end][0] =   1, q[end++][1] = c;
		q[end][0] = H+1, q[end++][1] = c;
	}
	for (r = 2; r <= H; r++) {
		memset(&a[r][2], INF, sizeof(int)*W);
		q[end][0] = r, q[end++][1] = 1;
		q[end][0] = r, q[end++][1] = W+1;
		ins(map+2);
		for (c = 2; c <= W; c++) if (map[c] == '.') {
			a[r][c] = 0, q[end][0] = r, q[end++][1] = c;
		}
	}
	bfs();
	ans = 0; for (r = 2; r <= H; r++) for (c = 2; c <= W; c++) {
		if (a[r][c] > ans) ans = a[r][c];
	}
	printf("%d\n", ans);
	return 0;
}
0