結果

問題 No.402 最も海から遠い場所
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-23 00:14:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,640 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 66,188 KB
実行使用メモリ 159,220 KB
最終ジャッジ日時 2024-04-24 06:50:24
合計ジャッジ時間 4,361 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
40,960 KB
testcase_01 AC 28 ms
40,960 KB
testcase_02 AC 28 ms
41,088 KB
testcase_03 WA -
testcase_04 AC 28 ms
40,960 KB
testcase_05 AC 28 ms
40,704 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 28 ms
40,832 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 28 ms
40,960 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 51 ms
42,752 KB
testcase_16 AC 47 ms
43,520 KB
testcase_17 WA -
testcase_18 AC 586 ms
56,600 KB
testcase_19 AC 454 ms
159,220 KB
testcase_20 WA -
testcase_21 AC 406 ms
105,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

struct State {
    int row, col, dist;

    State(int row, int col, int dist) : row(row), col(col), dist(dist) { }
};

const int kMAX_H = 3100;
const int kMAX_W = 3100;
string S[kMAX_H];

int dist[kMAX_H][kMAX_W];

int H, W;

bool IsIn(int row, int col) {
    return 0 <= row && row < H && 0 <= col && col < W;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> H >> W;
    for (int r = 0; r < H; r++) {
        cin >> S[r];
    }

    queue<State> que;
    memset(dist, -1, sizeof(dist));
    for (int r = 0; r < H; r++) {
        for (int c = 0; c < W; c++) {
            if (S[r][c] == '.') {
                que.push(State(r, c, 0));
                dist[r][c] = 0;
            }
        }
    }
    while (!que.empty()) {
        State s = que.front(); que.pop();
        for (int dr = -1; dr <= 1; dr++) {
            for (int dc = -1; dc <= 1; dc++) {
                int nr = s.row + dr, nc = s.col + dc;
                if (IsIn(nr, nc) && S[nr][nc] == '#' && dist[nr][nc] < 0) {
                    que.push(State(nr, nc, s.dist + 1));
                    dist[nr][nc] = s.dist + 1;
                }
            }
        }
    }

    int ans = 0;
    for (int r = 0; r < H; r++) {
        for (int c = 0; c < W; c++) {
            if (S[r][c] == '.') continue;
            int move_r = min(r, H - 1 - r),
                move_c = min(c, W - 1 - c),
                c_dist = move_r + move_c - min(move_r, move_c);
            ans = max(ans, min(dist[r][c], c_dist));
        }
    }
    cout << ans << endl;

    return 0;
}
0