結果

問題 No.2067 ±2^k operations
ユーザー 👑 rin204rin204
提出日時 2022-09-02 23:07:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 77,752 KB
最終ジャッジ日時 2024-04-27 22:47:33
合計ジャッジ時間 5,907 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,756 KB
testcase_01 AC 189 ms
77,432 KB
testcase_02 AC 170 ms
77,588 KB
testcase_03 AC 185 ms
77,200 KB
testcase_04 AC 178 ms
77,708 KB
testcase_05 AC 175 ms
77,088 KB
testcase_06 AC 170 ms
77,072 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 99 ms
76,172 KB
testcase_20 AC 135 ms
77,752 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

11011
3なんだよな
"""

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

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]
        ans %= MOD
        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]
        ans %= MOD
        t -= 1
        dp = [d % MOD for d in ndp]
    
    
    ans += eq
    return ans % MOD

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