結果
問題 |
No.240 ナイト散歩
|
ユーザー |
|
提出日時 | 2015-07-11 18:32:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 984 bytes |
コンパイル時間 | 777 ms |
コンパイル使用メモリ | 68,824 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-07 20:54:36 |
合計ジャッジ時間 | 1,413 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:31:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | int x, y; scanf("%d%d", &x, &y); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <queue> using namespace std; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n; public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}}; struct Point { int x, y, c; }; vector<int> dx = {2, 2, 1, 1, -1, -1, -2, -2}, dy = {1, -1, 2, -2, 2, -2, 1, -1}; bool nya(int x, int y, int times) { queue<Point> que; que.push(Point({x, y, times})); while(!que.empty()) { Point cur = que.front(); que.pop(); if(cur.c < 0) { continue; } if(cur.x == 0 && cur.y == 0) { return true; } for(int i : range(dx.size())) { int nx = cur.x + dx[i], ny = cur.y + dy[i], nc = cur.c - 1; que.push(Point({nx, ny, nc})); } } return false; } int main(void) { int x, y; scanf("%d%d", &x, &y); puts(nya(x, y, 3) ? "YES" : "NO"); return 0; }