結果

問題 No.240 ナイト散歩
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-07-10 23:18:42
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 778 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 51,156 KB
最終ジャッジ日時 2024-04-16 19:29:06
合計ジャッジ時間 801 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:8:1: error: ‘vector’ does not name a type
    8 | vector<int> dx = {-2, -2, -1, -1,  1, 1,  2, 2},
      | ^~~~~~
main.cpp:8:48: error: expected unqualified-id before ‘,’ token
    8 | vector<int> dx = {-2, -2, -1, -1,  1, 1,  2, 2},
      |                                                ^
main.cpp:9:16: error: expected constructor, destructor, or type conversion before ‘=’ token
    9 |             dy = {-1,  1, -2,  2, -2, 2, -1, 1};
      |                ^
main.cpp: In function ‘bool nya(int, int, int)’:
main.cpp:15:21: error: ‘dx’ was not declared in this scope; did you mean ‘x’?
   15 |   for(int i : range(dx.size())) {
      |                     ^~
      |                     x
main.cpp:18:20: error: ‘ny’ was not declared in this scope; did you mean ‘nx’?
   18 |     res |= nya(nx, ny, times-1);
      |                    ^~
      |                    nx
main.cpp: In function ‘int main()’:
main.cpp:24:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |   int x, y; scanf("%d%d", &x, &y);
      |             ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
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;}};

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) {
  if(times < 0) { return false; }
  if(x == 0 && y == 0) { return true; }
  bool res = false;
  for(int i : range(dx.size())) {
    int nx = x + dx[i],
        ny = y + dy[i];
    res |= nya(nx, ny, times-1);
  }
  return res;
}

int main(void) {
  int x, y; scanf("%d%d", &x, &y);
  puts(nya(x, y, 3) ? "YES" : "NO");
  return 0;
}
0