結果

問題 No.220 世界のなんとか2
ユーザー terasaterasa
提出日時 2022-11-04 21:50:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 1,000 ms
コード長 1,456 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 87,324 KB
実行使用メモリ 72,816 KB
最終ジャッジ日時 2023-09-26 00:13:38
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
72,768 KB
testcase_01 AC 104 ms
72,528 KB
testcase_02 AC 100 ms
72,764 KB
testcase_03 AC 102 ms
72,628 KB
testcase_04 AC 101 ms
72,640 KB
testcase_05 AC 100 ms
72,576 KB
testcase_06 AC 101 ms
72,644 KB
testcase_07 AC 101 ms
72,760 KB
testcase_08 AC 100 ms
72,560 KB
testcase_09 AC 100 ms
72,556 KB
testcase_10 AC 101 ms
72,624 KB
testcase_11 AC 101 ms
72,656 KB
testcase_12 AC 102 ms
72,584 KB
testcase_13 AC 100 ms
72,572 KB
testcase_14 AC 101 ms
72,688 KB
testcase_15 AC 102 ms
72,816 KB
testcase_16 AC 105 ms
72,376 KB
testcase_17 AC 103 ms
72,436 KB
testcase_18 AC 103 ms
72,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import itertools
import heapq
import bisect
from collections import deque, defaultdict
from functools import lru_cache, cmp_to_key

input = sys.stdin.readline

# for AtCoder Easy test
if __file__ != 'prog.py':
    sys.setrecursionlimit(10 ** 6)


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input().rstrip()


P = int(input())
S = str(10 ** P)
dp = [[[0, 0] for _ in range(2)] for _ in range(3)]
dp[0][0][0] = 1
for i in range(len(S)):
    ndp = [[[0, 0] for _ in range(2)] for _ in range(3)]
    for j in range(3):
        for k in range(10):
            n = (j + k) % 3
            if k == 3:
                ndp[n][1][1] += dp[j][1][1] + dp[j][0][1]
            else:
                ndp[n][1][1] += dp[j][1][1]
                ndp[n][0][1] += dp[j][0][1]

            if k < int(S[i]):
                if k == 3:
                    ndp[n][1][1] += dp[j][1][0] + dp[j][0][0]
                else:
                    ndp[n][1][1] += dp[j][1][0]
                    ndp[n][0][1] += dp[j][0][0]
            elif k == int(S[i]):
                if k == 3:
                    ndp[n][1][0] += dp[j][1][0] + dp[j][0][0]
                else:
                    ndp[n][1][0] += dp[j][1][0]
                    ndp[n][0][0] += dp[j][0][0]
    dp = ndp

ans = 0
for i in range(3):
    for j in range(2):
        if i == 0 or j == 1:
            ans += sum(dp[i][j])
print(ans - 1)
0