結果
問題 | No.911 ラッキーソート |
ユーザー |
|
提出日時 | 2022-06-12 18:14:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 208 ms / 2,000 ms |
コード長 | 1,591 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 112,460 KB |
最終ジャッジ日時 | 2024-09-23 04:29:38 |
合計ジャッジ時間 | 7,502 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
N,L,R = map(int,input().split()) A = list(map(int,input().split())) C = 61 x = [-1] * C import sys if N == 1: print(R - L + 1) exit() for i in range(N - 1): for j in reversed(range(C)): mask = 1 << j if A[i] & mask == A[i + 1] & mask: continue if A[i] & mask == 0: if x[j] == 1: print(0) exit() x[j] = 0 else: if x[j] == 0: print(0) exit() x[j] = 1 break def calc(S): if S == -1: return 0 dp = [0] * C mask = 1 << (C - 1) if S & mask: if x[-1] == 1: same = 1 dp[-1] = 0 elif x[-1] == 0: same = 0 dp[-1] = 1 else: same = 1 dp[-1] = 1 else: if x[-1] == 1: return 0 elif x[-1] == 0: same = 1 dp[-1] = 0 else: same = 1 dp[-1] = 0 for j in reversed(range(C - 1)): mask = 1 << j if S & mask: if x[j] == 1: dp[j] = dp[j+1] elif x[j] == 0: dp[j] = dp[j+1] + same same = 0 else: dp[j] = dp[j+1] * 2 + same else: if x[j] == 1: dp[j] = dp[j+1] same = 0 elif x[j] == 0: dp[j] = dp[j+1] else: dp[j] = dp[j+1] * 2 return dp[0] + same print(calc(R) - calc(L -1))