結果

問題 No.340 雪の足跡
ユーザー pekempeypekempey
提出日時 2016-11-21 04:30:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,201 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 173,464 KB
実行使用メモリ 11,480 KB
最終ジャッジ日時 2023-08-18 06:06:49
合計ジャッジ時間 4,809 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,648 KB
testcase_01 AC 4 ms
9,420 KB
testcase_02 AC 5 ms
7,400 KB
testcase_03 AC 4 ms
9,440 KB
testcase_04 AC 4 ms
9,420 KB
testcase_05 AC 5 ms
7,456 KB
testcase_06 AC 4 ms
9,432 KB
testcase_07 AC 4 ms
7,392 KB
testcase_08 AC 4 ms
9,416 KB
testcase_09 AC 6 ms
9,288 KB
testcase_10 AC 4 ms
9,492 KB
testcase_11 AC 5 ms
9,500 KB
testcase_12 AC 4 ms
9,444 KB
testcase_13 AC 5 ms
9,420 KB
testcase_14 AC 8 ms
9,836 KB
testcase_15 AC 8 ms
9,816 KB
testcase_16 AC 7 ms
9,828 KB
testcase_17 AC 9 ms
9,856 KB
testcase_18 AC 9 ms
9,872 KB
testcase_19 AC 9 ms
9,772 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 10 ms
11,248 KB
testcase_23 AC 41 ms
11,188 KB
testcase_24 AC 28 ms
11,244 KB
testcase_25 AC 30 ms
11,300 KB
testcase_26 AC 11 ms
9,800 KB
testcase_27 AC 5 ms
9,536 KB
testcase_28 AC 10 ms
9,756 KB
testcase_29 AC 57 ms
11,016 KB
testcase_30 AC 41 ms
10,276 KB
testcase_31 AC 69 ms
11,056 KB
testcase_32 AC 79 ms
11,312 KB
testcase_33 AC 66 ms
11,148 KB
testcase_34 AC 80 ms
11,308 KB
testcase_35 AC 49 ms
11,144 KB
testcase_36 AC 49 ms
11,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

int in() {
    int n, c;
    while ((c = getchar()) < '0') if (c == EOF) abort();
    n = c - '0';
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

short hor[1001][1001];
short ver[1001][1001];
int dist[1001][1001];

int main() {
    int w = in(), h = in(), n = in();

    for (int i = 0; i < n; i++) {
        int m = in();
        int pre = -1;
        for (int i = 0; i <= m; i++) {
            int cur = in();
            if (pre != -1) {
                int y = pre / w;
                int x = pre % w;
                int yy = cur / w;
                int xx = cur % w;
                if (y == yy) {
                    hor[y][min(x, xx)]++;
                    hor[y][max(x, xx)]--;
                } else {
                    ver[x][min(y, yy)]++;
                    ver[x][max(y, yy)]--;
                }
            }
            pre = cur;
        }
    }
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) hor[i][j + 1] += hor[i][j];
    for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) ver[i][j + 1] += ver[i][j];

    memset(dist, -1, sizeof(dist));
    dist[0][0] = 0;
    queue<pair<int, int>> q;
    q.emplace(0, 0);

    while (!q.empty()) {
        int y, x;
        tie(y, x) = q.front(); q.pop();
        if (y == h - 1 && x == w - 1) break;
        if (x > 0 && hor[y][x - 1] > 0 && dist[y][x - 1] == -1) {
            dist[y][x - 1] = dist[y][x] + 1;
            q.emplace(y, x - 1);
        }
        if (x + 1 < w && hor[y][x] > 0 && dist[y][x + 1] == -1) {
            dist[y][x + 1] = dist[y][x] + 1;
            q.emplace(y, x + 1);
        }
        if (y > 0 && ver[x][y - 1] > 0 && dist[y - 1][x] == -1) {
            dist[y - 1][x] = dist[y][x] + 1;
            q.emplace(y - 1, x);
        }
        if (y + 1 < h && ver[x][y] > 0 && dist[y + 1][x] == -1) {
            dist[y + 1][x] = dist[y][x] + 1;
            q.emplace(y + 1, x);
        }
    }

    if (dist[h - 1][w - 1] == -1) {
        puts("Odekakedekinai..");
    } else {
        cout << dist[h - 1][w - 1] << endl;
    }
}
0