結果

問題 No.402 最も海から遠い場所
ユーザー 小指が強い人小指が強い人
提出日時 2016-07-23 13:34:14
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 3,917 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 169,312 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2024-04-24 07:41:28
合計ジャッジ時間 9,385 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 30 ms
38,656 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 29 ms
38,784 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << a << endl;}
template<class T> void writes(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
void write(double a){cout << fixed << setprecision(12) << a << endl;}
void write(long double a){cout << fixed << setprecision(12) << a << endl;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};

int main(void)
{
    const int MAX=1e9;
    int h,w;
    veci fd[3000];
    rep(i,3000)fd[i].resize(3000,MAX);
    cin>>h>>w;
    rep(i,h){
        string s;
        cin>>s;
        rep(j,w){
            if(s[j]=='.')fd[i][j]=0;
            else{
                if(i==0||i==h-1||j==0||j==w-1)
                    fd[i][j]=1;
            }
        }
    }
    int res=0;
    rep(i,h)REP(j,1,w)
        fd[i][j]=min(fd[i][j],fd[i][j-1]+1);
    rep(i,h)RREP(j,0,w-1)
        fd[i][j]=min(fd[i][j],fd[i][j+1]+1);
    rep(i,h)REP(j,1,w)
        fd[j][i]=min(fd[j][i],fd[j-1][i]+1);
    rep(i,h)RREP(j,0,w-1)
        fd[j][i]=min(fd[j][i],fd[j+1][i]+1);
    int mhw=max(w,h);
    rep(i,mhw){
        int j=i+1,ti=1;
        while(ti<h&&j<w){
            fd[ti][j]=min(fd[ti][j],fd[ti-1][j-1]+1);
            j++;ti++;
        }
        j=i+1,ti=1;
        while(j<h&&ti<w){
            fd[j][ti]=min(fd[j][ti],fd[j-1][ti-1]+1);
            j++;ti++;
        }
    }
    rep(i,mhw){
        int j=i-1,ti=1;
        while(ti<h&&j>=0){
            fd[ti][j]=min(fd[ti][j],fd[ti-1][j+1]+1);
            j--;ti++;
        }
        j=w-2,ti=i;
        while(ti<h&&j>=0){
            fd[ti][j]=min(fd[ti][j],fd[ti-1][j+1]+1);
            j--;ti++;
        }
    }
    rep(i,mhw){
        int j=i+1,ti=h-2;
        while(ti>=0&&j<w){
            fd[ti][j]=min(fd[ti][j],fd[ti+1][j-1]+1);
            j++;ti--;
        }
        j=1,ti=h-i-2;
        while(ti>=0&&j<w){
            fd[ti][j]=min(fd[ti][j],fd[ti+1][j-1]+1);
            j++;ti--;
        }
    }
    rep(i,mhw){
        int j=w-i-2,ti=h-2;
        while(ti>=0&&j>=0){
            fd[ti][j]=min(fd[ti][j],fd[ti+1][j+1]+1);
            j--;ti--;
        }
        j=w-2,ti=h-i-2;
        while(ti>=0&&j>=0){
            fd[ti][j]=min(fd[ti][j],fd[ti+1][j+1]+1);
            j--;ti--;
        }
    }
    rep(i,h){
        rep(j,w){
            res=max(res,fd[i][j]);
            //cout<<fd[i][j];
        }
        //cout<<endl;
    }
    write(res);
    return 0;
}
0