結果

問題 No.402 最も海から遠い場所
ユーザー FF256grhyFF256grhy
提出日時 2016-07-22 23:43:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 24,704 KB
実行使用メモリ 45,568 KB
最終ジャッジ日時 2024-04-24 06:18:38
合計ジャッジ時間 2,692 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 0 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 10 ms
5,376 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 163 ms
15,616 KB
testcase_18 WA -
testcase_19 AC 276 ms
10,368 KB
testcase_20 WA -
testcase_21 AC 244 ms
27,904 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         scanf("%d%d", &h, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:11:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |                 scanf("%s", f[i] + 1);
      |                 ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

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

int queue[9000000], get, set;

int main() {
	scanf("%d%d", &h, &w);
	for(int i = 1; i <= h; i++) {
		scanf("%s", f[i] + 1);
		f[i][0    ] = '.';
		f[i][w + 1] = '.';
	}
	
	for(int j = 0; j <= w + 1; j++) {
		f[0    ][j] = '.';
		f[h + 1][j] = '.';
	}
	
	for(int i = 0; i <= h + 1; i++) {
	for(int j = 0; j <= w + 1; j++) {
		if(f[i][j] == '.') {
			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] == '#') {
					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] == '#') {
				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