結果

問題 No.3628 Sum of Superfibonacci Numbers
コンテスト
ユーザー detteiuu
提出日時 2026-08-14 23:19:51
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 1,410 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 221 ms
コンパイル使用メモリ 96,104 KB
実行使用メモリ 313,216 KB
最終ジャッジ日時 2026-08-14 23:20:28
合計ジャッジ時間 14,290 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 TLE * 3 -- * 9
権限があれば一括ダウンロードができます

ソースコード

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(10)] for _ in range(10)] for _ in range(2)]
    dp[0][0][0][0] = 1
    for i in range(size):
        n = N//10**(size-1-i)%10
        ndp = [[[[0]*1000 for _ in range(10)] for _ in range(10)] for _ in range(2)]
        for small in range(2):
            for j in range(10):
                for k in range(10):
                    for l in range(1000):
                        if dp[small][j][k][l] == 0: continue
                        for m in range(10 if small == 1 else n+1):
                            if i <= 1 or j <= m:
                                ndp[small or m < n][max(k-m, 0)][m][(l*10+m)%1000] += dp[small][j][k][l]
                                ndp[small or m < n][max(k-m, 0)][m][(l*10+m)%1000] %= MOD
        dp = ndp

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

    print(ans)
0