結果

問題 No.2067 ±2^k operations
ユーザー 👑 rin204rin204
提出日時 2022-09-02 23:14:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,226 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 79,188 KB
最終ジャッジ日時 2023-08-10 05:37:26
合計ジャッジ時間 5,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,256 KB
testcase_01 AC 157 ms
78,424 KB
testcase_02 AC 153 ms
78,192 KB
testcase_03 AC 159 ms
78,228 KB
testcase_04 AC 155 ms
78,028 KB
testcase_05 AC 165 ms
78,196 KB
testcase_06 AC 164 ms
78,296 KB
testcase_07 AC 184 ms
77,476 KB
testcase_08 AC 182 ms
77,896 KB
testcase_09 AC 191 ms
77,708 KB
testcase_10 AC 181 ms
77,616 KB
testcase_11 AC 180 ms
77,656 KB
testcase_12 AC 180 ms
77,652 KB
testcase_13 AC 174 ms
77,720 KB
testcase_14 AC 178 ms
77,716 KB
testcase_15 AC 180 ms
77,580 KB
testcase_16 AC 174 ms
77,520 KB
testcase_17 AC 166 ms
77,440 KB
testcase_18 AC 167 ms
78,044 KB
testcase_19 AC 126 ms
78,092 KB
testcase_20 AC 149 ms
79,188 KB
testcase_21 AC 151 ms
77,924 KB
testcase_22 AC 154 ms
77,872 KB
testcase_23 AC 174 ms
78,168 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