結果

問題 No.340 雪の足跡
ユーザー kimiyukikimiyuki
提出日時 2016-05-27 16:13:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,783 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 85,644 KB
実行使用メモリ 66,688 KB
最終ジャッジ日時 2024-04-16 17:44:18
合計ジャッジ時間 7,984 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 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 1 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 6 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 392 ms
20,736 KB
testcase_15 AC 544 ms
21,632 KB
testcase_16 AC 185 ms
11,776 KB
testcase_17 AC 778 ms
24,548 KB
testcase_18 AC 609 ms
24,576 KB
testcase_19 AC 805 ms
24,612 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
struct state_t { int dist, v; };
int main() {
    int w, h, n; cin >> w >> h >> n;
    vector<set<int> > g(h * w);
    repeat (i,n) {
        int m; cin >> m;
        vector<int> b(m+1); repeat (i,m+1) cin >> b[i];
        repeat (i,m) {
            int y0 = b[i]   / w;
            int y1 = b[i+1] / w;
            int x0 = b[i]   % w;
            int x1 = b[i+1] % w;
            if (y0 == y1) {
                int y = y0;
                repeat_from (z,min(x0,x1),max(x0,x1)) {
                    int u = y * w +  z;
                    int v = y * w + (z+1);
                    g[u].insert(v);
                    g[v].insert(u);
                }
            } else if (x0 == x1) {
                int x = x0;
                repeat_from (z,min(y0,y1),max(y0,y1)) {
                    int u =  z    * w + x;
                    int v = (z+1) * w + x;
                    g[u].insert(v);
                    g[v].insert(u);
                }
            } else {
                assert (false);
            }
        }
    }
    vector<int> dist(h * w);
    queue<state_t> que;
    dist[0] = 1;
    que.push((state_t) { 1, 0 });
    while (not que.empty()) {
        state_t s = que.front(); que.pop();
        for (int u : g[s.v]) {
            if (dist[u]) continue;
            state_t t;
            dist[u] = t.dist = s.dist + 1;
            t.v = u;
            que.push(t);
        }
    }
    if (dist[h * w - 1]) {
        cout << dist[h * w - 1] - 1 << endl;
    } else {
        cout << "Odekakedekinai.." << endl;
    }
    return 0;
}
0