結果

問題 No.161 制限ジャンケン
ユーザー lloyzlloyz
提出日時 2023-06-11 23:16:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 293 ms / 5,000 ms
コード長 1,450 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 88,588 KB
最終ジャッジ日時 2023-08-31 02:10:28
合計ジャッジ時間 4,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
78,492 KB
testcase_01 AC 97 ms
71,644 KB
testcase_02 AC 96 ms
71,564 KB
testcase_03 AC 97 ms
71,612 KB
testcase_04 AC 95 ms
71,692 KB
testcase_05 AC 94 ms
71,664 KB
testcase_06 AC 229 ms
86,460 KB
testcase_07 AC 103 ms
77,212 KB
testcase_08 AC 293 ms
88,588 KB
testcase_09 AC 113 ms
77,176 KB
testcase_10 AC 173 ms
79,724 KB
testcase_11 AC 163 ms
79,092 KB
testcase_12 AC 157 ms
78,792 KB
testcase_13 AC 238 ms
85,052 KB
testcase_14 AC 182 ms
80,284 KB
testcase_15 AC 209 ms
82,108 KB
testcase_16 AC 162 ms
78,976 KB
testcase_17 AC 158 ms
78,744 KB
testcase_18 AC 167 ms
78,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

g, c, p = map(int, input().split())
s = input()

n = g + c + p
DP = [[[-1 for _ in range(p + 1)] for _ in range(c + 1)] for _ in range(g + 1)]
DP[g][c][p] = 0
for i in range(n):
    ss = s[i]
    res = n - i
    for j in range(g + 1):
        for k in range(c + 1):
            if 0 <= res - j - k <= p:
                l = res - j - k
                if ss == 'G':
                    if j > 0:
                        DP[j - 1][k][l] = max(DP[j - 1][k][l], DP[j][k][l] + 1)
                    if k > 0:
                        DP[j][k - 1][l] = max(DP[j][k - 1][l], DP[j][k][l])
                    if l > 0:
                        DP[j][k][l - 1] = max(DP[j][k][l - 1], DP[j][k][l] + 3)
                elif ss == 'C':
                    if j > 0:
                        DP[j - 1][k][l] = max(DP[j - 1][k][l], DP[j][k][l] + 3)
                    if k > 0:
                        DP[j][k - 1][l] = max(DP[j][k - 1][l], DP[j][k][l] + 1)
                    if l > 0:
                        DP[j][k][l - 1] = max(DP[j][k][l - 1], DP[j][k][l])
                else:
                    if j > 0:
                        DP[j - 1][k][l] = max(DP[j - 1][k][l], DP[j][k][l])
                    if k > 0:
                        DP[j][k - 1][l] = max(DP[j][k - 1][l], DP[j][k][l] + 3)
                    if l > 0:
                        DP[j][k][l - 1] = max(DP[j][k][l - 1], DP[j][k][l] + 1)
print(DP[0][0][0])
0