結果
| 問題 |
No.2772 Appearing Even Times
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-05-21 01:12:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,141 bytes |
| コンパイル時間 | 676 ms |
| コンパイル使用メモリ | 82,240 KB |
| 実行使用メモリ | 410,708 KB |
| 最終ジャッジ日時 | 2025-05-21 01:12:32 |
| 合計ジャッジ時間 | 6,985 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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[i][j][k]
# i : i 桁目までみた
# j : n 未満か(j=0 完全一致 j=1 より小さい)
# k : leading zero
# m : 各数字の頻度の偶奇
dp[0][0][1][0] = 1
for i in range(nd):
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[i+1][nj][nk][nm] += dp[i][j][k][m]
dp[i+1][nj][nk][nm] %= MOD
return (dp[nd][0][0][0] + dp[nd][1][0][0]) % MOD
MOD = 998244353
N = input()
ans = digit_dp(N)
print(ans)
norioc