結果

問題 No.240 ナイト散歩
ユーザー noriocnorioc
提出日時 2018-08-08 22:37:34
言語 D
(dmd 2.106.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 875 bytes
コンパイル時間 45 ms
コンパイル使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-27 02:35:49
合計ジャッジ時間 329 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.d(1): Error: unable to read module `all`
Main.d(1):        Expected 'std/experimental/all.d' or 'std/experimental/all/package.d' in one of the following import paths:
import path[0] = /opt/dmd/src/druntime/import/
import path[1] = /opt/dmd/src/phobos
import path[2] = /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd

ソースコード

diff #

import std.experimental.all;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

// return [[1, 2], [1, -2], [-1, 2], ...]
int[][] knightMoves() {
    int[][] moves;
    foreach (x, y; cartesianProduct([1, -1, 2, -2], [1, -1, 2, -2])) {
        if (abs(x) == abs(y)) continue;
        moves ~= [x, y];
    }
    return moves;
}

bool calc(int sx, int sy) {
    bool rec(int x, int y, int step) {
        if (x == sx && y == sy) return true;
        if (step == 3) return false;

        foreach (dxy; knightMoves()) {
            if (rec(x + dxy[0], y + dxy[1], step + 1))
                return true;
        }
        return false;
    }
    return rec(0, 0, 0);
}

void main() {
    auto xy = readints();
    int x = xy[0], y = xy[1];
    writeln(calc(x, y) ? "YES" : "NO");
}
0