結果

問題 No.291 黒い文字列
ユーザー mkawa2mkawa2
提出日時 2023-10-19 14:59:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,636 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 266,140 KB
最終ジャッジ日時 2023-10-19 14:59:41
合計ジャッジ時間 11,124 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,788 KB
testcase_01 AC 41 ms
55,440 KB
testcase_02 AC 42 ms
55,440 KB
testcase_03 AC 41 ms
55,440 KB
testcase_04 AC 44 ms
55,440 KB
testcase_05 AC 40 ms
55,440 KB
testcase_06 AC 41 ms
55,440 KB
testcase_07 AC 41 ms
55,440 KB
testcase_08 AC 43 ms
55,440 KB
testcase_09 AC 46 ms
55,440 KB
testcase_10 AC 41 ms
55,440 KB
testcase_11 AC 92 ms
76,432 KB
testcase_12 AC 121 ms
77,044 KB
testcase_13 AC 41 ms
55,440 KB
testcase_14 AC 42 ms
55,440 KB
testcase_15 AC 40 ms
55,440 KB
testcase_16 AC 362 ms
85,900 KB
testcase_17 AC 514 ms
93,288 KB
testcase_18 AC 391 ms
87,932 KB
testcase_19 AC 1,125 ms
138,064 KB
testcase_20 AC 1,540 ms
186,804 KB
testcase_21 AC 42 ms
55,440 KB
testcase_22 AC 1,420 ms
171,880 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = -1-(-1 << 31)
# inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

from collections import defaultdict

def pack(arr):
    s = 0
    for a in arr: s = s*21+a
    return s

def unpack(p):
    res = []
    for _ in range(4):
        p, r = divmod(p, 21)
        res.append(r)
    return res[::-1]

def update(c):
    kuro = pkuro[:]
    val = pre[p]
    if c == 0:
        kuro[0] = min(20, kuro[0]+1)
    elif c == 4:
        if kuro[c-1]:
            kuro[c-1] -= 1
            val += 1
    elif kuro[c-1]:
        kuro[c-1] -= 1
        kuro[c] = min(20, kuro[c]+1)
    q = pack(kuro)
    dp[q] = max(dp[q], val)

s = SI()
dp = defaultdict(int)
dp[0] = 0
for c in s:
    c = "KUROI?".find(c)
    if c == -1: continue
    pre, dp = dp, defaultdict(int)
    for p in pre:
        pkuro = unpack(p)
        if c == 5:
            for i in range(5): update(i)
        else:
            update(c)
    # pDB(pre, dp)

print(max(dp.values()))
0