結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 29 ms
5,596 KB
testcase_19 WA -
testcase_20 AC 24 ms
6,348 KB
testcase_21 AC 19 ms
5,624 KB
testcase_22 WA -
testcase_23 AC 24 ms
6,132 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;

immutable long inf = 10^^9 + 7;
alias Edge = Tuple!(int, "to", long, "flow", long, "cap", int, "rev");

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

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

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

    d.sort();

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

    foreach (i ; 0 .. n) {
        int r = L - d[i];
        auto ub = d.assumeSorted.lowerBound(r + 1);

        debug {
            writeln(ub);
        }

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

    writeln(-1);
}

long Dinic(Edge[][] adj, int s, int t) {
    int n = adj.length.to!int;
    int[] level = new int[](n);
    int[] prog = new int[](n);
    auto q = Queue!(int)(n);

    bool bfs() {
        level[] = -1;
        level[s] = 0;
        q.clear();
        q.push(s);

        while (!q.empty) {
            auto u = q.front;
            q.pop;

            foreach (e ; adj[u]) {
                if (level[e.to] == -1 && e.cap - e.flow > 0) {
                    level[e.to] = level[u] + 1;
                    q.push(e.to);
                }
            }
        }

        return level[t] != -1;
    }

    long dfs(int u, long f) {
        if (u == t) return f;

        for (; prog[u] < adj[u].length; prog[u]++) {
            auto e = &adj[u][prog[u]];

            if (level[u] + 1 == level[e.to] && e.flow < e.cap) {
                long d = dfs(e.to, min(f, e.cap - e.flow));

                if (d > 0) {
                    e.flow += d;
                    adj[e.to][e.rev].flow -= d;
                    return d;
                }
            }
        }

        return 0;
    }

    long F;

    while (bfs()) {
        prog[] = 0;

        while (true) {
            auto df = dfs(s, inf);

            if (df) F += df;
            else break;
        }
    }

    return F;
}


struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this (int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head++;
        head %= N;
    }

    void clear() {
        head = tail = 0;
    }
}


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