結果

問題 No.240 ナイト散歩
ユーザー tadanoningentadanoningen
提出日時 2020-09-30 12:49:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 78,468 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 19:43:45
合計ジャッジ時間 1,663 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<queue>
#define ll long long

using namespace std;
typedef pair<ll,ll> P;
const int dx[] = {-2,-2,-1,-1,1,1,2,2};
const int dy[] = {1,-1,2,-2,2,-2,1,-1};

int main(){
    ll x,y;
    cin >> x >> y;
    queue<P> que;
    queue<int> num;
    que.push(P(0,0));
    num.push(0);
    while(!que.empty()){
        P cur = que.front();que.pop();
        int cnt = num.front();num.pop();
        if(cur.first == x && cur.second == y){
            cout << "YES" << endl;
            return 0;
        }
        
        if(cnt >= 3) continue;
        
        for(int i=0;i < 8;i++){
            int nx = cur.first + dx[i];
            int ny = cur.second + dy[i];
            que.push(P(nx,ny));
            num.push(cnt+1);
        }
    }
    cout << "NO" << endl;
    return 0;
}
0