結果

問題 No.2067 ±2^k operations
ユーザー 👑 rin204rin204
提出日時 2022-09-02 23:14:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,226 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 77,468 KB
最終ジャッジ日時 2024-04-27 22:55:28
合計ジャッジ時間 4,620 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,812 KB
testcase_01 AC 140 ms
77,148 KB
testcase_02 AC 135 ms
77,204 KB
testcase_03 AC 141 ms
76,936 KB
testcase_04 AC 141 ms
76,804 KB
testcase_05 AC 138 ms
76,828 KB
testcase_06 AC 138 ms
76,928 KB
testcase_07 AC 158 ms
76,548 KB
testcase_08 AC 166 ms
76,684 KB
testcase_09 AC 164 ms
76,772 KB
testcase_10 AC 163 ms
76,520 KB
testcase_11 AC 160 ms
76,420 KB
testcase_12 AC 168 ms
76,764 KB
testcase_13 AC 159 ms
76,720 KB
testcase_14 AC 165 ms
76,984 KB
testcase_15 AC 163 ms
76,936 KB
testcase_16 AC 159 ms
76,480 KB
testcase_17 AC 149 ms
76,700 KB
testcase_18 AC 150 ms
76,240 KB
testcase_19 AC 101 ms
76,100 KB
testcase_20 AC 129 ms
77,468 KB
testcase_21 AC 135 ms
77,076 KB
testcase_22 AC 134 ms
76,816 KB
testcase_23 AC 153 ms
76,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
直近が
0
00...
1
11...
で遷移が変わるはず

11011
3なんだよな
"""

bi = [1]
for _ in range(60):
    bi.append(bi[-1] * 2)

def solve(S):
    eq = 0
    ans = 0
    dp = [0, 0, 0, 0]
    eq = 1
    cnt = 1
    t = len(S) - 2
    flg = True
    for s in S[1:]:
        ndp = [0] * 4
        ndp[0] = dp[3]
        ndp[1] = dp[0] + dp[1] + dp[2]
        ndp[2] = dp[1]
        ndp[3] = dp[0] + dp[2] + dp[3]
        ans += (dp[0] + dp[1] + dp[2]) * bi[t]
        if s == "1":
            if cnt >= 2:
                ndp[0] += 1
            else:
                ndp[1] += 1
            ans += eq * bi[t]

            cnt += 1
            if cnt <= 2:
                eq += 1
            flg = False
        elif flg:
            cnt = 0
        else:
            if cnt == 1:
                cnt = 0
            else:
                cnt = 1
            flg = True
        
        ndp[2] += 1
        ans += bi[t]
        t -= 1
        dp = ndp
    
    
    ans += eq
    return ans

for _ in range(int(input())):
    n = int(input())
    ans = solve(bin(n)[2:])
    print(ans)

exit()

print()
bef = 0
for i in range(1, 33):
    ans = solve(bin(i)[2:])
    print(bin(i)[2:], ans - bef, ans)
    bef = ans
0