結果

問題 No.340 雪の足跡
ユーザー kimiyukikimiyuki
提出日時 2016-05-27 16:47:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,115 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 66,192 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-16 17:45:04
合計ジャッジ時間 14,653 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 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 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 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 27 ms
5,376 KB
testcase_18 AC 20 ms
5,376 KB
testcase_19 AC 26 ms
5,376 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 AC 5 ms
8,576 KB
testcase_23 AC 717 ms
8,576 KB
testcase_24 TLE -
testcase_25 AC 880 ms
8,832 KB
testcase_26 AC 37 ms
5,376 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 34 ms
5,376 KB
testcase_29 AC 447 ms
6,912 KB
testcase_30 AC 265 ms
5,888 KB
testcase_31 AC 496 ms
8,320 KB
testcase_32 AC 615 ms
8,832 KB
testcase_33 AC 460 ms
8,832 KB
testcase_34 AC 615 ms
8,576 KB
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <cstdint>
#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;
const int UP    = 0;
const int DOWN  = 1;
const int RIGHT = 2;
const int LEFT  = 3;
const int dy[4] = { -1, 1, 0, 0 };
const int dx[4] = { 0, 0, 1, -1 };
struct state_t { int dist; int16_t y, x; };
int main() {
    int w, h, n; scanf("%d%d%d", &w, &h, &n);
    vector<vector<uint8_t> > g(h, vector<uint8_t>(w));
    repeat (i,n) {
        int m; scanf("%d", &m);
        vector<int> b(m+1); repeat (i,m+1) scanf("%d", &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)) {
                    g[y][z  ] |= (1 << RIGHT);
                    g[y][z+1] |= (1 << LEFT);
                }
            } else if (x0 == x1) {
                int x = x0;
                repeat_from (z,min(y0,y1),max(y0,y1)) {
                    g[z  ][x] |= (1 << DOWN);
                    g[z+1][x] |= (1 << UP);
                }
            } else {
                assert (false);
            }
        }
    }
    vector<vector<int> > dist(h, vector<int>(w));
    queue<state_t> que;
    dist[0][0] = 1;
    que.push((state_t) { 1, 0, 0 });
    while (not que.empty()) {
        state_t s = que.front(); que.pop();
        repeat (i,4) {
            if (not (g[s.y][s.x] & (1 << i))) continue; // the edge doesn't exist
            state_t t;
            t.dist = s.dist + 1;
            t.y = s.y + dy[i];
            t.x = s.x + dx[i];
            if (t.y < 0 or h <= t.y or t.x < 0 or w <= t.x) continue;
            if (dist[t.y][t.x]) continue;
            dist[t.y][t.x] = t.dist;
            que.push(t);
        }
    }
    if (dist[h-1][w-1]) {
        printf("%d\n", dist[h-1][w-1] - 1);
    } else {
        puts("Odekakedekinai..");
    }
    return 0;
}
0