結果

問題 No.602 隠されていたゲーム2
ユーザー nanaenanae
提出日時 2017-12-02 00:21:08
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,257 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 103,364 KB
実行使用メモリ 6,608 KB
最終ジャッジ日時 2023-09-03 17:09:06
合計ジャッジ時間 2,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 33 ms
6,024 KB
testcase_19 AC 41 ms
6,192 KB
testcase_20 AC 40 ms
6,608 KB
testcase_21 AC 26 ms
6,516 KB
testcase_22 WA -
testcase_23 AC 30 ms
6,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    scan(n);
    auto d = readln.split.to!(int[]);
    int x, y;
    scan(x, y);

    long L = abs(x) + abs(y);

    if (L == 0) {
        writeln(0);
        return;
    }

    d.sort();

    foreach (i ; 0 .. n) {
        if (d[i] == L) {
            writeln(1);
            return;
        }
    }

    auto ds = (d.map!(a => -a).retro().array ~ d).assumeSorted();

    debug {
        writeln(ds);
    }

    foreach (i ; 0 .. 2*n) {
        long r = L - ds[i];
        auto lb = ds.lowerBound(r + 1);

        debug {
            writeln(lb);
        }

        if (!lb.empty && lb.back == r) {
            writeln(2);
            return;
        }
    }

    writeln(-1);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0