結果
問題 | No.340 雪の足跡 |
ユーザー | ckawatak |
提出日時 | 2017-10-28 16:12:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 628 ms / 1,000 ms |
コード長 | 2,352 bytes |
コンパイル時間 | 1,284 ms |
コンパイル使用メモリ | 80,036 KB |
実行使用メモリ | 82,560 KB |
最終ジャッジ日時 | 2024-05-01 20:58:40 |
合計ジャッジ時間 | 10,493 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
28,032 KB |
testcase_01 | AC | 9 ms
28,032 KB |
testcase_02 | AC | 9 ms
28,160 KB |
testcase_03 | AC | 8 ms
28,160 KB |
testcase_04 | AC | 8 ms
28,032 KB |
testcase_05 | AC | 8 ms
28,032 KB |
testcase_06 | AC | 9 ms
28,160 KB |
testcase_07 | AC | 8 ms
28,032 KB |
testcase_08 | AC | 8 ms
28,160 KB |
testcase_09 | AC | 8 ms
28,160 KB |
testcase_10 | AC | 9 ms
28,032 KB |
testcase_11 | AC | 10 ms
28,288 KB |
testcase_12 | AC | 9 ms
28,288 KB |
testcase_13 | AC | 12 ms
28,288 KB |
testcase_14 | AC | 39 ms
32,000 KB |
testcase_15 | AC | 43 ms
32,000 KB |
testcase_16 | AC | 34 ms
29,696 KB |
testcase_17 | AC | 55 ms
32,768 KB |
testcase_18 | AC | 50 ms
32,896 KB |
testcase_19 | AC | 54 ms
32,768 KB |
testcase_20 | AC | 333 ms
57,344 KB |
testcase_21 | AC | 178 ms
28,160 KB |
testcase_22 | AC | 20 ms
47,488 KB |
testcase_23 | AC | 434 ms
82,432 KB |
testcase_24 | AC | 279 ms
51,584 KB |
testcase_25 | AC | 364 ms
62,976 KB |
testcase_26 | AC | 60 ms
28,672 KB |
testcase_27 | AC | 19 ms
28,160 KB |
testcase_28 | AC | 60 ms
30,464 KB |
testcase_29 | AC | 460 ms
59,648 KB |
testcase_30 | AC | 319 ms
51,968 KB |
testcase_31 | AC | 573 ms
77,952 KB |
testcase_32 | AC | 627 ms
82,432 KB |
testcase_33 | AC | 549 ms
82,432 KB |
testcase_34 | AC | 628 ms
82,560 KB |
testcase_35 | AC | 565 ms
82,560 KB |
testcase_36 | AC | 577 ms
82,560 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; } }