結果

問題 No.291 黒い文字列
ユーザー maspymaspy
提出日時 2020-04-10 13:39:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 32,132 KB
最終ジャッジ日時 2023-10-13 02:17:31
合計ジャッジ時間 9,546 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
31,752 KB
testcase_01 AC 136 ms
31,756 KB
testcase_02 AC 143 ms
31,808 KB
testcase_03 AC 137 ms
31,800 KB
testcase_04 AC 135 ms
31,664 KB
testcase_05 AC 136 ms
31,820 KB
testcase_06 AC 139 ms
31,704 KB
testcase_07 AC 141 ms
31,788 KB
testcase_08 AC 144 ms
31,852 KB
testcase_09 AC 142 ms
31,780 KB
testcase_10 AC 152 ms
32,040 KB
testcase_11 AC 171 ms
31,940 KB
testcase_12 AC 169 ms
31,916 KB
testcase_13 AC 138 ms
31,892 KB
testcase_14 AC 142 ms
31,848 KB
testcase_15 AC 141 ms
31,924 KB
testcase_16 AC 210 ms
31,828 KB
testcase_17 AC 228 ms
31,780 KB
testcase_18 AC 218 ms
32,016 KB
testcase_19 AC 255 ms
31,840 KB
testcase_20 AC 257 ms
31,808 KB
testcase_21 AC 181 ms
31,880 KB
testcase_22 AC 229 ms
32,016 KB
testcase_23 AC 279 ms
31,872 KB
testcase_24 AC 228 ms
31,848 KB
testcase_25 AC 173 ms
31,912 KB
testcase_26 AC 183 ms
31,944 KB
testcase_27 AC 150 ms
31,808 KB
testcase_28 AC 155 ms
31,872 KB
testcase_29 AC 164 ms
32,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

S = read().rstrip().decode()
dp = np.full((21, 21, 21, 21), -100, np.int32)
dp[0, 0, 0, 0] = 0

for x in S:
    newdp = dp.copy()
    if x in 'K?':
        np.maximum(newdp[1:], dp[:-1], out=newdp[1:])
    if x in 'U?':
        np.maximum(newdp[:-1, 1:], dp[1:, :-1], out=newdp[:-1, 1:])
    if x in 'R?':
        np.maximum(newdp[:, :-1, 1:], dp[:, 1:, :-1], out=newdp[:, :-1, 1:])
    if x in 'O?':
        np.maximum(newdp[:, :, :-1, 1:], dp[:, :, 1:, :-1], out=newdp[:, :, :-1, 1:])
    if x in 'I?':
        np.maximum(newdp[:, :, :, :-1], dp[:, :, :, 1:] + 1, out=newdp[:, :, :, :-1])
    dp = newdp

print(dp.max())
0