結果

問題 No.402 最も海から遠い場所
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-22 23:41:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,798 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 81,460 KB
実行使用メモリ 50,048 KB
最終ジャッジ日時 2024-04-24 06:17:25
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 328 ms
50,048 KB
testcase_19 AC 182 ms
14,848 KB
testcase_20 AC 320 ms
50,048 KB
testcase_21 AC 263 ms
50,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
int d[3005][3005] = {0};
string s[3005];
// int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
// int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1, 1};
int dx[3] = {0, -1, -1,};
int dy[3] = {-1, -1, 0};
int dx1[3] = {1, 1, 0};
int dy1[3] = {0, 1, 1};
const int INF = 1e8;
int main(void){
	int h, w; cin >> h >> w;
	rep(i, w + 2){
		s[0].push_back('.');
		s[h + 1].push_back('.');
	}
	reps(i, 1, h + 1){
		cin >> s[i];
		s[i].insert(s[i].begin(), '.');
		s[i].push_back('.');
	}


	for (int i = 1; i < h + 1; ++i){//y h
		for (int j = 1; j < w + 1; ++j){//x w
			if(s[i][j] == '.') continue;
			int mini = INF;
			rep(k, 3){
				int y = i + dy[k], x = j + dx[k];
				
				if(0 <= x && x <= w + 1 && 0 <= y && y <= h + 1){
				
					mini = min(d[y][x], mini);
				}
			}
			
			d[i][j] = mini + 1;
		
		
		}
	}
	for (int i = h; i >= 1; --i){//y h
		for (int j = w; j >= 1; --j){//x w
			if(s[i][j] == '.') continue;
			int mini = INF;
			rep(k, 3){
				int y = i + dy1[k], x = j + dx1[k];

				if(0 <= x && x <= w + 1 && 0 <= y && y <= h + 1){
	
					mini = min(d[y][x], mini);
				}
			}
		
			if(d[i][j] > mini) d[i][j] = mini + 1;
	
		}
	}
	int ans = 0;
	rep(i, h + 2){
		rep(j, w + 2){
			ans = max(ans, d[i][j]);
		}
	}
	printf("%d\n", ans);

	return 0;
}
0