結果

問題 No.911 ラッキーソート
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-22 17:56:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,485 ms / 2,000 ms
コード長 1,664 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 160,568 KB
最終ジャッジ日時 2023-08-27 12:18:32
合計ジャッジ時間 35,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,440 KB
testcase_01 AC 71 ms
71,244 KB
testcase_02 AC 71 ms
71,524 KB
testcase_03 AC 79 ms
76,268 KB
testcase_04 AC 79 ms
76,072 KB
testcase_05 AC 86 ms
76,120 KB
testcase_06 AC 77 ms
75,952 KB
testcase_07 AC 84 ms
76,100 KB
testcase_08 AC 82 ms
76,092 KB
testcase_09 AC 83 ms
76,344 KB
testcase_10 AC 71 ms
71,464 KB
testcase_11 AC 82 ms
76,280 KB
testcase_12 AC 78 ms
76,044 KB
testcase_13 AC 1,422 ms
155,588 KB
testcase_14 AC 1,485 ms
140,076 KB
testcase_15 AC 1,317 ms
160,568 KB
testcase_16 AC 1,288 ms
131,176 KB
testcase_17 AC 1,340 ms
129,928 KB
testcase_18 AC 1,284 ms
131,516 KB
testcase_19 AC 1,342 ms
131,180 KB
testcase_20 AC 1,223 ms
159,448 KB
testcase_21 AC 1,120 ms
151,500 KB
testcase_22 AC 955 ms
137,544 KB
testcase_23 AC 961 ms
140,656 KB
testcase_24 AC 843 ms
125,328 KB
testcase_25 AC 513 ms
106,936 KB
testcase_26 AC 475 ms
95,800 KB
testcase_27 AC 250 ms
84,936 KB
testcase_28 AC 184 ms
81,288 KB
testcase_29 AC 144 ms
79,424 KB
testcase_30 AC 112 ms
78,940 KB
testcase_31 AC 94 ms
76,256 KB
testcase_32 AC 73 ms
71,140 KB
testcase_33 AC 84 ms
76,136 KB
testcase_34 AC 71 ms
71,288 KB
testcase_35 AC 91 ms
76,428 KB
testcase_36 AC 82 ms
76,200 KB
testcase_37 AC 84 ms
76,256 KB
testcase_38 AC 1,300 ms
139,968 KB
testcase_39 AC 946 ms
133,160 KB
testcase_40 AC 139 ms
79,188 KB
testcase_41 AC 1,209 ms
134,916 KB
testcase_42 AC 706 ms
126,016 KB
testcase_43 AC 1,314 ms
132,368 KB
testcase_44 AC 1,335 ms
155,128 KB
testcase_45 AC 1,351 ms
139,732 KB
testcase_46 AC 1,310 ms
135,920 KB
testcase_47 AC 1,312 ms
147,360 KB
testcase_48 AC 1,070 ms
134,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, L, R = map(int, input().split())
A = list(map(int, input().split()))
U = 62

bit = [3] * U


def dfs(d, A):
    if d < 0:
        return
    a0 = []
    a1 = []
    c01 = 0
    c10 = 0
    for i, a in enumerate(A):
        now = (a >> d) & 1
        if now:
            a1.append(a)
        else:
            a0.append(a)
        if i == 0:
            pre = now
            continue
        if pre == 0 and now == 1:
            c01 += 1
        if pre == 1 and now == 0:
            c10 += 1
        pre = now

    pair = (c01, c10)
    if pair == (0, 0):
        bit[d] &= 3
    elif pair == (0, 1):
        bit[d] &= 2
    elif pair == (1, 0):
        bit[d] &= 1
    else:
        bit[d] &= 0

    if a0:
        dfs(d - 1, a0)
    if a1:
        dfs(d - 1, a1)


dfs(U - 1, A)
dp = [[[0] * 2 for _ in range(2)] for _ in range(U + 1)]
dp[0][0][0] = 1
for i in range(U):
    shift = U-i-1
    D = bit[shift]
    Rbit = (R >> shift) & 1
    Lbit = (L >> shift) & 1
    for j in range(2):
        for k in range(2):
            for d in range(2):
                if (D >> d) & 1:
                    ni = i + 1
                    nj = j
                    nk = k
                    if nj == 0:
                        if d < Rbit:
                            nj = 1
                        if d > Rbit:
                            continue
                    if nk == 0:
                        if d > Lbit:
                            nk = 1
                        if d < Lbit:
                            continue
                    dp[ni][nj][nk] += dp[i][j][k]

ans = 0
for j in range(2):
    for k in range(2):
        ans += dp[U][j][k]
print(ans)
0