結果

問題 No.402 最も海から遠い場所
ユーザー AreTrashAreTrash
提出日時 2016-06-24 04:13:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,314 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 66,896 KB
実行使用メモリ 57,272 KB
最終ジャッジ日時 2024-04-24 03:20:41
合計ジャッジ時間 3,075 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 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 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
6,784 KB
testcase_16 AC 16 ms
8,064 KB
testcase_17 AC 168 ms
34,368 KB
testcase_18 AC 525 ms
40,832 KB
testcase_19 AC 226 ms
40,120 KB
testcase_20 WA -
testcase_21 AC 238 ms
57,272 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         scanf("%s", s);
      |         ~~~~~^~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;

int W, H;
int dist[3010][3010] = { 0 };
char s[3010];

int main(void)
{
    cin >> H >> W;
    queue<int> Q;

    for (int i = 2; i <= H + 1; i++) {
        scanf("%s", s);
        for (int j = 2; j <= W + 1; j++) {
            if (s[j - 2] == '#') {
                dist[i][j] = 1510;
            } else {
                Q.push((j << 12) + i);
            }
        }
    }

    for (int i = 2; i <= H + 1; i++) {
        Q.push((1 << 12) + i);
        Q.push((W + 2 << 12) + i);
    }
    for (int i = 2; i <= W + 1; i++) {
        Q.push((i << 12) + 1);
        Q.push((i << 12) + H + 2);
    }

    int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
    int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
    int ans = 0;

    while (Q.size()) {
        //t > 2^8 NG
        int deq = Q.front(); Q.pop();
        int t = deq >> 24 & 0xfff;
        int x = deq >> 12 & 0xfff;
        int y = deq & 0xfff;
        for (int i = 0; i < 8; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (dist[ny][nx] > t + 1) {
                ans = max(ans, dist[ny][nx] = t + 1);
                Q.push((t + 1 << 24) + (nx << 12) + ny);
            }
        }
    }

    cout << ans << endl;
    return 0;
}
0