結果

問題 No.402 最も海から遠い場所
ユーザー 👑 kmjpkmjp
提出日時 2016-07-22 22:36:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 574 ms / 3,000 ms
コード長 1,286 bytes
コンパイル時間 1,349 ms
コンパイル使用メモリ 151,780 KB
実行使用メモリ 93,336 KB
最終ジャッジ日時 2023-08-06 09:47:05
合計ジャッジ時間 4,749 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
4,472 KB
testcase_14 AC 3 ms
6,292 KB
testcase_15 AC 15 ms
9,508 KB
testcase_16 AC 20 ms
12,076 KB
testcase_17 AC 223 ms
43,360 KB
testcase_18 AC 574 ms
58,744 KB
testcase_19 AC 344 ms
93,336 KB
testcase_20 AC 373 ms
56,864 KB
testcase_21 AC 330 ms
75,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
string S[3030];
int D[3030][3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	
	FOR(y,H) cin>>S[y+1], S[y+1]='.'+S[y+1]+'.';
	
	FOR(x,W+2) S[0]+='.', S[H+1]+='.';
	H+=2;
	W+=2;
	
	FOR(y,H) FOR(x,W) D[y][x]=3030;
	queue<int> Q;
	FOR(y,H) FOR(x,W) {
		if(S[y][x]=='.') D[y][x]=0, Q.push(y*10000+x);
	}
	
	int ma=0;
	while(Q.size()) {
		k=Q.front();
		Q.pop();
		int cy=k/10000,cx=k%10000;
		FOR(i,9) {
			int ty=cy+(i/3-1);
			int tx=cx+(i%3-1);
			if(tx<0 || tx>=W || ty<0||ty>=H || D[ty][tx]<=D[cy][cx]+1) continue;
			ma=D[ty][tx]=D[cy][cx]+1;
			Q.push(ty*10000+tx);
		}
	}
	
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0