結果

問題 No.240 ナイト散歩
ユーザー tokizo
提出日時 2019-02-02 19:35:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 165,064 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 20:36:10
合計ジャッジ時間 2,734 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int x, y;

int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};
int dy[8] = {-1, 1, -2, 2, -2, 2, -1, 1};

bool dfs(int a, int b, int cnt){
    if(a == x and b == y) return true;
    if(cnt == 3) return false;
    for(int i = 0; i < 8; i++){
        int nx, ny;
        nx = dx[i] + a;
        ny = dy[i] + b;
        if(dfs(nx, ny, cnt + 1)) return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> x >> y;
    
    if(dfs(0, 0, 0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl; 
    }

    return 0;
}
0