結果

問題 No.240 ナイト散歩
ユーザー ferin
提出日時 2017-03-01 03:40:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 167,568 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-07 21:35:15
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<25)     //33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}, dy[] = {-1, 1, -2, 2, -2, 2, -1, 1};
signed main(void)
{
  ll x, y;
  cin >> x >> y;

  int d[31][31];
  REP(i, 31) REP(j, 31) d[i][j] = INF;
  queue<VI> que;
  que.push({0, 0, 0});
  d[0][0] = 0;

  while(que.size()) {
    VI p = que.front(); que.pop();
    if(p[2] == 3) continue;
    REP(i, 8) {
      int nx = p[0]+dx[i], ny = p[1]+dy[i];
      if(d[ny+15][nx+15] == INF) {
        que.push({ny, nx, p[2]+1});
        d[ny+15][nx+15] = p[2];
      }
    }
  }
  if(abs(x)<=15 && abs(y)<=15 && d[y+15][x+15] != INF) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}
0