結果

問題 No.911 ラッキーソート
ユーザー maspymaspy
提出日時 2020-03-17 12:18:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 11,052 KB
実行使用メモリ 33,056 KB
最終ジャッジ日時 2023-08-20 14:17:18
合計ジャッジ時間 7,679 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,772 KB
testcase_01 AC 22 ms
8,644 KB
testcase_02 AC 20 ms
8,756 KB
testcase_03 AC 20 ms
8,888 KB
testcase_04 AC 20 ms
8,812 KB
testcase_05 AC 20 ms
8,700 KB
testcase_06 AC 21 ms
8,684 KB
testcase_07 AC 20 ms
8,864 KB
testcase_08 AC 20 ms
8,840 KB
testcase_09 AC 20 ms
8,772 KB
testcase_10 AC 21 ms
8,684 KB
testcase_11 AC 21 ms
8,824 KB
testcase_12 AC 20 ms
8,856 KB
testcase_13 AC 123 ms
30,464 KB
testcase_14 AC 125 ms
31,688 KB
testcase_15 AC 124 ms
30,504 KB
testcase_16 AC 132 ms
32,912 KB
testcase_17 AC 132 ms
32,876 KB
testcase_18 AC 131 ms
33,056 KB
testcase_19 AC 130 ms
32,052 KB
testcase_20 AC 129 ms
30,788 KB
testcase_21 AC 131 ms
31,816 KB
testcase_22 AC 128 ms
31,052 KB
testcase_23 AC 119 ms
28,992 KB
testcase_24 AC 112 ms
27,976 KB
testcase_25 AC 77 ms
20,116 KB
testcase_26 AC 64 ms
17,616 KB
testcase_27 AC 41 ms
13,080 KB
testcase_28 AC 31 ms
10,800 KB
testcase_29 AC 23 ms
9,300 KB
testcase_30 AC 21 ms
8,764 KB
testcase_31 AC 20 ms
8,776 KB
testcase_32 AC 20 ms
8,868 KB
testcase_33 AC 20 ms
8,828 KB
testcase_34 AC 20 ms
8,688 KB
testcase_35 AC 20 ms
8,684 KB
testcase_36 AC 20 ms
8,800 KB
testcase_37 AC 20 ms
8,616 KB
testcase_38 AC 129 ms
32,916 KB
testcase_39 AC 127 ms
31,568 KB
testcase_40 AC 26 ms
9,320 KB
testcase_41 AC 130 ms
31,480 KB
testcase_42 AC 88 ms
22,712 KB
testcase_43 AC 126 ms
31,864 KB
testcase_44 AC 90 ms
30,480 KB
testcase_45 AC 99 ms
32,164 KB
testcase_46 AC 90 ms
32,344 KB
testcase_47 AC 93 ms
30,900 KB
testcase_48 AC 91 ms
31,264 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