結果

問題 No.402 最も海から遠い場所
ユーザー nasadigitalnasadigital
提出日時 2016-07-22 22:53:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,398 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 174,300 KB
実行使用メモリ 297,448 KB
最終ジャッジ日時 2024-04-24 05:52:04
合計ジャッジ時間 7,003 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 38 ms
6,272 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 203 ms
18,944 KB
testcase_16 AC 340 ms
24,704 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

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 main()
{
    ios::sync_with_stdio(false);
    map<ii,int> r;
    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.count({cur.first+dir[ctr2][0],cur.second+dir[ctr2][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]+1;
    }
    cout<<rez;
    return 0;
}
0