結果

問題 No.2772 Appearing Even Times
ユーザー rlangevinrlangevin
提出日時 2024-05-31 23:14:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 149 ms / 4,000 ms
コード長 1,111 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 87,808 KB
最終ジャッジ日時 2024-05-31 23:14:45
合計ジャッジ時間 2,992 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,532 KB
testcase_01 AC 38 ms
53,152 KB
testcase_02 AC 40 ms
52,264 KB
testcase_03 AC 40 ms
52,556 KB
testcase_04 AC 38 ms
53,264 KB
testcase_05 AC 39 ms
52,656 KB
testcase_06 AC 39 ms
53,420 KB
testcase_07 AC 39 ms
52,340 KB
testcase_08 AC 93 ms
84,964 KB
testcase_09 AC 121 ms
87,352 KB
testcase_10 AC 38 ms
53,748 KB
testcase_11 AC 38 ms
53,260 KB
testcase_12 AC 117 ms
87,788 KB
testcase_13 AC 120 ms
87,236 KB
testcase_14 AC 119 ms
87,372 KB
testcase_15 AC 116 ms
87,772 KB
testcase_16 AC 118 ms
87,608 KB
testcase_17 AC 118 ms
87,808 KB
testcase_18 AC 117 ms
87,788 KB
testcase_19 AC 149 ms
87,436 KB
testcase_20 AC 118 ms
87,308 KB
testcase_21 AC 117 ms
87,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(input())
S = list(map(int, S))
N = len(S)
dp = [[[0] * 2 for _ in range(11)] for _ in range(N)]
dp[0][1][0] = S[0] - 1
dp[0][0][1] = 1
mod = 998244353
L = [0] * 10
L[S[0]] += 1
for i in range(1, N):
    for j in range(11):
        # 真に小さい場合
        
        # 奇数個の数が増える
        if j + 1 <= 10:
            dp[i][j + 1][0] += dp[i - 1][j][0] * (10 - j)
            dp[i][j + 1][0] += dp[i - 1][j][1] * 9
            dp[i][j + 1][0] %= mod
        
        # 奇数個の数が減る
        if j:
            dp[i][j - 1][0] += dp[i - 1][j][0] * j
            dp[i][j - 1][0] %= mod
        
        # leading0が続く
        dp[i][j][1] += dp[i - 1][j][1]
        dp[i][j][1] %= mod
        
    # Nちょうどから遷移してくる場合
    pj = sum(L)
    for j in range(S[i]):
        L[j] ^= 1
        nj = sum(L)
        dp[i][nj][0] += 1
        dp[i][nj][0] %= mod
        L[j] ^= 1
    
    # Nちょうどの場合の奇数個を管理    
    L[S[i]] ^= 1

ans = dp[N - 1][0][0]
if sum(L) == 0:
    ans += 1
    ans %= mod
        
print(ans)            
0