結果

問題 No.402 最も海から遠い場所
ユーザー AreTrashAreTrash
提出日時 2016-07-22 14:03:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 579 ms / 3,000 ms
コード長 1,224 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 67,364 KB
実行使用メモリ 224,264 KB
最終ジャッジ日時 2024-04-24 05:30:50
合計ジャッジ時間 3,966 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_06 AC 2 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 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 18 ms
9,216 KB
testcase_16 AC 19 ms
9,600 KB
testcase_17 AC 299 ms
79,536 KB
testcase_18 AC 528 ms
44,756 KB
testcase_19 AC 579 ms
224,264 KB
testcase_20 AC 345 ms
38,784 KB
testcase_21 AC 431 ms
150,780 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);
      |         ~~~~~^~~~~~~~~
main.cpp:53:22: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |     cout << dist[y][x] << endl;
      |                      ^
main.cpp:53:22: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]

ソースコード

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(0); Q.push(j); Q.push(i);
            }
        }
    }

    for (int i = 1; i <= H + 2; i++) {
        for (int j = 1; j <= W + 2; j++) {
            if (dist[i][j] == 0) {
                Q.push(0); Q.push(j); Q.push(i);
            }
        }
    }

    int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
    int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
    int t, x, y, nx, ny;

    while (Q.size()) {
        t = Q.front(); Q.pop();
        x = Q.front(); Q.pop();
        y = Q.front(); Q.pop();
        for (int i = 0; i < 8; i++) {
            nx = x + dx[i];
            ny = y + dy[i];
            if (dist[ny][nx] > t + 1) {
                dist[ny][nx] = t + 1;
                Q.push(t + 1); Q.push(nx); Q.push(ny);
            }
        }
    }

    cout << dist[y][x] << endl;
    return 0;
}
0