結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー ygd.ygd.
提出日時 2021-06-13 00:28:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 80,436 KB
最終ジャッジ日時 2023-08-22 21:24:18
合計ジャッジ時間 16,118 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 109 ms
72,256 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 108 ms
71,932 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 107 ms
72,168 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)

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): #i~j
                if k > N or j > N: continue
                dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j])
                if k+1 > N or j > N: continue
                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