結果

問題 No.402 最も海から遠い場所
ユーザー chocoruskchocorusk
提出日時 2019-07-06 19:12:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,136 ms / 3,000 ms
コード長 1,855 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 105,304 KB
実行使用メモリ 227,808 KB
最終ジャッジ日時 2024-04-08 13:50:46
合計ジャッジ時間 12,558 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
146,600 KB
testcase_01 AC 93 ms
146,600 KB
testcase_02 AC 93 ms
146,856 KB
testcase_03 AC 93 ms
146,600 KB
testcase_04 AC 93 ms
146,600 KB
testcase_05 AC 97 ms
146,600 KB
testcase_06 AC 92 ms
146,600 KB
testcase_07 AC 95 ms
146,600 KB
testcase_08 AC 93 ms
146,600 KB
testcase_09 AC 92 ms
146,600 KB
testcase_10 AC 92 ms
146,600 KB
testcase_11 AC 92 ms
146,728 KB
testcase_12 AC 92 ms
146,728 KB
testcase_13 AC 99 ms
147,368 KB
testcase_14 AC 97 ms
149,376 KB
testcase_15 AC 131 ms
151,040 KB
testcase_16 AC 146 ms
150,656 KB
testcase_17 AC 863 ms
186,944 KB
testcase_18 AC 2,136 ms
157,440 KB
testcase_19 AC 1,525 ms
227,808 KB
testcase_20 AC 1,680 ms
153,600 KB
testcase_21 AC 1,666 ms
227,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%s", s[i]+1);
      |         ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e8;
char s[3010][3010];
int h, w;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
bool check(int i, int j){
    if(i<0 || i>=h+w || j<0 || j>=h+w) return false;
    return true;
}
int main()
{
    cin>>h>>w;
    for(int i=1; i<=h; i++){
        scanf("%s", s[i]+1);
        s[i][0]='.';
        s[i][w+1]='.';
    }
    for(int i=0; i<w+2; i++) s[0][i]=s[h+1][i]='.';
    h+=2, w+=2;
    int d[6010][6010];
    for(int i=0; i<h+w; i++){
        for(int j=0; j<h+w; j++){
            d[i][j]=INF;
        }
    }
    queue<P> que;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j]=='.'){
                d[i+j][i-j+w-1]=0;
                que.push({i+j, i-j+w-1});
            }
        }
    }
    while(!que.empty()){
        P p=que.front();
        que.pop();
        int x=p.first, y=p.second;
        for(int k=0; k<4; k++){
            int x1=x+dx[k], y1=y+dy[k];
            if(!check(x1, y1)) continue;
            if(d[x1][y1]>d[x][y]+1){
                d[x1][y1]=d[x][y]+1;
                que.push({x1, y1});
            }
        }
    }
    int ans=0;
    for(int i=0; i<h+w; i++){
        for(int j=0; j<h+w; j++){
            if((i+j+w-1)&1) continue;
            int x=(i+j-w+1)/2, y=(i-j+w-1)/2;
            if(x<=0 || x>=h-1 || y<=0 || y>=w-1) continue;
            ans=max(ans, d[i][j]/2);
        }
    }
    cout<<ans<<endl;
    return 0;
}
0