結果

問題 No.1961 Clear Brackets
コンテスト
ユーザー 👑 rin204
提出日時 2022-05-27 22:16:53
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 670 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 419 ms
コンパイル使用メモリ 95,824 KB
実行使用メモリ 84,096 KB
最終ジャッジ日時 2026-08-31 21:12:11
合計ジャッジ時間 6,624 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n = int(input())
S = input().strip()

ans = 0
mi = 0
tot = 0
flg = False
flg2 = False
for s in S:
    if s == "(":
        tot += 1
        flg = True
    elif s == ")":
        tot -= 1
        flg2 = True
        if tot < mi:
            mi = tot
            if flg:
                ans += 1
                flg = False
                flg2 = False
    else:
        if flg:
            tot -= 1
            flg2 = True
            if tot < mi:
                mi = tot
                if flg:
                    ans += 1
                    flg = False
                    flg2 = False
        else:
            tot += 1
            flg = True
ans += flg2
print(ans)
0