結果

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

Tuple!(int, int)[] knightMoves() {
    auto signs = cartesianProduct([1, -1], [1, -1]);
    Tuple!(int, int)[] moves;
    foreach (xy, sx, sy; cartesianProduct([[1, 2], [2, 1]], signs)) {
        moves ~= tuple(xy[0] * sx, xy[1] * sy);
    }
    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