結果

問題 No.911 ラッキーソート
ユーザー maspymaspy
提出日時 2020-03-17 12:18:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 35,432 KB
最終ジャッジ日時 2024-05-07 20:44:56
合計ジャッジ時間 7,244 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 25 ms
10,752 KB
testcase_03 AC 28 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 29 ms
10,880 KB
testcase_08 AC 29 ms
10,624 KB
testcase_09 AC 28 ms
10,624 KB
testcase_10 AC 26 ms
10,752 KB
testcase_11 AC 26 ms
10,752 KB
testcase_12 AC 26 ms
10,880 KB
testcase_13 AC 140 ms
32,876 KB
testcase_14 AC 139 ms
33,892 KB
testcase_15 AC 141 ms
33,000 KB
testcase_16 AC 148 ms
35,180 KB
testcase_17 AC 149 ms
35,056 KB
testcase_18 AC 144 ms
35,036 KB
testcase_19 AC 144 ms
34,128 KB
testcase_20 AC 141 ms
32,792 KB
testcase_21 AC 150 ms
34,248 KB
testcase_22 AC 143 ms
33,224 KB
testcase_23 AC 131 ms
31,036 KB
testcase_24 AC 125 ms
29,940 KB
testcase_25 AC 88 ms
22,132 KB
testcase_26 AC 75 ms
19,964 KB
testcase_27 AC 52 ms
15,104 KB
testcase_28 AC 37 ms
12,984 KB
testcase_29 AC 29 ms
11,392 KB
testcase_30 AC 28 ms
10,880 KB
testcase_31 AC 27 ms
10,752 KB
testcase_32 AC 26 ms
10,624 KB
testcase_33 AC 27 ms
10,880 KB
testcase_34 AC 30 ms
10,752 KB
testcase_35 AC 26 ms
10,752 KB
testcase_36 AC 26 ms
10,752 KB
testcase_37 AC 26 ms
10,752 KB
testcase_38 AC 147 ms
35,432 KB
testcase_39 AC 145 ms
33,832 KB
testcase_40 AC 32 ms
11,392 KB
testcase_41 AC 146 ms
33,804 KB
testcase_42 AC 101 ms
24,816 KB
testcase_43 AC 146 ms
34,024 KB
testcase_44 AC 101 ms
32,872 KB
testcase_45 AC 113 ms
34,276 KB
testcase_46 AC 106 ms
34,500 KB
testcase_47 AC 107 ms
32,956 KB
testcase_48 AC 103 ms
33,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache

# %%
N, L, R, *A = map(int, read().split())
status = [-1] * 64


# %%
def calc_bitwise_status():
    for a, b in zip(A, A[1:]):
        n = (a ^ b).bit_length() - 1
        aa = (a >> n) & 1
        if aa == 0:
            if status[n] == 1:
                return False
            status[n] = 0
        else:
            if status[n] == 0:
                return False
            status[n] = 1
    return True


# %%
if not calc_bitwise_status():
    print(0)
    exit()


# %%
@lru_cache(None)
def f(N, i):
    if N < 0:
        return 0
    if i == 63:
        return 1
    s = status[i]
    q, r = divmod(N, 2)
    if s == 0:
        return f(N // 2, i + 1)
    elif s == 1:
        return f((N - 1) // 2, i + 1)
    else:
        return f(N // 2, i + 1) + f((N - 1) // 2, i + 1)


# %%
print(f(R, 0) - f(L - 1, 0))
0