結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 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 3 ms
5,376 KB
testcase_13 AC 5 ms
5,888 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 18 ms
9,600 KB
testcase_16 AC 22 ms
11,648 KB
testcase_17 AC 247 ms
59,008 KB
testcase_18 AC 487 ms
85,376 KB
testcase_19 AC 499 ms
85,504 KB
testcase_20 AC 468 ms
85,212 KB
testcase_21 AC 496 ms
85,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%d %d",&H,&W);
      |         ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

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

using namespace std;

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

int VD[3002][3002],HD[3002][3002];

int main(){
	int H,W,MAX,ans = 0;
	vector <string> S;
	scanf("%d %d",&H,&W);
	S = vector <string> (H);
	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