結果

問題 No.240 ナイト散歩
ユーザー eve__fuyuki
提出日時 2018-03-13 23:48:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 64,136 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 08:51:56
合計ジャッジ時間 1,730 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
struct point{
    int x;
    int y;
    int d;
};
    int dx[8] = {-2,-2,-1,-1,1,1,2,2};
    int dy[8] = {-1,1,-2,2,-2,2,-1,1};
int main(){
    int X,Y;
    point p,p1;
    queue<point> que;
    cin >> X >> Y;
    p.x = 0;
    p.y = 0;
    p.d = 0;
    que.push(p);
    while(1){
        p = que.front();
        que.pop();
        if(p.d == 3) break;
        for(int i=0;i<8;i++){
            if(p.x +dx[i] == X && p.y + dy[i] == Y){
                cout << "YES" << endl;
                return 0;
            }
            p1.x = p.x + dx[i];
            p1.y = p.y + dy[i];
            p1.d = p.d + 1;
            que.push(p1);
        }
    }
    cout << "NO" << endl;
    return 0;
}
0