結果
| 問題 |
No.220 世界のなんとか2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-30 17:45:14 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 1,000 ms |
| コード長 | 1,098 bytes |
| コンパイル時間 | 97 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-11-27 15:11:25 |
| 合計ジャッジ時間 | 1,605 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
INF = float("inf")
sys.setrecursionlimit(10 ** 7)
# 4近傍(右, 下, 左, 上)
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
S = ""
memo = {}
def dfs(idx, tight, find, rest):
if idx >= len(S):
return find or rest == 0
if (idx, tight, find, rest) in memo:
return memo[(idx, tight, find, rest)]
x = int(S[idx])
upper = x if tight else 9
ans = 0
for i in range(upper + 1):
ans += dfs(idx + 1, tight and (i == x), find or i == 3, (rest + i) % 3)
memo[(idx, tight, find, rest)] = ans
return ans
def main():
global S
S = str(10 ** int(input()))
print(dfs(0, True, False, 0) - 1)
if __name__ == '__main__':
main()