結果

問題 No.911 ラッキーソート
ユーザー nebukuro09nebukuro09
提出日時 2019-10-18 23:27:49
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 803 ms / 2,000 ms
コード長 2,047 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 117,544 KB
実行使用メモリ 19,992 KB
最終ジャッジ日時 2023-09-04 03:08:53
合計ジャッジ時間 15,237 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 496 ms
17,352 KB
testcase_14 AC 521 ms
17,428 KB
testcase_15 AC 533 ms
17,364 KB
testcase_16 AC 595 ms
19,992 KB
testcase_17 AC 578 ms
18,964 KB
testcase_18 AC 612 ms
19,804 KB
testcase_19 AC 628 ms
17,824 KB
testcase_20 AC 655 ms
19,008 KB
testcase_21 AC 670 ms
19,344 KB
testcase_22 AC 672 ms
19,344 KB
testcase_23 AC 803 ms
19,224 KB
testcase_24 AC 719 ms
18,940 KB
testcase_25 AC 363 ms
12,248 KB
testcase_26 AC 422 ms
11,048 KB
testcase_27 AC 177 ms
6,928 KB
testcase_28 AC 87 ms
5,688 KB
testcase_29 AC 21 ms
4,376 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 506 ms
17,272 KB
testcase_39 AC 720 ms
18,668 KB
testcase_40 AC 17 ms
4,376 KB
testcase_41 AC 598 ms
17,760 KB
testcase_42 AC 477 ms
14,860 KB
testcase_43 AC 503 ms
17,272 KB
testcase_44 AC 74 ms
14,408 KB
testcase_45 AC 74 ms
14,664 KB
testcase_46 AC 75 ms
14,644 KB
testcase_47 AC 107 ms
15,828 KB
testcase_48 AC 69 ms
14,664 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.string, core.stdc.stdlib;

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

    immutable int M = 61;
    auto possible = new int[][](M+1);

    void rec(int l, int r, int keta, int si) {
        if (keta < 0) return;
        if (r - l == 1) {
            possible[si-1] ~= 2;
            return;
        }
        auto B = A[l..r].map!(a => (a & (1L << keta)) > 0).array;
        auto x = B.uniq.array.length;
        if (x > 2) {
            writeln(0);
            exit(0);
        } else if (x == 2) {
            possible[si-1] ~= B.front;
            int cut = B.countUntil(!B.front).to!int;
            rec(l, l+cut, keta-1, si+1);
            rec(l+cut, r, keta-1, si+1);
        } else {
            possible[si-1] ~= 2;
            rec(l, r, keta-1, si+1);
        }
    }

    rec(0, N, M-1, 1);

    long solve(long ub) {
        auto dp = new long[][](M+1, 2);
        dp[0][0] = 1;

        foreach (i; 0..M) {
            auto hoge = possible[i].sort().uniq.array;
            int[] nexts;
            if (hoge.canFind(0) && hoge.canFind(1))  {
                writeln(0);
                exit(0);
            } else if (hoge.canFind(0)) {
                nexts ~= 0;
            } else if (hoge.canFind(1)) {
                nexts ~= 1;
            } else {
                nexts ~= [0, 1];
            }
            bool b = (ub & (1L << (M - i - 1))) > 0;
            foreach (under; 0..2) {
                foreach (next; nexts) {
                    if (!under && next && !b) continue;
                    dp[i+1][under||(next<b)] += dp[i][under];
                }
            }
        }
        return dp[M].sum;
    }

    auto ansR = solve(R);
    auto ansL = L == 0 ? 0 : solve(L - 1);
    writeln(ansR - ansL);
}
0