結果

問題 No.240 ナイト散歩
ユーザー Ryu
提出日時 2018-01-17 16:49:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 92,072 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 06:46:57
合計ジャッジ時間 1,655 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 100000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

ll X, Y;

int main()
{
    cin >> X >> Y;
    queue<P> que;
    queue<int> num;
    que.push(P(0, 0));
    num.push(0);

    while (!que.empty())
    {
        P p = que.front();
        que.pop();
        int cnt = num.front();
        num.pop();
        if (cnt >= 3)
            continue;

        rep(i, 8)
        {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];

            if (nx == X && ny == Y)
            {
                cout << "YES" << endl;
                return 0;
            }

            que.push(P(nx, ny));
            num.push(cnt + 1);
        }
    }

    cout << "NO" << endl;
    return 0;
}
0