結果
問題 |
No.1185 完全な3の倍数
|
ユーザー |
![]() |
提出日時 | 2020-08-27 23:13:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 524 bytes |
コンパイル時間 | 211 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 52,416 KB |
最終ジャッジ日時 | 2024-11-24 09:49:55 |
合計ジャッジ時間 | 3,043 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
n = int(input()) ans = 0 threes = 0 for i in range(10, min(100, n+1)): p, q = divmod(i, 10) if (p + q) % 3 == 0: ans += 1 if p % 3 == 0: threes += 1 if n < 100: print(ans) exit() ans -= threes + 4 n = str(n) dp = [[0, 0] for _ in range(len(n) + 1)] dp[0][0] = 1 for i, x in enumerate(map(int, n)): if x == 0 or x == 3 or x == 6 or x == 9: dp[i+1][0] += dp[i][0] dp[i+1][1] += (x + 2) // 3 * dp[i][0] dp[i+1][1] += dp[i][1] * 4 ans += sum(dp[len(n)]) print(ans)