結果
問題 | No.911 ラッキーソート |
ユーザー | mkawa2 |
提出日時 | 2021-03-15 16:59:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 432 ms / 2,000 ms |
コード長 | 2,852 bytes |
コンパイル時間 | 379 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 109,436 KB |
最終ジャッジ日時 | 2024-11-07 04:23:02 |
合計ジャッジ時間 | 13,987 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
55,296 KB |
testcase_01 | AC | 51 ms
54,912 KB |
testcase_02 | AC | 51 ms
55,296 KB |
testcase_03 | AC | 57 ms
62,208 KB |
testcase_04 | AC | 62 ms
63,488 KB |
testcase_05 | AC | 59 ms
62,464 KB |
testcase_06 | AC | 58 ms
62,208 KB |
testcase_07 | AC | 60 ms
62,208 KB |
testcase_08 | AC | 60 ms
62,080 KB |
testcase_09 | AC | 58 ms
62,080 KB |
testcase_10 | AC | 52 ms
55,424 KB |
testcase_11 | AC | 60 ms
62,080 KB |
testcase_12 | AC | 59 ms
62,080 KB |
testcase_13 | AC | 418 ms
104,960 KB |
testcase_14 | AC | 421 ms
105,092 KB |
testcase_15 | AC | 406 ms
108,288 KB |
testcase_16 | AC | 419 ms
109,052 KB |
testcase_17 | AC | 432 ms
109,436 KB |
testcase_18 | AC | 420 ms
107,128 KB |
testcase_19 | AC | 400 ms
106,088 KB |
testcase_20 | AC | 384 ms
105,044 KB |
testcase_21 | AC | 372 ms
108,368 KB |
testcase_22 | AC | 336 ms
107,768 KB |
testcase_23 | AC | 320 ms
104,964 KB |
testcase_24 | AC | 301 ms
99,824 KB |
testcase_25 | AC | 205 ms
98,688 KB |
testcase_26 | AC | 195 ms
87,680 KB |
testcase_27 | AC | 129 ms
81,280 KB |
testcase_28 | AC | 110 ms
78,464 KB |
testcase_29 | AC | 95 ms
76,800 KB |
testcase_30 | AC | 83 ms
73,600 KB |
testcase_31 | AC | 69 ms
66,304 KB |
testcase_32 | AC | 52 ms
55,808 KB |
testcase_33 | AC | 63 ms
64,256 KB |
testcase_34 | AC | 53 ms
55,168 KB |
testcase_35 | AC | 64 ms
63,488 KB |
testcase_36 | AC | 59 ms
62,208 KB |
testcase_37 | AC | 62 ms
63,232 KB |
testcase_38 | AC | 426 ms
108,816 KB |
testcase_39 | AC | 343 ms
102,280 KB |
testcase_40 | AC | 94 ms
76,416 KB |
testcase_41 | AC | 414 ms
106,696 KB |
testcase_42 | AC | 250 ms
98,304 KB |
testcase_43 | AC | 418 ms
106,252 KB |
testcase_44 | AC | 149 ms
104,960 KB |
testcase_45 | AC | 227 ms
105,088 KB |
testcase_46 | AC | 271 ms
105,964 KB |
testcase_47 | AC | 124 ms
105,956 KB |
testcase_48 | AC | 135 ms
104,280 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 from functools import lru_cache kn=62 n, l, r = LI() aa = LI() # for a in aa: print(bin(a)[2:].zfill(12)) bb = [-1]*kn def chk(k, l, r): stack=[(k,l,r)] while stack: k,l,r=stack.pop() m = -1 pb = aa[l] >> k & 1 for i, a in enumerate(aa[l+1:r], l+1): b = a >> k & 1 if b != pb: if m == -1: m = i else: return False pb = b if m == -1: if k:stack.append((k-1,l,r)) else: if bb[k] == -1: bb[k] = 1-pb elif bb[k] != 1-pb: return False if k: stack.append((k-1, l, m)) stack.append((k-1, m, r)) return True if chk(kn-1, 0, n) == False: print(0) exit() # kケタ見終わって、その桁以降が以下でもよい(1)か、未満でなければいけない(0)か # @lru_cache(None) # def solve(k, f): # if k == kn: return f # res = 0 # if f: # if lim[k]: # if bb[k] != 1: res += solve(k+1, 1) # if bb[k] != 0: res += solve(k+1, 1) # else: # if bb[k] != 1: res += solve(k+1, 1) # if bb[k] != 0: res += solve(k+1, 0) # else: # if lim[k]: # if bb[k] != 1: res += solve(k+1, 1) # if bb[k] != 0: res += solve(k+1, 0) # else: # if bb[k] != 1: res += solve(k+1, 0) # if bb[k] != 0: res += solve(k+1, 0) # return res def solve(r): if r==-1:return 0 cc=[r>>k&1 for k in range(kn)] dp=[[0]*2 for _ in range(kn+1)] dp[0][0]=1 for i,(b,c) in enumerate(zip(bb[::-1],cc[::-1])): for f in range(2): pre=dp[i][f] if pre==0:continue if f: if b!=1:dp[i+1][1]+=pre if b!=0:dp[i+1][1]+=pre else: if b!=1: if c:dp[i+1][1]+=pre else:dp[i+1][0]+=pre if b!=0 and c:dp[i+1][0]+=pre # p2D(dp) return sum(dp[-1]) ans=solve(r)-solve(l-1) print(ans)