結果

問題 No.2145 Segment +-
ユーザー sotanishysotanishy
提出日時 2022-12-02 23:54:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 82,732 KB
実行使用メモリ 76,972 KB
最終ジャッジ日時 2024-04-18 09:01:13
合計ジャッジ時間 3,530 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,280 KB
testcase_01 AC 44 ms
52,568 KB
testcase_02 AC 42 ms
52,748 KB
testcase_03 AC 35 ms
53,192 KB
testcase_04 AC 38 ms
52,004 KB
testcase_05 AC 37 ms
52,568 KB
testcase_06 AC 44 ms
60,644 KB
testcase_07 AC 50 ms
59,784 KB
testcase_08 AC 51 ms
59,788 KB
testcase_09 AC 46 ms
59,420 KB
testcase_10 AC 212 ms
76,328 KB
testcase_11 AC 206 ms
76,972 KB
testcase_12 AC 40 ms
54,472 KB
testcase_13 AC 39 ms
54,116 KB
testcase_14 AC 39 ms
52,552 KB
testcase_15 AC 80 ms
76,316 KB
testcase_16 AC 64 ms
70,344 KB
testcase_17 AC 59 ms
67,420 KB
testcase_18 AC 69 ms
73,580 KB
testcase_19 AC 57 ms
68,040 KB
testcase_20 AC 183 ms
76,052 KB
testcase_21 AC 79 ms
75,968 KB
testcase_22 AC 63 ms
70,208 KB
testcase_23 AC 37 ms
52,796 KB
testcase_24 AC 186 ms
76,336 KB
testcase_25 AC 257 ms
76,436 KB
testcase_26 AC 246 ms
76,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
L = 30
dp0 = [-10**18] * L
dp1 = [-10**18] * L
dp0[0] = 0
for i in range(N):
    for j in range(L-1):
        dp1[j+1] = max(dp1[j+1], dp0[j])
    ndp0 = [-10**18] * L
    ndp1 = [-10**18] * L
    if S[i] != "-":
        for j in range(L):
            ndp0[j] = max(ndp0[j], dp0[j]+1)
            if dp1[j]-1 >= 0:
                ndp1[j] = max(ndp1[j], dp1[j]-1)
    if S[i] != "+":
        for j in range(L):
            if dp0[j]-1 >= 0:
                ndp0[j] = max(ndp0[j], dp0[j]-1)
            ndp1[j] = max(ndp1[j], dp1[j]+1)
    dp0 = ndp0
    dp1 = ndp1
    for j in range(L):
        dp0[j] = max(dp0[j], dp1[j])
ans = 0
while dp0[ans] < 0:
    ans += 1
print(ans)
0