結果

問題 No.1811 EQUIV Ten
ユーザー customaddonecustomaddone
提出日時 2022-01-14 23:13:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 2,249 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 82,624 KB
実行使用メモリ 136,884 KB
最終ジャッジ日時 2024-04-30 17:08:33
合計ジャッジ時間 5,497 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
63,096 KB
testcase_01 AC 43 ms
61,632 KB
testcase_02 AC 51 ms
67,604 KB
testcase_03 AC 43 ms
61,888 KB
testcase_04 AC 44 ms
62,560 KB
testcase_05 AC 44 ms
62,072 KB
testcase_06 AC 43 ms
61,692 KB
testcase_07 AC 44 ms
62,440 KB
testcase_08 AC 44 ms
62,516 KB
testcase_09 AC 45 ms
63,024 KB
testcase_10 AC 44 ms
62,192 KB
testcase_11 AC 277 ms
126,812 KB
testcase_12 AC 271 ms
130,380 KB
testcase_13 AC 295 ms
135,148 KB
testcase_14 AC 292 ms
136,704 KB
testcase_15 AC 294 ms
136,884 KB
testcase_16 AC 44 ms
62,880 KB
testcase_17 AC 60 ms
71,256 KB
testcase_18 AC 60 ms
73,256 KB
testcase_19 AC 53 ms
68,360 KB
testcase_20 AC 76 ms
80,664 KB
testcase_21 AC 78 ms
79,916 KB
testcase_22 AC 61 ms
71,884 KB
testcase_23 AC 148 ms
97,580 KB
testcase_24 AC 84 ms
81,296 KB
testcase_25 AC 59 ms
73,116 KB
testcase_26 AC 133 ms
93,720 KB
testcase_27 AC 71 ms
78,332 KB
testcase_28 AC 44 ms
61,944 KB
testcase_29 AC 54 ms
68,364 KB
testcase_30 AC 260 ms
125,212 KB
testcase_31 AC 74 ms
78,976 KB
testcase_32 AC 84 ms
81,484 KB
testcase_33 AC 89 ms
81,188 KB
testcase_34 AC 246 ms
122,772 KB
testcase_35 AC 132 ms
93,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
import math
from copy import deepcopy
from itertools import combinations, permutations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right

import sys

def input():
    return sys.stdin.readline().rstrip()
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getListGraph():
    return list(map(lambda x:int(x) - 1, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

mod = 10 ** 9 + 7
MOD = 998244353
# sys.setrecursionlimit(10000000)
inf = float('inf')
eps = 10 ** (-15)
dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]

#############
# Main Code #
#############

"""
Nがくそでか bitで考える 桁dp?
x // 2^k あるbit以下を切り捨て 後ろ4つが 1010
つまり 1010を持つ数がいくつあるか 桁dp
'', '1', '10', '101', '1010' の5つ
耳桁dp
"""

S = '1' * getN()
if S == '':
    print(0)
    exit()

N = len(S)
# 次にあるべき数字
jud = [1, 0, 1, 0, inf]
# dp[i][j][k]: iまで進んで最大値になる可能性がある(0)/ない(1), 状態はk
dp = [[[0] * 5 for _ in range(2)] for i in range(N + 1)]
dp[0][0][0] = 1

for i in range(N):
    d = int(S[i])
    # Lになる可能性があるかないか
    # ある→ある
    for j in range(2):
        # 次の桁は何にする あるの場合はd以下 ないの場合は0, 1
        for d_j in range(2 if j else d + 1):
            # 状態1~4
            for k in range(4):
                # 次に進める
                if d_j == jud[k]:
                    dp[i + 1][j | (d_j < d)][k + 1] += dp[i][j][k]
                    dp[i + 1][j | (d_j < d)][k + 1] %= mod
                # 進めない
                else:
                    # 次が0なら状態0, 1なら状態1
                    dp[i + 1][j | (d_j < d)][(d_j == 1)] += dp[i][j][k]
                    dp[i + 1][j | (d_j < d)][(d_j == 1)] %= mod
            # 状態5
            dp[i + 1][j | (d_j < d)][4] += dp[i][j][4]
            dp[i + 1][j | (d_j < d)][4] %= mod

print((dp[i + 1][0][-1] + dp[i + 1][1][-1]) % mod)
0