結果
| 問題 |
No.240 ナイト散歩
|
| コンテスト | |
| ユーザー |
forest3
|
| 提出日時 | 2025-03-27 15:08:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 728 bytes |
| コンパイル時間 | 1,915 ms |
| コンパイル使用メモリ | 175,156 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2025-03-27 15:08:05 |
| 合計ジャッジ時間 | 3,474 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
int main() {
ll x, y;
cin >> x >> y;
vector<int> dy{-1, 1, -2, 2, -2, 2, -1, 1}, dx{-2, -2, -1, -1, 1, 1, 2, 2};
using P = pair<int, int>;
using PP = pair<P, int>;
queue<PP> q;
q.push(PP(P(0, 0), 0));
set<P> st;
st.insert(P(0, 0));
while(q.size()) {
int i, j, d;
P p;
tie(p, d) = q.front();
q.pop();
tie(i, j) = p;
if(i == x && j == y) {
cout << "YES" << endl;
return 0;
}
if(d == 3) continue;
rep(k, 8) {
int nx = i + dx[k];
int ny = j + dy[k];
if(st.count(P(nx, ny))) continue;
st.insert(P(nx, ny));
q.push(PP(P(nx, ny), d + 1));
}
}
cout << "NO" << endl;
}
forest3