結果
問題 |
No.367 ナイトの転身
|
ユーザー |
|
提出日時 | 2016-04-30 00:17:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,974 bytes |
コンパイル時間 | 972 ms |
コンパイル使用メモリ | 88,208 KB |
実行使用メモリ | 8,448 KB |
最終ジャッジ日時 | 2024-10-04 23:25:11 |
合計ジャッジ時間 | 1,582 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 WA * 2 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:93:26: warning: 'gx' may be used uninitialized [-Wmaybe-uninitialized] 93 | std::cout << P[gy][gx].depth << "\n"; | ^ main.cpp:27:13: note: 'gx' was declared here 27 | int gy, gx; | ^~ main.cpp:93:22: warning: 'gy' may be used uninitialized [-Wmaybe-uninitialized] 93 | 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=!(b);} 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].thenN=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){ Pos& check = P[searchY][searchX]; check.visitedN=true; check.depth=now.depth+1; if(check.isRed){ check.thenN=false; } search.push(check); } } }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){ Pos& check = P[searchY][searchX]; check.visitedB=true; check.depth=now.depth+1; if(check.isRed){ check.thenN=true; } search.push(check); } } } //SHOWVECTOR2; } std::cout << P[gy][gx].depth << "\n"; return 0; }