結果
問題 |
No.2772 Appearing Even Times
|
ユーザー |
![]() |
提出日時 | 2025-05-21 04:58:42 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,238 bytes |
コンパイル時間 | 487 ms |
コンパイル使用メモリ | 82,504 KB |
実行使用メモリ | 271,668 KB |
最終ジャッジ日時 | 2025-05-21 04:58:49 |
合計ジャッジ時間 | 7,245 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 13 |
ソースコード
def ndlist(shape: list[int], *, val=0) -> list: assert len(shape) > 0 and all(s > 0 for s in shape) def rec(p): if p == len(shape)-1: return [val] * shape[p] return [rec(p+1) for _ in range(shape[p])] return rec(0) def digit_dp(s: str) -> int: ds = [int(c) for c in s] nd = len(ds) # dp = ndlist([nd+1, 2, 2, 1 << 10]) dp = ndlist([1 << 10, 2, 2]) # dp[i][j][k] # i : i 桁目までみた # j : n 未満か(j=0 完全一致 j=1 より小さい) # k : leading zero # m : 各数字の頻度の偶奇 # dp[0][0][1][0] = 1 dp[0][0][1] = 1 for i in range(nd): pp = ndlist([1 << 10, 2, 2]) dp, pp = pp, dp for j in range(2): to = ds[i] if j == 0 else 9 for k in range(2): for m in range(1 << 10): for x in range(to+1): nj = j | (x < to) nk = k & (x == 0) nm = m if nk else m ^ (1 << x) dp[nm][nj][nk] += pp[m][j][k] dp[nm][nj][nk] %= MOD return (dp[0][0][0] + dp[0][1][0]) % MOD MOD = 998244353 N = input() ans = digit_dp(N) print(ans)