結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー nebukuro09nebukuro09
提出日時 2017-11-09 02:43:36
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,289 ms / 4,000 ms
コード長 2,243 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 189,124 KB
実行使用メモリ 38,812 KB
最終ジャッジ日時 2023-09-03 16:43:02
合計ジャッジ時間 11,439 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 6 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 1,213 ms
38,336 KB
testcase_30 AC 1,090 ms
38,812 KB
testcase_31 AC 972 ms
20,040 KB
testcase_32 AC 796 ms
38,036 KB
testcase_33 AC 608 ms
14,704 KB
testcase_34 AC 491 ms
13,900 KB
testcase_35 AC 1,281 ms
38,060 KB
testcase_36 AC 1,289 ms
38,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto W = s[1].to!int;
    auto H = s[2].to!long;

    auto A = new int[](N);
    auto B = new long[](N);
    auto X = new int[](N);

    foreach (i; 0..N) {
        s = readln.split;
        A[i] = s[0].to!int;
        B[i] = s[1].to!long;
        X[i] = s[2].to!int - 1;
    }


    auto ans = new int[](W);
    auto rbt = new RedBlackTree!(Tuple!(int, int, int, int), "a[3] < b[3]", true)();

    foreach (i; 0..W)
        rbt.insert(tuple(i, -1, N-1, (N-2)/2));


    for (int settled = 0; settled < W; ) {
        BIT height = new BIT(W+10);

        foreach (i; 0..N) {
            height.add(X[i], X[i]+A[i], B[i]);
            auto nodes = rbt.equalRange(tuple(0, 0, 0, i)).array;

            foreach (node; nodes) {
                auto col = node[0];
                auto lo = node[1];
                auto hi = node[2];
                rbt.removeKey(node);

                if (hi - lo <= 1) {
                    settled += 1;
                    ans[col] = hi % 2 ? -1 : 1;
                } else {
                    if (height.sum(col) >= H) hi = (hi + lo) / 2;
                    else lo = (hi + lo) / 2;
                    rbt.insert(tuple(col, lo, hi, (hi+lo)/2));
                }
            }
        }
    }

    if (ans.sum > 0) writeln("A");
    else if (ans.sum == 0) writeln("DRAW");
    else writeln("B");
}


class BIT{
    int n;
    long[] table;

    this(int n){
        this.n = n;
        table = new long[](n+1);
    }

    void add(int i, long x){
        i++;
        while (i <= n){
            table[i] += x;
            i += i & -i;
        }
    }

    // [l, r)
    void add(int l, int r, long x) {
        add(l, x);
        add(r, -x);
    }

    // [0, i]
    long sum(int i){
        i++;
        long ret = 0;
        while (i > 0){
            ret += table[i];
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    long sum(int l, int r){
        if (l >= r) return 0;
        return sum(r-1) - sum(l-1);
    }
}
0