목차

괄호

ps
링크acmicpc.net/…
출처BOJ
문제 번호9012
문제명괄호
레벨실버 4
분류

괄호문자열

시간복잡도O(T*n)
인풋사이즈T<=?, n<=50
사용한 언어Python 3.13
제출기록32412KB / 48ms
최고기록32ms
해결날짜2025/02/16

풀이

코드

"""Solution code for "BOJ 9012. 괄호".

- Problem link: https://www.acmicpc.net/problem/9012
- Solution link: http://www.teferi.net/ps/problems/boj/9012
"""

from teflib import psutils


@psutils.run_n_times
def main():
    S = input()

    score = 0
    min_score = min(score := score + (1 if x == '(' else -1) for x in S)
    print('YES' if score == 0 and min_score >= 0 else 'NO')


if __name__ == '__main__':
    main()