結果

問題 No.367 ナイトの転身
ユーザー satanicsatanic
提出日時 2016-04-30 00:12:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,948 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 87,888 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-04-15 07:48:27
合計ジャッジ時間 1,747 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 20 ms
8,320 KB
testcase_11 AC 24 ms
8,576 KB
testcase_12 AC 6 ms
6,940 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
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;
      |         ^~
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:92:22: warning: 'gy' may be used uninitialized [-Wmaybe-uninitialized]
   92 |     std::cout << P[gy][gx].depth << "\n";
      |                      ^
main.cpp:27:9: note: 'gy' was declared here
   27 |     int gy, gx;
      |         ^~
main.cpp:92:26: warning: 'gx' may be used uninitialized [-Wmaybe-uninitialized]
   92 |     std::cout << P[gy][gx].depth << "\n";
      |                          ^
main.cpp:27:13: note: 'gx' was declared here
   27 |     int gy, gx;
      |             ^~

ソースコード

diff #

#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){
                    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;
}
0