結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2020-06-26 14:43:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,510 bytes |
コンパイル時間 | 1,705 ms |
コンパイル使用メモリ | 188,984 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-03 23:55:17 |
合計ジャッジ時間 | 2,756 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)#define all(x) (x).begin(), (x).end()#define rall(x) (x).rbegin(), (x).rend()#define sz(x) ((ll)(x).size())#define len(x) ((ll)(x).length())#define endl "\n"int main() {cin.tie(0);ios::sync_with_stdio(false);// ifstream in("input.txt");// cin.rdbuf(in.rdbuf());const ll d[8][2] = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {1, -2}, {1, 2}, {2, -1}, {2, 1}};ll x, y;cin >> x >> y;if ((x == 0) && (y == 0)) {cout << "YES" << endl;return 0;}if ((abs(x) + abs(y)) > 9) {cout << "NO" << endl;return 0;}map<ll, map<ll, ll>> dist;queue<pair<ll, ll>> q;q.push(make_pair(0, 0));dist[0][0] = 0;while(!q.empty()) {auto p = q.front(); q.pop();ll cx = p.first, cy = p.second;rep(i, 8) {ll nx = cx + d[i][0];ll ny = cy + d[i][1];if ((dist[nx][ny] != 0) && (dist[nx][ny] <= (dist[cx][cy] + 1))) continue;if ((dist[cx][cy] + 1) > 3) continue;dist[nx][ny] = dist[cx][cy] + 1;q.push(make_pair(nx, ny));}}cout << ((dist[x][y] != 0) ? "YES" : "NO") << endl;return 0;}