結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
40,236 KB
testcase_01 AC 14 ms
40,428 KB
testcase_02 AC 14 ms
40,284 KB
testcase_03 AC 14 ms
40,284 KB
testcase_04 AC 14 ms
40,180 KB
testcase_05 AC 14 ms
40,212 KB
testcase_06 AC 15 ms
40,216 KB
testcase_07 AC 14 ms
40,164 KB
testcase_08 AC 14 ms
40,320 KB
testcase_09 AC 14 ms
40,412 KB
testcase_10 AC 14 ms
40,316 KB
testcase_11 AC 14 ms
40,236 KB
testcase_12 AC 14 ms
40,256 KB
testcase_13 AC 17 ms
40,552 KB
testcase_14 AC 15 ms
40,288 KB
testcase_15 AC 30 ms
41,272 KB
testcase_16 AC 34 ms
43,476 KB
testcase_17 AC 295 ms
62,204 KB
testcase_18 AC 689 ms
51,556 KB
testcase_19 AC 497 ms
120,980 KB
testcase_20 AC 447 ms
47,792 KB
testcase_21 AC 453 ms
84,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;

const int INF = 1000000;
char b[3010][3010];
int d[3010][3010];
int dx[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dy[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };

struct P {
	int x, y;
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int H, W;
	cin >> H >> W;

	fill((int*)begin(d), (int*)end(d), INF);

	queue<P> q;
	for(int i = 0; i < H + 2; i++) {
		for(int j = 0; j < W + 2; j++) {
			if(i != 0 && i != H + 1 && j != 0 && j != W + 1) {
				cin >> b[i][j];
			}
			else {
				b[i][j] = '.';
			}
			if(b[i][j] == '.') {
				d[i][j] = 0;
				q.push(P{ j, i });
			}
		}
	}

	int ans = 0;
	while(!q.empty()) {
		P p = q.front();
		q.pop();

		for(int i = 0; i < 8; i++) {
			int ny = p.y + dy[i], nx = p.x + dx[i];
			if(1 <= nx && nx <= W && 1 <= ny && ny <= H && d[p.y][p.x] + 1 < d[ny][nx]) {
				d[ny][nx] = d[p.y][p.x] + 1;
				q.push(P{ nx, ny });
				ans = max(ans, d[ny][nx]);
			}
		}
	}

	cout << ans << endl;
}
0