結果
| 問題 |
No.240 ナイト散歩
|
| コンテスト | |
| ユーザー |
hadrori
|
| 提出日時 | 2015-07-26 22:44:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 761 bytes |
| コンパイル時間 | 1,556 ms |
| コンパイル使用メモリ | 164,172 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-07 21:00:22 |
| 合計ジャッジ時間 | 2,132 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘void input()’:
main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repi(i,0,n)
const int di[] = {-1,1,-2,2,-2,2,-1,1}, dj[] = {-2,-2,-1,-1,1,1,2,2};
int x, y;
int solve() {
queue<pair<int,pair<int,int>>> q;
q.push(make_pair(0,make_pair(0,0)));
while(!q.empty()) {
int d = q.front().first;
int i = q.front().second.first, j = q.front().second.second;
q.pop();
if(y == i and j == x) return 1;
if(d == 3) continue;
for (int k = 0; k < 8; k++)
q.push(make_pair(d+1, make_pair(i+di[k], j+dj[k])));
}
return 0;
}
void input() {
scanf("%d%d", &x, &y);
}
int main() {
input();
puts(solve()? "YES": "NO");
return 0;
}
hadrori