結果

問題 No.3628 Sum of Superfibonacci Numbers
コンテスト
ユーザー detteiuu
提出日時 2026-08-14 23:25:39
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 420 ms / 2,000 ms
+ 551µs
コード長 1,077 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 227 ms
コンパイル使用メモリ 95,900 KB
実行使用メモリ 85,536 KB
最終ジャッジ日時 2026-08-14 23:25:49
合計ジャッジ時間 5,808 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline

def judge(n):
    s = str(n)
    return any(int(s[i]) > int(s[i+1])+int(s[i+2]) for i in range(len(s)-2))

MOD = 998244353

half = pow(2, -1, MOD)

B = []
for n in range(0, 1000):
    k = n
    while not judge(k):
        k += 1
    B.append(k-n)

for _ in range(int(input())):
    N = int(input())

    size = len(str(N))
    dp = [[0]*1000 for _ in range(2)]
    dp[0][0] = 1
    for i in range(size):
        n = N//10**(size-1-i)%10
        ndp = [[0]*1000 for _ in range(2)]
        for small in range(2):
            for j in range(1000):
                if dp[small][j] == 0: continue
                for k in range(10 if small else n+1):
                    if i <= 1 or j%10+k >= j//10%10:
                        ndp[small or k < n][(j*10+k)%1000] += dp[small][j]
                        ndp[small or k < n][(j*10+k)%1000] %= MOD
        dp = ndp

    ans = ((1+N)%MOD*N%MOD*half%MOD-100)%MOD
    for i in range(2):
        for j in range(1000):
            ans += B[j]*dp[i][j]%MOD
            ans %= MOD

    print(ans)
0