結果
問題 | No.2067 ±2^k operations |
ユーザー | とりゐ |
提出日時 | 2022-08-25 21:51:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,116 ms / 2,000 ms |
コード長 | 590 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 259,304 KB |
最終ジャッジ日時 | 2024-04-23 19:16:35 |
合計ジャッジ時間 | 14,613 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
51,968 KB |
testcase_01 | AC | 368 ms
90,964 KB |
testcase_02 | AC | 368 ms
91,532 KB |
testcase_03 | AC | 524 ms
93,620 KB |
testcase_04 | AC | 501 ms
94,080 KB |
testcase_05 | AC | 448 ms
94,100 KB |
testcase_06 | AC | 248 ms
78,848 KB |
testcase_07 | AC | 978 ms
257,240 KB |
testcase_08 | AC | 964 ms
257,116 KB |
testcase_09 | AC | 997 ms
256,596 KB |
testcase_10 | AC | 945 ms
256,796 KB |
testcase_11 | AC | 939 ms
251,388 KB |
testcase_12 | AC | 929 ms
259,304 KB |
testcase_13 | AC | 970 ms
256,384 KB |
testcase_14 | AC | 980 ms
258,904 KB |
testcase_15 | AC | 1,116 ms
256,108 KB |
testcase_16 | AC | 919 ms
255,628 KB |
testcase_17 | AC | 313 ms
80,812 KB |
testcase_18 | AC | 224 ms
77,184 KB |
testcase_19 | AC | 112 ms
76,160 KB |
testcase_20 | AC | 136 ms
76,544 KB |
testcase_21 | AC | 143 ms
76,672 KB |
testcase_22 | AC | 140 ms
76,928 KB |
testcase_23 | AC | 140 ms
76,800 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%4==0: res,a,b,c=calc(n//4) res2=res*4+4*a+3*b+c a2=2*a+b+c b2=a+2*b+c c2=a+b+2*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])