結果

問題 No.402 最も海から遠い場所
ユーザー nasadigitalnasadigital
提出日時 2016-07-22 23:01:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 558 ms / 3,000 ms
コード長 1,433 bytes
コンパイル時間 1,416 ms
コンパイル使用メモリ 149,760 KB
実行使用メモリ 111,944 KB
最終ジャッジ日時 2023-08-06 09:58:01
合計ジャッジ時間 4,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
38,592 KB
testcase_01 AC 12 ms
38,584 KB
testcase_02 AC 12 ms
38,688 KB
testcase_03 AC 12 ms
38,552 KB
testcase_04 AC 12 ms
38,596 KB
testcase_05 AC 12 ms
38,740 KB
testcase_06 AC 12 ms
38,600 KB
testcase_07 AC 12 ms
38,560 KB
testcase_08 AC 12 ms
38,736 KB
testcase_09 AC 11 ms
38,596 KB
testcase_10 AC 12 ms
38,680 KB
testcase_11 AC 12 ms
38,588 KB
testcase_12 AC 12 ms
38,668 KB
testcase_13 AC 14 ms
38,788 KB
testcase_14 AC 12 ms
38,688 KB
testcase_15 AC 24 ms
39,592 KB
testcase_16 AC 28 ms
39,844 KB
testcase_17 AC 226 ms
56,420 KB
testcase_18 AC 558 ms
42,560 KB
testcase_19 AC 389 ms
111,944 KB
testcase_20 AC 359 ms
38,788 KB
testcase_21 AC 349 ms
75,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int dir[8][2] = {{1,1},{1,-1},{-1,1},{-1,-1},{1,0},{-1,0},{0,1},{0,-1}};

int n,m;
bool isok(int a,int b){
    return a>=0 && a<=n+1 && b>=0 && b<=m+1;
}

int r[3003][3003];

int main()
{
    memset(r,-1,sizeof(r));
    ios::sync_with_stdio(false);
    queue<ii> bfs;

    cin>>n>>m;
    string t;
    for(int ctr1=0;ctr1<=m+1;ctr1++)
    bfs.push({0,ctr1}),r[0][ctr1]=0;
    for(int ctr1=1;ctr1<=n;ctr1++){
        bfs.push({ctr1,0}),r[ctr1][0]=0;
        cin>>t;
        for(int ctr2=0;ctr2<m;ctr2++){
            if(t[ctr2]=='.')
            bfs.push({ctr1,ctr2+1}),r[ctr1][ctr2+1]=0;
        }
        bfs.push({ctr1,m+1}),r[ctr1][m+1]=0;
    }
    for(int ctr1=0;ctr1<=m+1;ctr1++)
    bfs.push({n+1,ctr1}),r[n+1][ctr1]=0;
    int rez=0;
    while(!bfs.empty()){
        ii cur=bfs.front();
        bfs.pop();
        for(int ctr2=0;ctr2<8;ctr2++)
        if(isok(cur.first+dir[ctr2][0],cur.second+dir[ctr2][1]) && r[cur.first+dir[ctr2][0]][cur.second+dir[ctr2][1]]==-1)
            bfs.push({cur.first+dir[ctr2][0],cur.second+dir[ctr2][1]}),rez=r[cur.first+dir[ctr2][0]][cur.second+dir[ctr2][1]]=r[cur.first][cur.second]+1;
    }
    cout<<rez;
    return 0;
}
0