結果
問題 | No.340 雪の足跡 |
ユーザー | ckawatak |
提出日時 | 2017-10-28 16:12:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 716 ms / 1,000 ms |
コード長 | 2,352 bytes |
コンパイル時間 | 1,356 ms |
コンパイル使用メモリ | 79,940 KB |
実行使用メモリ | 82,560 KB |
最終ジャッジ日時 | 2024-11-22 03:27:11 |
合計ジャッジ時間 | 11,484 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
28,032 KB |
testcase_01 | AC | 20 ms
28,032 KB |
testcase_02 | AC | 20 ms
27,904 KB |
testcase_03 | AC | 20 ms
28,032 KB |
testcase_04 | AC | 20 ms
28,032 KB |
testcase_05 | AC | 21 ms
27,904 KB |
testcase_06 | AC | 21 ms
28,032 KB |
testcase_07 | AC | 20 ms
28,032 KB |
testcase_08 | AC | 21 ms
28,032 KB |
testcase_09 | AC | 20 ms
27,904 KB |
testcase_10 | AC | 20 ms
28,032 KB |
testcase_11 | AC | 22 ms
28,160 KB |
testcase_12 | AC | 21 ms
28,160 KB |
testcase_13 | AC | 22 ms
28,288 KB |
testcase_14 | AC | 52 ms
31,872 KB |
testcase_15 | AC | 58 ms
32,000 KB |
testcase_16 | AC | 43 ms
29,696 KB |
testcase_17 | AC | 68 ms
32,768 KB |
testcase_18 | AC | 62 ms
32,768 KB |
testcase_19 | AC | 69 ms
32,768 KB |
testcase_20 | AC | 371 ms
57,344 KB |
testcase_21 | AC | 204 ms
28,160 KB |
testcase_22 | AC | 38 ms
47,360 KB |
testcase_23 | AC | 489 ms
82,432 KB |
testcase_24 | AC | 319 ms
51,456 KB |
testcase_25 | AC | 401 ms
62,976 KB |
testcase_26 | AC | 69 ms
28,672 KB |
testcase_27 | AC | 30 ms
28,032 KB |
testcase_28 | AC | 71 ms
30,336 KB |
testcase_29 | AC | 516 ms
59,520 KB |
testcase_30 | AC | 380 ms
51,968 KB |
testcase_31 | AC | 634 ms
77,824 KB |
testcase_32 | AC | 716 ms
82,432 KB |
testcase_33 | AC | 616 ms
82,560 KB |
testcase_34 | AC | 711 ms
82,432 KB |
testcase_35 | AC | 625 ms
82,432 KB |
testcase_36 | AC | 625 ms
82,432 KB |
ソースコード
#include <iostream> #include <vector> #include <queue> using namespace std; struct Block { Block() : up(0), down(0),left(0),right(0) {} int up; int down; int left; int right; }; vector<int> paths[(1<<10) * (1<<10)]; int hops[(1<<10) * (1<<10)]; int visit[(1<<10) * (1<<10)]; int main(int argc, char* argv[]) { // Retrieve data int W,H,N; cin >> W >> H >> N; // Initialize the path for each block int nblocks = W * H; vector<Block> blocks(nblocks); for (int i = 0; i < N; i++) { int m; cin >> m; int prev = -1; for (int j = 0; j < m+1; j++) { int n; cin >> n; if (prev != -1) { int b = min(n, prev); int d = abs(n - prev); if (d < W) { blocks[b].right = max(blocks[b].right, d); } else { blocks[b].up = max(blocks[b].up, d/W); } } prev = n; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { int b = i * W + j; if (i) { blocks[b].up = max(blocks[b].up, blocks[b-W].up-1); } if (j) { blocks[b].right = max(blocks[b].right, blocks[b-1].right-1); } if (blocks[b].up && i < H-1) { paths[b].push_back(b+W); paths[b+W].push_back(b); } if (blocks[b].right && j < W-1) { paths[b].push_back(b+1); paths[b+1].push_back(b); } } } // Do BFS to search for a path for (int i = 0; i < nblocks; i++) { hops[i] = 1<<20; } hops[0] = 0; visit[0] = 1; queue<int> que; que.push(0); while (!que.empty()) { int current = que.front(); que.pop(); vector<int> path = paths[current]; for (int i = 0; i < path.size(); i++) { int p = path[i]; if (visit[p] == 0) { visit[p] = 1; hops[p] = hops[current] + 1; que.push(p); } } } if (visit[nblocks-1]) { cout << hops[nblocks-1] << endl; } else { cout << "Odekakedekinai.." << endl; } }