結果

問題 No.402 最も海から遠い場所
ユーザー mayoko_mayoko_
提出日時 2016-07-22 22:49:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 484 ms / 3,000 ms
コード長 1,932 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 106,520 KB
実行使用メモリ 125,080 KB
最終ジャッジ日時 2024-04-24 05:50:48
合計ジャッジ時間 3,784 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 12 ms
7,680 KB
testcase_16 AC 17 ms
8,832 KB
testcase_17 AC 186 ms
50,092 KB
testcase_18 AC 484 ms
55,296 KB
testcase_19 AC 340 ms
125,080 KB
testcase_20 AC 306 ms
51,712 KB
testcase_21 AC 309 ms
88,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXH = 3333;
const int INF = 1e9;
string board[MAXH];
int d[MAXH][MAXH];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        string s;
        cin >> s;
        s = '.' + s + '.';
        board[i] = s;
    }
    H += 2;
    W += 2;
    {
        string s;
        for (int i = 0; i < W; i++)
            s += '.';
        board[0] = s;
        board[H-1] = s;
    }
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++)
        d[i][j] = INF;
    queue<pii> que;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (board[i][j] == '.') {
            d[i][j] = 0;
            que.push(pii(i, j));
        }
    }
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        int y = p.first, x = p.second;
        for (int i = 0; i < 8; i++) {
            int ny = y+dy[i], nx = x+dx[i];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
            if (d[ny][nx] > d[y][x] + 1) {
                d[ny][nx] = d[y][x] + 1;
                que.push(pii(ny, nx));
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        ans = max(ans, d[i][j]);
    }
    cout << ans << endl;
    return 0;
}
0