結果

問題 No.1185 完全な3の倍数
コンテスト
ユーザー tktk_snsn
提出日時 2021-04-25 16:39:42
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 520 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 428 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-03-25 17:11:34
合計ジャッジ時間 5,675 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

S = input()
N = len(S)

dp = [[0]*2 for _ in range(N+1)]
dp[0][0] = 1
for i, s in enumerate(S):
    nd = int(s)
    for j in range(2):
        for d in range(0, 10, 3):
            ni = i + 1
            nj = j
            if nj == 0:
                if d > nd:
                    continue
                if d < nd:
                    nj = 1
            dp[ni][nj] += dp[i][j]

ans = dp[N][0] + dp[N][1] - 4
for i in range(10, min(int(S)+1, 100)):
    if i % 3 == 0 and (i % 10) % 3 != 0:
        ans += 1

print(ans)
0