結果

問題 No.402 最も海から遠い場所
ユーザー haruteruharuteru
提出日時 2016-07-26 13:10:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,127 ms / 3,000 ms
コード長 2,373 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 57,696 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2024-04-24 09:31:36
合計ジャッジ時間 7,369 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 19 ms
6,400 KB
testcase_16 AC 27 ms
7,040 KB
testcase_17 AC 491 ms
25,472 KB
testcase_18 AC 1,106 ms
38,656 KB
testcase_19 AC 1,120 ms
38,656 KB
testcase_20 AC 1,127 ms
38,784 KB
testcase_21 AC 1,124 ms
38,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

#define MAX (3000)

int H, W;
int S[MAX+2][MAX+2];

int fn(int h, int w, int (*inc)(int &,int &))
{
    int *p = &S[h][w];
    if (inc(h, w)) {
        *p = min(*p, 1);
    }
    else {
        *p = min(*p, fn(h, w, inc) + 1);
    }
    return *p;
}

int main()
{
    cin >> H;
    cin >> W;
    for (int h = 0; h < H; h++) {
        string s;
        cin >> s;
        for (int w = 0; w < W; w++) {
            if (s[w] == '.') {
                S[h][w] = 0;
            }
            else {
                S[h][w] = MAX;
            }
        }
    }
    for (int h = 0; h < H; h++) {
        fn(h, 0, [](int &hh, int &ww)->int {
            if (++ww >= W) return -1;
            return 0;
        });
        fn(h, W-1, [](int &hh, int &ww)->int {
            if (--ww < 0) return -1;
            return 0;
        });
        fn(h, 0, [](int &hh, int &ww)->int {
            if (++hh >= H || ++ww >= W) return -1;
            return 0;
        });
        fn(h, 0, [](int &hh, int &ww)->int {
            if (--hh < 0 || ++ww >= W) return -1;
            return 0;
        });
        fn(h, W-1, [](int &hh, int &ww)->int {
            if (--hh < 0 || --ww < 0) return -1;
            return 0;
        });
        fn(h, W-1, [](int &hh, int &ww)->int {
            if (++hh >= H || --ww < 0) return -1;
            return 0;
        });
    }
    for (int w = 0; w < W; w++) {
        fn(0, w, [](int &hh, int &ww)->int {
            if (++hh >= H) return -1;
            return 0;
        });
        fn(H-1, w, [](int &hh, int &ww)->int {
            if (--hh < 0) return -1;
            return 0;
        });
        fn(0, w, [](int &hh, int &ww)->int {
            if (++hh >= H || ++ww >= W) return -1;
            return 0;
        });
        fn(0, w, [](int &hh, int &ww)->int {
            if (++hh >= H || --ww < 0) return -1;
            return 0;
        });
        fn(H-1, w, [](int &hh, int &ww)->int {
            if (--hh < 0 || ++ww >= W) return -1;
            return 0;
        });
        fn(H-1, w, [](int &hh, int &ww)->int {
            if (--hh < 0 || --ww < 0) return -1;
            return 0;
        });
    }
    int ans = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            ans = max(ans, S[h][w]);
        }
    }
    cout << ans << endl;
}
0