結果

問題 No.402 最も海から遠い場所
ユーザー sugim48sugim48
提出日時 2016-07-22 22:32:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 347 ms / 3,000 ms
コード長 1,575 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 121,376 KB
実行使用メモリ 85,908 KB
最終ジャッジ日時 2023-08-06 09:43:47
合計ジャッジ時間 4,502 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 12 ms
5,576 KB
testcase_16 AC 16 ms
6,524 KB
testcase_17 AC 200 ms
42,880 KB
testcase_18 AC 347 ms
20,336 KB
testcase_19 AC 308 ms
85,868 KB
testcase_20 AC 294 ms
12,608 KB
testcase_21 AC 317 ms
85,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_set>
#include <vector>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int INF = INT_MAX / 2;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

char c[3010];

int main() {
	int H, W; cin >> H >> W;
	vector<string> a(H);
	for (int y = 0; y < H; y++) {
		scanf("%s", c);
		a[y] = c;
	}
	queue<i_i> q;
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++)
			if (a[y][x] == '.')
				q.push(i_i(y, x));
	for (int y = 0; y < H; y++) {
		q.push(i_i(y, -1));
		q.push(i_i(y, W));
	}
	for (int x = 0; x < W; x++) {
		q.push(i_i(-1, x));
		q.push(i_i(H, x));
	}
	int t;
	for (t = 0; !q.empty(); t++) {
		queue<i_i> _q;
		while (!q.empty()) {
			i_i yx = q.front(); q.pop();
			int y = yx.first, x = yx.second;
			for (int dy = -1; dy <= 1; dy++)
				for (int dx = -1; dx <= 1; dx++) {
					int _y = y + dy, _x = x + dx;
					if (0 <= _y && _y < H && 0 <= _x && _x < W && a[_y][_x] == '#') {
						a[_y][_x] = '.';
						_q.push(i_i(_y, _x));
					}
				}
		}
		q = _q;
	}
	cout << t - 1 << endl;
}
0