結果

問題 No.402 最も海から遠い場所
ユーザー kapokapo
提出日時 2016-07-22 23:48:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 954 ms / 3,000 ms
コード長 2,152 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 78,008 KB
実行使用メモリ 111,976 KB
最終ジャッジ日時 2023-08-06 10:25:34
合計ジャッジ時間 5,595 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 7 ms
5,456 KB
testcase_14 AC 5 ms
7,788 KB
testcase_15 AC 24 ms
10,512 KB
testcase_16 AC 33 ms
12,988 KB
testcase_17 AC 397 ms
43,976 KB
testcase_18 AC 954 ms
42,484 KB
testcase_19 AC 654 ms
111,976 KB
testcase_20 AC 710 ms
38,716 KB
testcase_21 AC 652 ms
76,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()

typedef pair<int, int> Pii;
typedef vector<int> V;
typedef long long ll;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int MAX_N = 202020;

int A[3003][3003];
int H, W;
queue<Pii> Qe, Qo;
int dy[8] = {-1,-1,0,1,1,1,0,-1}; // u r d l
int dx[8] = {0,1,1,1,0,-1,-1,-1};

int main()
{
	cin >> H >> W;
	fill(A[0],A[H+2],9999);

	rep(i,0,H+2) { // tate
		A[i][0] = 0;
		Qo.push(mp(i,0));
		A[i][W+1] = 0;
		Qo.push(mp(i,W+1));
	}
	rep(i,0,W+2) { // yoko
		A[0][i] = 0;
		Qo.push(mp(0,i));
		A[H+1][i] = 0;
		Qo.push(mp(H+1,i));
	}
	rep(i,1,H+1) rep(j,1,W+1) {
		char c; cin >> c;
		if (c == '.') {
			A[i][j] = 0;
			Qo.push(mp(i,j));
		}
	}
	//rep(i,0,H+2) { rep(j,0,W+2) printf("%04d ",A[i][j]); cout << endl; } cout << endl;

	rep(i,1,max(H,W)+1) {
		if (i%2==0) { // Qe
			while(!Qe.empty()) {
				Pii P = Qe.front(); Qe.pop();
				int cy = P.first, cx = P.second;
				rep(j,0,8) {
					int ty = cy + dy[j];
					int tx = cx + dx[j];
					if (ty<0 || ty>H+1 || tx<0 || tx>W+1) continue;
					if (A[ty][tx] == 9999) {
						A[ty][tx] = i;
						Qo.push(mp(ty,tx));
					}
				}
			}
		}
		else { // Qo
			while(!Qo.empty()) {
				Pii P = Qo.front(); Qo.pop();
				int cy = P.first, cx = P.second;
				//printf("     cy=%d cx=%d\n",cy,cx);
				rep(j,0,8) {
					int ty = cy + dy[j];
					int tx = cx + dx[j];
					if (ty<0 || ty>H+1 || tx<0 || tx>W+1) continue;
					if (A[ty][tx] == 9999) {
						A[ty][tx] = i;
						Qe.push(mp(ty,tx));
						//if(i==1) printf("push ty=%d tx=%d\n",ty,tx);
					}
				}
			}
		//if (i==1) rep(i,0,H+2) { rep(j,0,W+2) printf("%04d ",A[i][j]); cout << endl; } cout << endl;
		}
	}
	//rep(i,0,H+2) { rep(j,0,W+2) printf("%04d ",A[i][j]); cout << endl; }

	int ans = 0;
	rep(i,0,H+2) rep(j,0,W+2) ans = max(ans, A[i][j]);
	cout << ans;

	return 0;
}
0