結果
問題 | No.240 ナイト散歩 |
ユーザー |
|
提出日時 | 2020-04-13 11:10:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 958 bytes |
コンパイル時間 | 1,023 ms |
コンパイル使用メモリ | 81,836 KB |
最終ジャッジ日時 | 2025-01-09 17:54:40 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <iostream>#include <vector>#include <queue>#include <tuple>const std::vector<int>dx{-2, -2, -1, -1, 1, 1, 2, 2},dy{-1, 1, -2, 2, -2, 2, -1, 1};void solve() {int gx, gy;std::cin >> gx >> gy;std::queue<std::pair<int, int>> que, nque;que.emplace(0, 0);for (int d = 0; d < 3; ++d) {while (!que.empty()) {int x, y;std::tie(x, y) = que.front();que.pop();for (int i = 0; i < 8; ++i) {int nx = x + dx[i],ny = y + dy[i];if (nx == gx && ny == gy) {std::cout << "YES" << std::endl;return;}nque.emplace(nx, ny);}}std::swap(que, nque);}std::cout << "NO" << std::endl;}int main() {std::cin.tie(nullptr);std::ios::sync_with_stdio(false);solve();return 0;}