結果

問題 No.3142 Balancing with O=>X Flip
ユーザー msksknkn
提出日時 2025-06-28 18:48:04
言語 Java
(openjdk 23)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 498 bytes
コンパイル時間 2,825 ms
コンパイル使用メモリ 76,748 KB
実行使用メモリ 48,524 KB
最終ジャッジ日時 2025-06-28 18:48:13
合計ジャッジ時間 8,530 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

package no3142_balancing_with_flip_2;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int open = 0;
		boolean ok = true;
		for(int i = 0;i < n;i++) {
			if(s.charAt(i) == '(')open++;
			else {
				if(open == 0) {
					ok = false;
				}open--;
			}
		}if(open != 0)ok = false;
		System.out.print(ok ? "Yes":"No");
	}

}
0