結果
問題 | No.2067 ±2^k operations |
ユーザー | とりゐ |
提出日時 | 2022-08-29 00:33:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 958 ms / 2,000 ms |
コード長 | 572 bytes |
コンパイル時間 | 230 ms |
コンパイル使用メモリ | 82,232 KB |
実行使用メモリ | 246,884 KB |
最終ジャッジ日時 | 2024-04-23 19:25:49 |
合計ジャッジ時間 | 13,545 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,032 KB |
testcase_01 | AC | 335 ms
90,240 KB |
testcase_02 | AC | 340 ms
89,740 KB |
testcase_03 | AC | 450 ms
90,884 KB |
testcase_04 | AC | 406 ms
89,768 KB |
testcase_05 | AC | 377 ms
88,528 KB |
testcase_06 | AC | 223 ms
78,808 KB |
testcase_07 | AC | 941 ms
242,396 KB |
testcase_08 | AC | 848 ms
240,432 KB |
testcase_09 | AC | 804 ms
243,876 KB |
testcase_10 | AC | 958 ms
246,884 KB |
testcase_11 | AC | 913 ms
243,416 KB |
testcase_12 | AC | 879 ms
240,956 KB |
testcase_13 | AC | 890 ms
241,004 KB |
testcase_14 | AC | 872 ms
240,588 KB |
testcase_15 | AC | 908 ms
240,760 KB |
testcase_16 | AC | 911 ms
240,852 KB |
testcase_17 | AC | 305 ms
81,132 KB |
testcase_18 | AC | 231 ms
77,488 KB |
testcase_19 | AC | 97 ms
76,476 KB |
testcase_20 | AC | 117 ms
77,056 KB |
testcase_21 | AC | 119 ms
76,288 KB |
testcase_22 | AC | 133 ms
76,484 KB |
testcase_23 | AC | 124 ms
76,472 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())): n=int(input()) print(calc(n+1)[0])