結果

問題 No.402 最も海から遠い場所
ユーザー femtofemto
提出日時 2016-07-22 23:04:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,071 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 73,448 KB
実行使用メモリ 121,612 KB
最終ジャッジ日時 2024-04-24 05:55:55
合計ジャッジ時間 4,977 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
39,384 KB
testcase_01 AC 13 ms
39,236 KB
testcase_02 AC 14 ms
39,580 KB
testcase_03 WA -
testcase_04 AC 13 ms
39,184 KB
testcase_05 AC 14 ms
40,280 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 13 ms
39,636 KB
testcase_09 AC 13 ms
39,036 KB
testcase_10 AC 13 ms
39,588 KB
testcase_11 AC 13 ms
39,964 KB
testcase_12 WA -
testcase_13 AC 17 ms
39,196 KB
testcase_14 AC 15 ms
39,456 KB
testcase_15 AC 28 ms
41,436 KB
testcase_16 AC 34 ms
41,500 KB
testcase_17 AC 281 ms
62,064 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int INF = 1000000;
char b[3000][3000];
int d[3000][3000];
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(0 <= nx && nx < W && 0 <= 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