結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー ygd.ygd.
提出日時 2021-06-13 00:33:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,069 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 12,152 KB
最終ジャッジ日時 2023-08-22 21:29:25
合計ジャッジ時間 7,334 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,152 KB
testcase_01 AC 16 ms
7,748 KB
testcase_02 AC 16 ms
7,736 KB
testcase_03 AC 18 ms
7,760 KB
testcase_04 AC 62 ms
8,256 KB
testcase_05 AC 274 ms
8,396 KB
testcase_06 TLE -
testcase_07 AC 90 ms
8,356 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input()); INF = float("inf")
    S = str(input())
    #dp[i][j]: S[i,j)でponを挿入した最大回数
    dp = [[0]*(N+1) for _ in range(N+1)]

    for l in range(N): #まず長さを決める
        for i in range(N-l): #0 ~ N-len-1
            j = i + l +1 #0~N
            for k in range(i,j+1,1): #kはi~jの間
                dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j])
                #本当は二つの遷移は微妙に範囲が違うので分けた方が良いかも。
                if i < k and k < j-1:
                    if S[i] == "p" and S[k] == "o" and S[j-1] == "n":
                        #print("A",i,k,j)
                        dp[i][j] = max(dp[i][j], dp[i+1][k] + dp[k+1][j-1] + 1)
                        #print("dp",dp[i][j])
                #print(i,k,j)
    #print(dp)
    ans = -1
    for i in range(N):
        if dp[0][i] >= 1 and dp[i][N] >= 1:
            temp = dp[0][i] + dp[i][N] - 2
            #print(i,temp)
            ans = max(ans, temp)

    print(ans)

if __name__ == '__main__':
    main()
0