結果

問題 No.2276 I Want AC
ユーザー FromBooskaFromBooska
提出日時 2023-04-21 22:54:19
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 851,456 KB
最終ジャッジ日時 2024-04-24 08:56:19
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,224 KB
testcase_01 AC 42 ms
52,224 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 41 ms
52,224 KB
testcase_04 AC 42 ms
52,224 KB
testcase_05 AC 42 ms
52,096 KB
testcase_06 AC 41 ms
52,224 KB
testcase_07 AC 45 ms
52,096 KB
testcase_08 AC 41 ms
52,224 KB
testcase_09 AC 43 ms
52,352 KB
testcase_10 AC 41 ms
52,096 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 3次元dpはMLEした
# 1次元目と3次元目を交換してみる

N = int(input())
S = input()
INF = 10**10
dp = [[[-INF]*(N+1) for i in range(N+1)] for k in range(2)]
#dp = [[[-INF]*2 for j in range(N+1)] for i in range(N+1)]
dp[1][0][0] = 0
dp[0][0][0] = 0

for i in range(1, N+1):
    if S[i-1] == 'A':
        for j in range(N+1):
            if j+1 <= N:
                dp[0][i][j+1] = max(dp[0][i][j+1], dp[0][i-1][j])
                dp[0][i][j+1] = max(dp[0][i][j+1], dp[1][i-1][j])
    elif S[i-1] == 'C':
        for j in range(N+1):
            if j <= N:
                dp[1][i][j] = max(dp[1][i][j], dp[0][i-1][j]+j)
                dp[1][i][j] = max(dp[1][i][j], dp[1][i-1][j]+j)        
    elif S[i-1] == '?':
        for j in range(N+1):
            if j+1 <= N:
                dp[0][i][j+1] = max(dp[0][i][j+1], dp[0][i-1][j])
                dp[0][i][j+1] = max(dp[0][i][j+1], dp[1][i-1][j])
        for j in range(N+1):
            if j <= N:
                dp[1][i][j] = max(dp[1][i][j], dp[0][i-1][j]+j)
                dp[1][i][j] = max(dp[1][i][j], dp[1][i-1][j]+j)  
    #print(dp[i])

ans = 0
for j in range(N+1):
    for k in range(2):
        ans = max(ans, dp[k][N][j])
print(ans)
0