結果

問題 No.240 ナイト散歩
ユーザー kurokuro
提出日時 2021-04-30 14:50:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 165,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 15:17:19
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

struct Vec2D {
  Vec2D(uint64_t _x, uint64_t _y) : x(_x), y(_y) {}
  uint64_t x;
  uint64_t y;
};

bool check(const Vec2D pos, const Vec2D targ) {
  if (pos.x == targ.x && pos.y == targ.y) {
    return true;
  } else {
    return false;
  }
}

int main() {
  uint64_t X, Y;
  cin >> X >> Y;

  Vec2D moveList[8] = {Vec2D(-2, -1), Vec2D(-2, 1), Vec2D(-1, -2), Vec2D(-1, 2),
                       Vec2D(1, -2),  Vec2D(1, 2),  Vec2D(2, -1),  Vec2D(2, 1)};
  if (X == 0 && Y == 0) {
    cout << "YES" << endl;
    return 0;
  }

  const Vec2D targ(X, Y);

  for (int i = 0; i < 8; ++i) {
    Vec2D p0 = moveList[i];
    if (check(p0, targ)) {
      cout << "YES" << endl;
      return 0;
    }

    for (int j = 0; j < 8; ++j) {
      Vec2D p1 = p0;
      p1.x += moveList[j].x;
      p1.y += moveList[j].y;
      if (check(p1, targ)) {
        cout << "YES" << endl;
        return 0;
      }

      for (int k = 0; k < 8; ++k) {
        Vec2D p2 = p1;
        p2.x += moveList[k].x;
        p2.y += moveList[k].y;
        if (check(p2, targ)) {
          cout << "YES" << endl;
          return 0;
        }
      }
    }
  }

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