結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,640 KB
testcase_01 AC 4 ms
9,492 KB
testcase_02 WA -
testcase_03 AC 4 ms
9,472 KB
testcase_04 WA -
testcase_05 AC 5 ms
7,280 KB
testcase_06 AC 4 ms
9,664 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 5 ms
9,344 KB
testcase_10 WA -
testcase_11 AC 4 ms
9,476 KB
testcase_12 AC 4 ms
9,460 KB
testcase_13 AC 4 ms
9,668 KB
testcase_14 AC 7 ms
9,716 KB
testcase_15 AC 8 ms
9,840 KB
testcase_16 AC 6 ms
9,756 KB
testcase_17 AC 9 ms
9,792 KB
testcase_18 AC 8 ms
9,808 KB
testcase_19 AC 9 ms
9,864 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 40 ms
11,168 KB
testcase_24 AC 27 ms
11,176 KB
testcase_25 WA -
testcase_26 AC 10 ms
9,656 KB
testcase_27 AC 5 ms
9,480 KB
testcase_28 AC 9 ms
9,688 KB
testcase_29 AC 49 ms
11,068 KB
testcase_30 AC 36 ms
10,236 KB
testcase_31 AC 57 ms
11,088 KB
testcase_32 AC 66 ms
11,228 KB
testcase_33 AC 53 ms
11,232 KB
testcase_34 AC 65 ms
11,180 KB
testcase_35 AC 48 ms
11,184 KB
testcase_36 AC 47 ms
11,256 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