結果
問題 | No.2145 Segment +- |
ユーザー |
👑 |
提出日時 | 2023-10-09 22:28:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 682 bytes |
コンパイル時間 | 366 ms |
コンパイル使用メモリ | 82,148 KB |
実行使用メモリ | 85,376 KB |
最終ジャッジ日時 | 2024-07-26 20:53:30 |
合計ジャッジ時間 | 2,915 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 WA * 18 |
ソースコード
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)