結果

問題 No.911 ラッキーソート
ユーザー mkawa2mkawa2
提出日時 2019-11-02 16:49:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,055 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 132,004 KB
最終ジャッジ日時 2023-10-13 01:25:50
合計ジャッジ時間 20,176 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,212 KB
testcase_01 AC 16 ms
8,436 KB
testcase_02 AC 16 ms
8,028 KB
testcase_03 WA -
testcase_04 AC 16 ms
8,340 KB
testcase_05 WA -
testcase_06 AC 17 ms
8,112 KB
testcase_07 AC 17 ms
8,276 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 17 ms
7,996 KB
testcase_11 WA -
testcase_12 AC 17 ms
7,988 KB
testcase_13 WA -
testcase_14 AC 1,844 ms
128,932 KB
testcase_15 AC 1,822 ms
129,640 KB
testcase_16 AC 1,880 ms
127,492 KB
testcase_17 AC 1,874 ms
132,004 KB
testcase_18 WA -
testcase_19 AC 1,829 ms
126,584 KB
testcase_20 WA -
testcase_21 TLE -
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 sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    max_k = 60
    n, l, r = map(int, input().split())
    aa = list(map(int, input().split()))
    #for a in aa:
        #print(format(a, "b"))

    aadig = [[] for _ in range(max_k)]
    for a in aa:
        for j in range(max_k - 1, -1, -1):
            aadig[max_k - 1 - j].append((a >> j) & 1)
    #p2D(aadig)
    ans_dig = [-1] * max_k
    sep = set([n])
    for k in range(max_k):
        nsep = set()
        pi = 0
        flag_k = -1
        for si in sorted(sep):
            flag_sep = -1
            st = aadig[k][pi]
            for i in range(pi, si):
                d = aadig[k][i]
                if flag_sep == d:
                    print(0)
                    exit()
                if d == 1 - st:
                    flag_sep = st
                    st = d
                    nsep.add(i)
            if flag_sep > -1:
                if flag_k > -1 and flag_k != flag_sep:
                    print(0)
                    exit()
                else:
                    flag_k = flag_sep
            pi = si
        else:
            sep |= nsep
            ans_dig[k] = flag_k
    #print(format(l, "b"))
    #print(format(r, "b"))
    #print(ans_dig)
    dp = [[[0] * 2 for _ in range(2)] for _ in range(max_k + 1)]
    dp[0][0][0] = 1
    for k in range(max_k):
        lk = l >> (max_k - 1 - k) & 1
        rk = r >> (max_k - 1 - k) & 1
        for b in range(2):
            for s in range(2):
                pre = dp[k][b][s]
                if pre == 0: continue
                nb, ns = b, s
                if ans_dig[k] != 1 and (s == 1 or lk == 0):
                    if rk == 1: nb = 1
                    dp[k + 1][nb][ns] += pre
                nb = b
                if ans_dig[k] != 0 and (b == 1 or rk == 1):
                    if lk == 0: ns = 1
                    dp[k + 1][nb][ns] += pre
    print(sum(dp[max_k][0]) + sum(dp[max_k][1]))
    #p2D(dp)

main()
0