結果

問題 No.240 ナイト散歩
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-04-26 20:50:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,860 bytes
コンパイル時間 2,095 ms
コンパイル使用メモリ 81,884 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-16 12:02:16
合計ジャッジ時間 4,191 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,388 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;

struct C {
    int x, y;
};

int main() {
    int X, Y;
    cin >> X >> Y;
    const int N = 3; //進める回数
    const int dx[] = {-2,-2,-1,-1, 1, 1, 2, 2};
    const int dy[] = {-1, 1,-2, 2,-2, 2,-1, 1};
    vector<vector<bool>> visited(4 * N + 1, vector<bool>(4 * N + 1, false)); //通った座標の記録
    queue<pair<C, int>> q;
    q.push(pair<C, int>(C{0,0}, 0));
    while (!q.empty()) {
        pair<C, int> p = q.front(); q.pop();
        if (visited[p.first.x + 2 * N][p.first.y + 2 * N]) continue;
        visited[p.first.x + 2 * N][p.first.y + 2 * N] = true;
        if (p.second < N) {
            for (int i = 0; i < 8; i++)
            {
                q.push(pair<C, int>(C{p.first.x + dx[i], p.first.y + dy[i]}, p.second + 1));
            }
        }
    }
    if (X >= -2 * N && Y >= -2 * N && X <= 2 * N && Y <= 2 * N && visited[X + 2 * N][Y + 2 * N]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    // 試しに表示してみる
    /*
    for (int i = -2 * N; i <= 2 * N; i++)
    {
        for (int j = -2 * N; j <= 2 * N; j++)
        {
            if (i == 0 && j == 0) {
                cout << "%";
            }
            else if (visited[i+2 * N][j+2 * N]) {
                cout << "#";
            }
            else {
                cout << ".";
            }
        }
        cout << endl;
    }
    */
    getchar(); getchar();
    return 0;
}
0