結果

問題 No.973 余興
ユーザー nebukuro09nebukuro09
提出日時 2020-01-17 22:28:25
言語 D
(dmd 2.107.1)
結果
MLE  
実行時間 -
コード長 2,687 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 105,728 KB
実行使用メモリ 693,212 KB
最終ジャッジ日時 2023-09-04 04:44:56
合計ジャッジ時間 12,012 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

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, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto X = s[1].to!long;
    auto A = readln.split.map!(to!long).array;

    auto B = new long[](N+1);
    foreach (i; 0..N) B[i+1] = B[i] + A[i];

    long sum(int l, int r) {
        if (r < l) return 0;
        return B[r+1] - B[l];
    }

    alias SegTree = SegmentTree!(int, (a,b)=>a+b, 0);
    auto rst = new SegTree[](N);
    auto cst = new SegTree[](N);
    foreach (i; 0..N) rst[i] = new SegTree(N);
    foreach (i; 0..N) cst[i] = new SegTree(N);

    int calc_left(int l, int r) {
        int hi = r + 1;
        int lo = l;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if (sum(l, mid) <= X) lo = mid;
            else hi = mid;
        }
        return lo;
    }

    int calc_right(int l, int r) {
        int hi = r;
        int lo = l - 1;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if (sum(mid, r) <= X) hi = mid;
            else lo = mid;
        }
        return hi;
    }

    foreach (len; 2..N+1) foreach (l; 0..N-len+1) {
        int r = l + len - 1;
        auto nr = calc_left(l, r) + 1;
        auto nl = calc_right(l, r) - 1;
        auto x = rst[l].query(l + 1, nr) != nr - l;
        auto y = cst[r].query(nl, r - 1) != r - nl;
        auto z = x | y;
        rst[l].add(r, 1);
        cst[r].add(l, 1);
    }

    writeln(rst[0].query(N-1, N-1) == 1 ? "A" : "B");
}

class SegmentTree(T, alias op, T e) {
    T[] table;
    int size;
    int offset;

    this(int n) {
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        fill(table, e);
        offset = size / 2;
    }

    void assign(int pos, T val) {
        pos += offset;
        table[pos] = val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    void add(int pos, T val) {
        pos += offset;
        table[pos] += val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    T query(int l, int r) {
        return query(l, r, 1, 0, offset-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) {
            return e;
        } else if (l <= a && b <= r) {
            return table[i];
        } else {
            return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }
}
0