結果

問題 No.402 最も海から遠い場所
ユーザー 夜
提出日時 2020-11-17 18:41:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 726 ms / 3,000 ms
コード長 1,500 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 102,592 KB
実行使用メモリ 165,284 KB
最終ジャッジ日時 2023-09-30 14:21:36
合計ジャッジ時間 5,306 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,824 KB
testcase_14 AC 4 ms
6,336 KB
testcase_15 AC 18 ms
10,444 KB
testcase_16 AC 24 ms
13,440 KB
testcase_17 AC 278 ms
60,784 KB
testcase_18 AC 726 ms
62,576 KB
testcase_19 AC 496 ms
165,284 KB
testcase_20 AC 452 ms
56,864 KB
testcase_21 AC 454 ms
111,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int ans[3030][3030];
string s[3030];
int x2[8] = { 0,0,1,-1,1,1,-1,-1 };
int y2[8] = { 1,-1,0,0,1,-1,1,-1 };
int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		cin >> s[i];
		s[i] = '.' + s[i] + '.';
	}
	s[0] = "";
	s[h + 1] = "";
	for (int i = 0; i < w + 2; i++) {
		s[0] += '.';
		s[h + 1] += '.';
	}
	queue<tuple<int, int, int>> que;
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			if (s[i][j] == '.') {
				que.push(make_tuple(0, i, j));
				ans[i][j] = 0;
			}
			else {
				ans[i][j] = -1;
			}
		}
	}
	while (!que.empty()) {
		tuple<int, int, int> t = que.front();
		que.pop();
		int x = get<1>(t);
		int y = get<2>(t);
		int z = get<0>(t);
		for (int i = 0; i < 8; i++) {
			if (x + x2[i] < 0 || x + x2[i] >= h + 2 || y + y2[i] < 0 || y + y2[i] >= w + 2) {
				continue;
			}
			if (ans[x + x2[i]][y + y2[i]] == -1) {
				ans[x + x2[i]][y + y2[i]] = z + 1;
				que.push(make_tuple(z + 1, x + x2[i], y + y2[i]));
			}
		}
	}
	int ans1 = -1;
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			if (ans1 < ans[i][j]) {
				ans1 = ans[i][j];
			}
		}
	}
	cout << ans1 << endl;
}
0