結果

問題 No.1185 完全な3の倍数
ユーザー tktk_snsn
提出日時 2021-04-25 16:39:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-04 09:30:41
合計ジャッジ時間 2,575 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

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