結果

問題 No.2145 Segment +-
ユーザー 👑 rin204rin204
提出日時 2023-10-09 22:28:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 682 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 85,872 KB
最終ジャッジ日時 2023-10-09 22:28:49
合計ジャッジ時間 4,498 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,268 KB
testcase_01 AC 60 ms
71,496 KB
testcase_02 AC 63 ms
71,248 KB
testcase_03 AC 77 ms
70,892 KB
testcase_04 AC 63 ms
71,400 KB
testcase_05 AC 64 ms
71,396 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 65 ms
71,192 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 65 ms
71,320 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 62 ms
71,224 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = list(input())
tot = 0
mi = False
ma = 0
ind = -1
for i, s in enumerate(S):
    if s == "+":
        tot += 1
    elif s == "-":
        tot -= 1
    else:
        tot += 1
    if tot < 0:
        if not mi:
            mi = True
            ind = i
    if mi:
        ma = max(ma, tot)

if not mi:
    print(0)
    exit()

for i in range(ind - 1, -1, -1):
    if S[i] == "?":
        if ma > 0:
            S[i] = "-"
            ma -= 1
        else:
            S[i] = "+"

if ma > 0:
    print(2)
    exit()
tot = 0
for i in range(ind):
    if S[i] == "+":
        tot += 1
    else:
        tot -= 1
    if tot < 0:
        print(2)
        exit()
print(1)
0