結果
問題 | No.2067 ±2^k operations |
ユーザー | 遭難者 |
提出日時 | 2022-08-29 09:25:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 509 ms / 2,000 ms |
コード長 | 587 bytes |
コンパイル時間 | 230 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 81,660 KB |
最終ジャッジ日時 | 2024-04-24 01:48:26 |
合計ジャッジ時間 | 8,812 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,352 KB |
testcase_01 | AC | 307 ms
78,336 KB |
testcase_02 | AC | 313 ms
78,552 KB |
testcase_03 | AC | 339 ms
79,380 KB |
testcase_04 | AC | 291 ms
79,268 KB |
testcase_05 | AC | 334 ms
78,672 KB |
testcase_06 | AC | 278 ms
79,344 KB |
testcase_07 | AC | 420 ms
80,232 KB |
testcase_08 | AC | 494 ms
81,228 KB |
testcase_09 | AC | 344 ms
79,872 KB |
testcase_10 | AC | 491 ms
80,640 KB |
testcase_11 | AC | 414 ms
81,660 KB |
testcase_12 | AC | 486 ms
80,768 KB |
testcase_13 | AC | 472 ms
80,512 KB |
testcase_14 | AC | 509 ms
81,612 KB |
testcase_15 | AC | 453 ms
80,088 KB |
testcase_16 | AC | 447 ms
81,048 KB |
testcase_17 | AC | 358 ms
80,484 KB |
testcase_18 | AC | 321 ms
79,872 KB |
testcase_19 | AC | 86 ms
76,192 KB |
testcase_20 | AC | 111 ms
76,672 KB |
testcase_21 | AC | 106 ms
76,280 KB |
testcase_22 | AC | 242 ms
77,864 KB |
testcase_23 | AC | 184 ms
77,312 KB |
ソースコード
memo={} def f(n): if n<=1: return n if n in memo: return memo[n] if n%2==0: res=f(n//2) memo[n]=res return res else: res=1+min(f(n//2),f(n//2+1)) memo[n]=res return res def calc(n): if n==1: return 0,1,0,0 if n%2==0: res,a,b,c=calc(n//2) res2=2*res+a+b a2=a+b b2=a+c c2=b+c return res2,a2,b2,c2 res,a,b,c=calc(n-1) p=f(n-1) q=f(n) res+=p if p<q: a+=1 if p==q: b+=1 if p>q: c+=1 return res,a,b,c for _ in range(int(input())): memo.clear() n=int(input()) print(calc(n+1)[0])