結果
問題 |
No.2067 ±2^k operations
|
ユーザー |
![]() |
提出日時 | 2022-08-29 09:25:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 607 ms / 2,000 ms |
コード長 | 587 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 81,544 KB |
最終ジャッジ日時 | 2024-11-06 08:27:46 |
合計ジャッジ時間 | 10,447 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 23 |
ソースコード
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])