結果

問題 No.911 ラッキーソート
ユーザー nebukuro09nebukuro09
提出日時 2019-10-18 23:25:12
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,966 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 117,396 KB
実行使用メモリ 48,300 KB
最終ジャッジ日時 2023-09-04 03:08:26
合計ジャッジ時間 6,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
        auto B = A[l..r].map!(a => (a & (1L << keta)) > 0).array;
        auto x = B.dup.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].dup.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