結果

問題 No.402 最も海から遠い場所
ユーザー TawaraTawara
提出日時 2016-07-22 20:20:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 535 ms / 3,000 ms
コード長 1,098 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 56,556 KB
実行使用メモリ 85,248 KB
最終ジャッジ日時 2024-04-24 05:33:54
合計ジャッジ時間 4,114 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 5 ms
5,888 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 15 ms
9,472 KB
testcase_16 AC 20 ms
11,648 KB
testcase_17 AC 279 ms
58,880 KB
testcase_18 AC 535 ms
85,248 KB
testcase_19 AC 515 ms
85,248 KB
testcase_20 AC 520 ms
85,212 KB
testcase_21 AC 520 ms
85,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf("%d %d",&H,&W);
      |         ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

#define range(i,a,b) for(int i=(a); i < (b); i++)
#define rep(i,n) range(i,0,n)

string S[3000];
int VD[3002][3002],HD[3002][3002];

int main(){
	int H,W,MAX,ans = 0;
	scanf("%d %d",&H,&W);
	if ((H < 1)||(H > 3000)) throw "H is bad!";
	if ((W < 1)||(W > 3000)) throw "W is bad!";
	rep(i,H){
		cin >> S[i];
	 	if(S[i].size() != W) throw "row size";
	 	rep(j,W){
	 		if((S[i][j] != '#') && (S[i][j] != '.')) throw "row element";
	 	}
	}
	MAX = max(H,W);
	rep(i,H+2) rep(j,W+2){
		if (i < 1 || i > H || j < 1 || j > W){
			VD[i][j] = HD[j][i] = 0;
		}
		else{
			VD[i][j] = HD[j][i] = (S[i-1][j-1] == '.' ? 0 : MAX);
		}
	}
	range(i,1,H+1) range(j,1,W+1) rep(k,3){
		VD[i][j] = min(VD[i][j],VD[i-1][j-1+k]+1);
		VD[H+1-i][j] = min(VD[H+1-i][j],VD[H+2-i][j-1+k]+1);
	}
	range(j,1,W+1) range(i,1,H+1) rep(k,3){
		HD[j][i] = min(HD[j][i],HD[j-1][i-1+k]+1);
		HD[W+1-j][i] = min(HD[W+1-j][i],HD[W+2-j][i-1+k]+1);
	}
	range(i,1,H+1) range(j,1,W+1){
		ans = max(ans,min(VD[i][j],HD[j][i]));
	}
	printf("%d\n",ans);
	return 0;
}
0