結果

問題 No.340 雪の足跡
ユーザー kyunakyuna
提出日時 2019-08-21 14:39:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,151 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 87,384 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-04-17 06:02:01
合計ジャッジ時間 8,554 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 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 4 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 19 ms
5,376 KB
testcase_15 AC 24 ms
5,376 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 31 ms
5,376 KB
testcase_18 AC 24 ms
5,376 KB
testcase_19 AC 32 ms
5,376 KB
testcase_20 AC 307 ms
15,488 KB
testcase_21 AC 193 ms
5,376 KB
testcase_22 AC 14 ms
15,488 KB
testcase_23 WA -
testcase_24 AC 298 ms
15,360 KB
testcase_25 AC 345 ms
15,360 KB
testcase_26 AC 51 ms
5,376 KB
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 44 ms
5,376 KB
testcase_29 AC 317 ms
10,496 KB
testcase_30 AC 220 ms
8,832 KB
testcase_31 AC 338 ms
14,464 KB
testcase_32 AC 410 ms
15,488 KB
testcase_33 AC 296 ms
15,488 KB
testcase_34 AC 392 ms
15,488 KB
testcase_35 AC 347 ms
15,488 KB
testcase_36 AC 353 ms
15,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

int main() {
    int w, h, n; cin >> w >> h >> n;
    vector<vector<int>> row(h, vector<int>(w + 1));
    vector<vector<int>> col(h + 1, vector<int>(w));
    while (n--) {
        int m; cin >> m;
        vector<int> b(m + 1);
        for (int &bi: b) cin >> bi;
        for (int i = 0; i < m; i++) {
            int p0 = b[i], p1 = b[i + 1];
            int i0 = p0 / w, j0 = p0 % w;
            int i1 = p1 / w, j1 = p1 % w;
            if (i0 == i1) {
                if (j0 > j1) swap(j0, j1);
                j1++;
                row[i0][j0]++;
                row[i1][j1]--;
            } else {
                if (i0 > i1) swap(i0, i1);
                i1++;
                col[i0][j0]++;
                col[i1][j1]--;
            }
        }
    }
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        row[i][j + 1] += row[i][j];
    }
    for (int j = 0; j < w; j++) for (int i = 0; i < h; i++) {
        col[i + 1][j] += col[i][j];
    }
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    dist[0][0] = 0; que.emplace(0, 0);
    while (!que.empty()) {
        int i, j; tie(i, j) = que.front(); que.pop();
        if (row[i][j]) {
            if (j - 1 >= 0 && row[i][j - 1] && dist[i][j - 1] == -1) {
                dist[i][j - 1] = dist[i][j] + 1; que.emplace(i, j - 1);
            }
            if (j + 1 < w && row[i][j + 1] && dist[i][j + 1] == -1) {
                dist[i][j + 1] = dist[i][j] + 1; que.emplace(i, j + 1);
            }
        }
        if (col[i][j]) {
            if (i - 1 >= 0 && col[i - 1][j] && dist[i - 1][j] == -1) {
                dist[i - 1][j] = dist[i][j] + 1; que.emplace(i - 1, j);
            }
            if (i + 1 < h && col[i + 1][j] && dist[i + 1][j] == -1) {
                dist[i + 1][j] = dist[i][j] + 1; que.emplace(i + 1, j);
            }
        }
    }
    int res = dist[h - 1][w - 1];
    if (res == -1) {
        cout << "Odekakedekinai.." << endl;
    } else {
        cout << res << endl;
    }
    return 0;
}
0