結果

問題 No.911 ラッキーソート
ユーザー mkawa2mkawa2
提出日時 2021-03-15 16:24:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,297 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 38,576 KB
最終ジャッジ日時 2024-04-24 18:58:48
合計ジャッジ時間 5,105 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
16,384 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 32 ms
11,008 KB
testcase_03 AC 32 ms
10,752 KB
testcase_04 AC 33 ms
10,880 KB
testcase_05 AC 34 ms
11,008 KB
testcase_06 AC 32 ms
10,880 KB
testcase_07 AC 34 ms
10,752 KB
testcase_08 AC 32 ms
11,008 KB
testcase_09 AC 34 ms
11,008 KB
testcase_10 AC 32 ms
10,880 KB
testcase_11 AC 33 ms
10,880 KB
testcase_12 AC 32 ms
11,008 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 sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from functools import lru_cache

n, l, r = LI()
aa = LI()
# for a in aa: print(bin(a)[2:].zfill(12))

bb = [-1]*65

def chk(k, l, r):
    if k < 0: return True
    m = -1
    pb = aa[l] >> k & 1
    for i, a in enumerate(aa[l+1:r], l+1):
        b = a >> k & 1
        if b != pb:
            if m == -1:
                m = i
            else:
                return False
        pb = b
    if m == -1:
        if chk(k-1, l, r) == False: return False
    else:
        if bb[k] == -1:
            bb[k] = 1-pb
        elif bb[k] != 1-pb:
            return False
        if chk(k-1, l, m) == False: return False
        if chk(k-1, m, r) == False: return False
    return True

if chk(65, 0, n) == False:
    print(0)
    exit()

# kケタ見終わって、その桁以降が以下でもよい(1)か、未満でなければいけない(0)か
@lru_cache(None)
def solve(k, f):
    if k == 65: return f
    res = 0
    if f:
        if lim[k]:
            if bb[k] != 1: res += solve(k+1, 1)
            if bb[k] != 0: res += solve(k+1, 1)
        else:
            if bb[k] != 1: res += solve(k+1, 1)
            if bb[k] != 0: res += solve(k+1, 0)
    else:
        if lim[k]:
            if bb[k] != 1: res += solve(k+1, 1)
            if bb[k] != 0: res += solve(k+1, 0)
        else:
            if bb[k] != 1: res += solve(k+1, 0)
            if bb[k] != 0: res += solve(k+1, 0)
    return res

lim = [r >> k & 1 for k in range(65)]
# print(lim)
R = solve(0, 1)

solve.cache_clear()
L=0
if l>0:
    lim = [(l-1) >> k & 1 for k in range(65)]
    L = solve(0, 1)
# print(R, L)
print(R-L)
0