結果

問題 No.402 最も海から遠い場所
ユーザー masamasa
提出日時 2016-07-22 23:55:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,565 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 89,144 KB
実行使用メモリ 158,784 KB
最終ジャッジ日時 2024-04-24 06:22:40
合計ジャッジ時間 5,341 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 733 ms
55,936 KB
testcase_19 AC 673 ms
158,784 KB
testcase_20 AC 508 ms
50,304 KB
testcase_21 AC 688 ms
105,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

typedef tuple<int, int, int> TUP;

const vector<int> dx = {1, 1,  0, -1, -1, -1,  0,  1};
const vector<int> dy = {0, 1,  1,  1,  0, -1, -1, -1};
const int INF = 1e9;

void show(vector<vector<int>> &v) {
cout <<"---------" << endl;
	for (auto vv : v) {
		for (auto vvv : vv) {
			if (vvv == INF) {
				printf("INF ");
			} else {
				printf("%3d ", vvv);
			}
		}
		printf("\n");
	}
}

int main() {
	int h, w;

	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	vector<vector<int>> t(h, vector<int>(w,INF));
	queue<TUP> que;

	for (int i = 0; i < h; i++) {
		que.push(make_tuple(i, -1, 0));
		que.push(make_tuple(i,  w, 0));
	}
	for (int i = 0; i < w; i++) {
		que.push(make_tuple(-1, i, 0));
		que.push(make_tuple( h, i, 0));
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.') {
				que.push(make_tuple(i, j, 0));
				t[i][j] = 0;
			}
		}
	}

	int ans = -1;
	while (!que.empty()) {
		auto tup = que.front();
		que.pop();
		int x = get<0>(tup);
		int y = get<1>(tup);
		int v = get<2>(tup);

		for (int i = 0; i < 8; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
				continue;
			}
			if (v + 1 < t[ny][nx]) {
				t[ny][nx] = v + 1;
				que.push(make_tuple(nx, ny, v + 1));
				ans = max(ans, v + 1);
			}
		}
	}
	// show(t);
	cout << ans << endl;
	return 0;
}
0