結果
問題 |
No.911 ラッキーソート
|
ユーザー |
|
提出日時 | 2022-06-12 18:07:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,591 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 82,036 KB |
実行使用メモリ | 112,572 KB |
最終ジャッジ日時 | 2024-09-23 04:20:01 |
合計ジャッジ時間 | 8,267 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 WA * 18 |
ソースコード
N,L,R = map(int,input().split()) A = list(map(int,input().split())) C = 60 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 = 0 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))