結果

問題 No.291 黒い文字列
ユーザー maspymaspy
提出日時 2020-04-10 13:18:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 981 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 78,180 KB
最終ジャッジ日時 2023-10-13 01:31:57
合計ジャッジ時間 9,372 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
75,896 KB
testcase_01 AC 84 ms
75,972 KB
testcase_02 AC 84 ms
75,976 KB
testcase_03 AC 90 ms
76,020 KB
testcase_04 AC 84 ms
76,064 KB
testcase_05 AC 86 ms
76,020 KB
testcase_06 AC 85 ms
75,960 KB
testcase_07 AC 87 ms
75,916 KB
testcase_08 AC 84 ms
75,900 KB
testcase_09 AC 85 ms
75,980 KB
testcase_10 AC 86 ms
76,004 KB
testcase_11 AC 151 ms
77,404 KB
testcase_12 AC 161 ms
78,060 KB
testcase_13 AC 84 ms
76,092 KB
testcase_14 AC 86 ms
75,960 KB
testcase_15 AC 85 ms
76,296 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 884 ms
77,872 KB
testcase_21 AC 86 ms
75,852 KB
testcase_22 WA -
testcase_23 AC 861 ms
78,144 KB
testcase_24 WA -
testcase_25 AC 85 ms
75,960 KB
testcase_26 AC 85 ms
75,972 KB
testcase_27 AC 85 ms
75,972 KB
testcase_28 AC 84 ms
76,004 KB
testcase_29 AC 85 ms
76,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools

S = read().rstrip().decode()
ques = S.count('?')


def solve(a, b, c, d, e):
    stack = ['I'] * e + ['O'] * d + ['R'] * c + ['U'] * b + ['K'] * a
    K = 0
    KU = 0
    KUR = 0
    KURO = 0
    KUROI = 0
    for i, x in enumerate(S):
        if x == '?':
            x = stack.pop()
        if x == 'K':
            K += 1
        elif x == 'U' and K:
            K -= 1
            KU += 1
        elif x == 'R' and KU:
            KU -= 1
            KUR += 1
        elif x == 'O' and KUR:
            KUR -= 1
            KURO += 1
        elif x == 'I' and KURO:
            KURO -= 1
            KUROI += 1
    return KUROI


answer = 0
for a, b, c, d in itertools.product(range(21), repeat=4):
    e = ques - (a + b + c + d)
    if e < 0:
        continue
    x = solve(a, b, c, d, e)
    if answer < x:
        answer = x
print(answer)
0