結果

問題 No.2067 ±2^k operations
ユーザー chineristACchineristAC
提出日時 2022-09-02 23:15:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,938 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 241,536 KB
最終ジャッジ日時 2024-04-27 22:56:25
合計ジャッジ時間 6,399 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
61,184 KB
testcase_01 AC 491 ms
98,024 KB
testcase_02 AC 495 ms
96,256 KB
testcase_03 AC 478 ms
97,536 KB
testcase_04 AC 494 ms
98,176 KB
testcase_05 AC 374 ms
95,104 KB
testcase_06 AC 143 ms
79,744 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
from itertools import cycle, permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

memo = {}
def calc(n):
    if n <= 1:
        return n
    
    if n in memo:
        return memo[n]
    
    if n&1 == 1:
        memo[n] = 1 + min(calc(n//2),calc((n+1)//2))
    else:
        memo[n] = calc(n//2)
        
    return memo[n]

A = [calc(i) for i in range(101)]

def calc2(n):
    if n <= 1:
        return n
    
    if n&1:
        if (n//2) & 1:
            return 1 + calc2((n+1)//2)
        else:
            return 1 + calc2((n)//2)
    else:
        return calc2(n//2)


def calc3(n):
    if n <= 1:
        return n
    
    if n&1:
        if n%4 == 3:
            return 1 + calc3((n+1)//2)
        else:
            return 1 + calc3((n)//2)
    else:
        return calc3(n//2)
        
memo = {}
def f(n):
    if n in memo:
        return memo[n]
    """
    sum calc(i) for i in 0...n
    """
    q,r = (n+1)//4,(n+1)%4
    res = 0
    for i in range(r):
        res += calc3(4*q+i)
    
    """
    sum calc(i) for i in 0123,4567,...,(4*q-4),(4*q-3),(4*q-2),(4*q-1)
    
    r
    0: calc(0) + calc(4//2) + calc(8//2) + ... calc((4*q-4)//2) = calc(0) + calc(1) + calc(2) + ... calc(q-1)
    1: calc(0) + calc(4//2) + calc(8//2) + ... calc((4*q-4)//2) = calc(0) + calc(1) + calc(2) + ... calc(q-1) + q
    2: calc(2//2) + calc(6//2) + calc(10//2) + ... calc((4*q-2)//2) = calc(1) + calc(3) + calc(5) + ... calc(2*q-1)
    3: calc(4//2) + calc(8//2) + ... calc((4*q)//2) = calc(1) + calc(2) + ... + calc(q) + q

    sum = f(q-1) + f(2*q-1) + f(q)
    """

    if q!=0:
        res += f(q-1) + f(2*q-1) + f(q) + 2*q
    
    memo[n] = res
    
    return res

for _ in range(int(input())):
    print(f(int(input())))
0