結果

問題 No.402 最も海から遠い場所
ユーザー itezpaceitezpace
提出日時 2016-10-03 10:54:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 439 ms / 3,000 ms
コード長 1,219 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 67,592 KB
実行使用メモリ 38,704 KB
最終ジャッジ日時 2023-08-13 18:37:56
合計ジャッジ時間 4,196 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 12 ms
4,692 KB
testcase_17 AC 215 ms
20,696 KB
testcase_18 AC 439 ms
38,520 KB
testcase_19 AC 418 ms
38,704 KB
testcase_20 AC 437 ms
38,452 KB
testcase_21 AC 422 ms
38,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int H,W;cin>>H>>W;
  string S;
  vector<vector<int>> vv(H+2,vector<int>(W+2,-1));
  for(int i=0;i<H+2;++i) vv[i][0]=0;
  for(int i=0;i<H+2;++i) vv[i][W+2-1]=0;
  for(int i=0;i<W+2;++i) vv[0][i]=0;
  for(int i=0;i<W+2;++i) vv[H+2-1][i]=0;

  for(int i=0;i<H;++i){
    cin>>S;
    for(int j=0;j<W;++j){
      if(S[j]=='.'){
        vv[i+1][j+1]=0;
      } else {
        int a=vv[i+1][j];
        int b=vv[i][j];
        int c=vv[i][j+1];
        vv[i+1][j+1]=min(a,min(b,c))+1;
      }
    }
  }

  for(int i=1;i<=H;++i){
    for(int j=W;j>=1;--j){
      int a=vv[i][j];
      int b=vv[i][j+1];
      int c=vv[i-1][j+1];
      vv[i][j]=min(a,min(b,c)+1);
    }
  }

  for(int i=1;i<=W;++i){
    for(int j=H;j>=1;--j){
      int a=vv[j][i];
      int b=vv[j+1][i-1];
      int c=vv[j+1][i];
      vv[j][i]=min(a,min(b,c)+1);
    }
  }

  for(int i=W;i>=1;--i){
    for(int j=H;j>=1;--j){
      int a=vv[j][i];
      int b=vv[j+1][i+1];
      vv[j][i]=min(a,b+1);
    }
  }

  int ans=0;
  for(int i=1;i<H+2;++i){
    for(int j=1;j<W+2;++j){
      if(vv[i][j]>ans) ans=vv[i][j];
    }
  }
  cout<<ans<<endl;
}
0