結果

問題 No.402 最も海から遠い場所
ユーザー FF256grhyFF256grhy
提出日時 2016-07-23 00:04:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 392 ms / 3,000 ms
コード長 1,103 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 27,404 KB
実行使用メモリ 73,292 KB
最終ジャッジ日時 2023-08-06 10:39:23
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,000 KB
testcase_01 AC 2 ms
5,004 KB
testcase_02 AC 2 ms
5,076 KB
testcase_03 AC 2 ms
5,072 KB
testcase_04 AC 2 ms
5,032 KB
testcase_05 AC 2 ms
5,012 KB
testcase_06 AC 2 ms
5,008 KB
testcase_07 AC 2 ms
5,000 KB
testcase_08 AC 2 ms
5,048 KB
testcase_09 AC 2 ms
4,992 KB
testcase_10 AC 2 ms
5,004 KB
testcase_11 AC 2 ms
5,064 KB
testcase_12 AC 3 ms
4,996 KB
testcase_13 AC 4 ms
7,200 KB
testcase_14 AC 3 ms
7,104 KB
testcase_15 AC 12 ms
11,532 KB
testcase_16 AC 15 ms
12,340 KB
testcase_17 AC 156 ms
35,716 KB
testcase_18 AC 392 ms
73,292 KB
testcase_19 AC 228 ms
38,548 KB
testcase_20 AC 310 ms
73,232 KB
testcase_21 AC 224 ms
56,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int h, w;
int f[3002][3002];

int queue[9000000], get, set;

int main() {
	scanf("%d%d", &h, &w);
	for(int i = 1; i <= h; i++) {
		char s[3002];
		scanf("%s", s + 1);
		for(int j = 1; j <= w; j++) {
			f[i][j] = (s[j] == '.' ? 0 : -1);
		}
	}
	
	for(int i = 0; i <= h + 1; i++) {
	for(int j = 0; j <= w + 1; j++) {
		if(f[i][j] == 0) {
			for(int k = -1; k <= 1; k++) {
			for(int l = -1; l <= 1; l++) {
				if(k == 0 && l == 0) { continue; }
				if( ! (1 <= i + k && i + k <= h && 1 <= j + l && j + l <= w) ) { continue; }
				
				if(f[i + k][j + l] == -1) {
					f[i + k][j + l] = 1;
					queue[set++] = (i + k) * 4000 + (j + l);
				}
			}
			}
		}
	}
	}
	
	int max = 1;
	while(get != set) {
		int q = queue[get++];
		int i = q / 4000;
		int j = q % 4000;
		for(int k = -1; k <= 1; k++) {
		for(int l = -1; l <= 1; l++) {
			if(k == 0 && l == 0) { continue; }
			
			if(f[i + k][j + l] == -1) {
				f[i + k][j + l] = f[i][j] + 1;
				if(max < f[i][j] + 1) { max = f[i][j] + 1; }
				queue[set++] = (i + k) * 4000 + (j + l);
			}
		}
		}
	}
	
	printf("%d\n", max);
	
	return 0;
}
0