結果

問題 No.3142 Balancing with O=>X Flip
ユーザー norioc
提出日時 2025-05-16 21:58:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 303 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 62,928 KB
最終ジャッジ日時 2025-05-16 23:53:47
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = input()


def is_balanced(s: str) -> bool:
    d = 0
    for c in S:
        if c == '(':
            d += 1
        elif c == ')':
            if d == 0:
                return False
            d -= 1

    return d == 0


if is_balanced(S):
    print('Yes')
else:
    print('No')
0