結果
問題 | No.340 雪の足跡 |
ユーザー | ckawatak |
提出日時 | 2017-10-26 15:35:39 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,910 bytes |
コンパイル時間 | 907 ms |
コンパイル使用メモリ | 86,668 KB |
実行使用メモリ | 32,388 KB |
最終ジャッジ日時 | 2024-11-21 20:04:08 |
合計ジャッジ時間 | 21,705 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 2 ms
28,032 KB |
testcase_02 | AC | 2 ms
10,496 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 4 ms
5,248 KB |
testcase_12 | AC | 3 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 25 ms
5,248 KB |
testcase_15 | AC | 33 ms
5,248 KB |
testcase_16 | AC | 23 ms
5,248 KB |
testcase_17 | AC | 45 ms
5,632 KB |
testcase_18 | AC | 34 ms
5,248 KB |
testcase_19 | AC | 44 ms
5,760 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 7 ms
18,816 KB |
testcase_23 | AC | 823 ms
26,752 KB |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | AC | 64 ms
5,248 KB |
testcase_27 | AC | 12 ms
5,248 KB |
testcase_28 | AC | 57 ms
5,248 KB |
testcase_29 | AC | 927 ms
18,380 KB |
testcase_30 | AC | 440 ms
15,104 KB |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
ソースコード
#include <iostream> #include <vector> #include <queue> using namespace std; struct Block { Block() : top(-1), bottom(-1),left(-1),right(-1) {} int top; int bottom; int left; int right; }; int hop[(1<<10) * (1<<10)]; int main(int argc, char* argv[]) { // Retrieve data int W,H,N; cin >> W >> H >> N; vector<vector<int> > paths(N); for (int i = 0; i < N; i++) { int m; cin >> m; for (int j = 0; j < m+1; j++) { int b; cin >> b; paths[i].push_back(b); } } // Initialize the path for each block int nblocks = W * H; vector<Block> blocks(nblocks); for (int i = 0; i < N; i++) { vector<int> path = paths[i]; int size = path.size(); for (int j = 0; j < size-1; j++) { int start = path[j]; int end = path[j+1]; if (end < start) { int temp = start; start = end; end = temp; } // the starting point and the ending point are in the same row if (start/W == end/W) { for (int k = start; k <= end; k++) { if (k == start) { blocks[k].right = k+1; } else if (k == end) { blocks[k].left = k-1; } else { blocks[k].left = k-1; blocks[k].right = k+1; } } } // the starting point and the ending point are NOT in the same row else { for (int k = start; k <= end; k+=W) { if (k == start) { blocks[k].top = k+W; } else if (k == end) { blocks[k].bottom = k-W; } else { blocks[k].bottom = k-W; blocks[k].top = k+W; } } } } } // Do BFS to search for a path hop[0] = 1; queue<int> que; que.push(0); int solution = -1; while (!que.empty()) { int current = que.front(); que.pop(); if (current == nblocks-1) { break; } Block block = blocks[current]; int directions[] = {block.top, block.bottom, block.left, block.right}; for (int i = 0; i < sizeof(directions)/sizeof(int); i++) { if (directions[i] != -1 && hop[directions[i]] == 0) { que.push(directions[i]); hop[directions[i]] = hop[current] + 1; } } } solution = hop[nblocks-1]; if (solution == 0) { cout << "Odekakedekinai.." << endl; } else { cout << solution-1 << endl; } }