結果
問題 | No.367 ナイトの転身 |
ユーザー | satanic |
提出日時 | 2016-04-29 23:28:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,981 bytes |
コンパイル時間 | 807 ms |
コンパイル使用メモリ | 88,044 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2024-10-04 19:05:01 |
合計ジャッジ時間 | 1,633 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 1 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 16 ms
8,320 KB |
testcase_11 | AC | 21 ms
8,320 KB |
testcase_12 | AC | 5 ms
6,820 KB |
testcase_13 | AC | 5 ms
6,820 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 9 ms
6,816 KB |
testcase_17 | AC | 2 ms
6,816 KB |
testcase_18 | AC | 3 ms
6,816 KB |
testcase_19 | AC | 3 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 4 ms
6,816 KB |
testcase_22 | AC | 2 ms
6,816 KB |
testcase_23 | AC | 1 ms
6,816 KB |
testcase_24 | AC | 1 ms
6,820 KB |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 1 ms
6,816 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:90:26: warning: 'gx' may be used uninitialized [-Wmaybe-uninitialized] 90 | std::cout << P[gy][gx].depth << "\n"; | ^ main.cpp:27:13: note: 'gx' was declared here 27 | int gy, gx; | ^~ main.cpp:90:22: warning: 'gy' may be used uninitialized [-Wmaybe-uninitialized] 90 | std::cout << P[gy][gx].depth << "\n"; | ^ main.cpp:27:9: note: 'gy' was declared here 27 | int gy, gx; | ^~ main.cpp:54:13: warning: 'sx' may be used uninitialized [-Wmaybe-uninitialized] 54 | P[sy][sx].visitedN=true; | ^ main.cpp:26:13: note: 'sx' was declared here 26 | int sy, sx; | ^~ main.cpp:54:9: warning: 'sy' may be used uninitialized [-Wmaybe-uninitialized] 54 | P[sy][sx].visitedN=true; | ^ main.cpp:26:9: note: 'sy' was declared here 26 | int sy, sx; | ^~
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <iomanip> #define SHOWVECTOR2 {std::cout << "----" << "\n";for(auto i : P){for(auto j : i){std::cout << std::setw(2) << j.depth << " ";}std::cout << "\n";}} using ll = long long int; typedef struct{ int y, x; bool visitedN, visitedB; bool isRed; int depth; bool thenN; }Pos; int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int h, w; std::cin >> h >> w; std::vector<std::vector<Pos>> P(h, std::vector<Pos>(w)); int sy, sx; int gy, gx; #define INIT(b) {P[i][j].y=i; P[i][j].x=j; P[i][j].visitedN=false; P[i][j].visitedB=false; P[i][j].isRed=(b); P[i][j].depth=-1; P[i][j].thenN=true;} for(int i=0; i<h; ++i){ for(int j=0; j<w; ++j){ char input; std::cin >> input; switch(input){ case 'S': sy=i; sx=j; INIT(false); break; case 'G': gy=i; gx=j; INIT(false); break; case '.': INIT(false); break; case 'R': INIT(true); break; } } } #undef INIT std::queue<Pos> search; P[sy][sx].visitedN=true; P[sy][sx].depth=0; search.push(P[sy][sx]); std::vector<int> moveN({-1, -2, -2, -1, -2, 1, -1, 2, 1, 2, 2, 1, 2, -1, 1, -2}); std::vector<int> moveB({-1, -1, -1, 1, 1, 1, 1, -1}); while(!search.empty() && P[gy][gx].depth==-1){ Pos& now = search.front(); search.pop(); if(now.thenN){ for(int i=0; i<8; ++i){ int searchY = now.y+moveN[i*2]; int searchX = now.x+moveN[i*2+1]; if(searchY>=0 && searchY<h && searchX>=0 && searchX<w && !P[searchY][searchX].visitedN){ P[searchY][searchX].visitedN=true; P[searchY][searchX].depth=now.depth+1; if(P[searchY][searchX].isRed){ P[searchY][searchX].thenN=false; } search.push(P[searchY][searchX]); } } }else{ for(int i=0; i<4; ++i){ int searchY = now.y+moveB[i*2]; int searchX = now.x+moveB[i*2+1]; if(searchY>=0 && searchY<h && searchX>=0 && searchX<w && !P[searchY][searchX].visitedB){ P[searchY][searchX].visitedB=true; P[searchY][searchX].depth=now.depth+1; if(P[searchY][searchX].isRed){ P[searchY][searchX].thenN=true; } search.push(P[searchY][searchX]); } } } //SHOWVECTOR2; } std::cout << P[gy][gx].depth << "\n"; return 0; }