====== 괄호 ====== ===== 풀이 ===== * 가장 기본적인 [[ps:tutorial:올바른 괄호 문자열]] 문제. * '('의 개수 - ')'의 개수가 항상 0 이상을 유지하다가 마지막에 0이 되는지를 확인하면 된다. 시간복잡도는 O(|S|) ===== 코드 ===== """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() {{tag>BOJ ps:problems:boj:실버_4}}