結果

問題 No.973 余興
ユーザー nebukuro09nebukuro09
提出日時 2020-01-17 22:50:23
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,376 ms / 4,000 ms
コード長 1,518 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 105,136 KB
実行使用メモリ 44,652 KB
最終ジャッジ日時 2023-09-04 04:49:31
合計ジャッジ時間 42,578 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,364 ms
43,436 KB
testcase_01 AC 1,371 ms
44,652 KB
testcase_02 AC 1,363 ms
43,708 KB
testcase_03 AC 1,368 ms
44,104 KB
testcase_04 AC 1,371 ms
43,672 KB
testcase_05 AC 1,368 ms
43,436 KB
testcase_06 AC 1,370 ms
44,092 KB
testcase_07 AC 1,372 ms
43,928 KB
testcase_08 AC 1,370 ms
43,140 KB
testcase_09 AC 1,376 ms
44,648 KB
testcase_10 AC 1,312 ms
42,384 KB
testcase_11 AC 366 ms
14,932 KB
testcase_12 AC 369 ms
14,944 KB
testcase_13 AC 365 ms
14,672 KB
testcase_14 AC 365 ms
14,636 KB
testcase_15 AC 47 ms
4,380 KB
testcase_16 AC 48 ms
4,380 KB
testcase_17 AC 29 ms
4,380 KB
testcase_18 AC 38 ms
4,380 KB
testcase_19 AC 38 ms
4,380 KB
testcase_20 AC 28 ms
4,384 KB
testcase_21 AC 46 ms
4,376 KB
testcase_22 AC 47 ms
4,380 KB
testcase_23 AC 38 ms
4,380 KB
testcase_24 AC 37 ms
4,376 KB
testcase_25 AC 17 ms
4,380 KB
testcase_26 AC 28 ms
4,376 KB
testcase_27 AC 56 ms
4,384 KB
testcase_28 AC 38 ms
4,380 KB
testcase_29 AC 36 ms
4,376 KB
testcase_30 AC 1,081 ms
43,160 KB
testcase_31 AC 1,081 ms
43,616 KB
testcase_32 AC 1,078 ms
43,180 KB
testcase_33 AC 1,083 ms
43,136 KB
testcase_34 AC 1,077 ms
43,364 KB
testcase_35 AC 1,085 ms
43,176 KB
testcase_36 AC 1,050 ms
43,212 KB
testcase_37 AC 1,051 ms
42,340 KB
testcase_38 AC 1,083 ms
43,472 KB
testcase_39 AC 1,082 ms
44,192 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1,106 ms
43,436 KB
testcase_47 AC 1,099 ms
43,432 KB
testcase_48 AC 1,103 ms
43,140 KB
testcase_49 AC 1,016 ms
42,096 KB
testcase_50 AC 1,091 ms
43,164 KB
testcase_51 AC 1,107 ms
43,120 KB
testcase_52 AC 1,116 ms
43,432 KB
testcase_53 AC 1,088 ms
42,896 KB
testcase_54 AC 1,109 ms
43,436 KB
testcase_55 AC 1,109 ms
43,172 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, 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];
    }

    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;
    }

    auto ans = new bool[][](N, N);
    auto minr = new int[](N);
    auto maxl = new int[](N);
    foreach (i; 0..N) minr[i] = maxl[i] = i;

    foreach (len; 2..N+1) foreach (l; 0..N-len+1) {
        int r = l + len - 1;
        int nr = calc_right(l, r) - 1;
        int nl = calc_left(l, r) + 1;
        if (nr <= minr[l] || nl >= maxl[r]) {
            ans[l][r] = true;
        } else {
            minr[l] = r;
            maxl[r] = l;
        }
    }

    writeln(ans[0][N-1] ? "A" : "B");
}
0