結果
問題 |
No.3142 Balancing with O=>X Flip
|
ユーザー |
|
提出日時 | 2025-05-16 21:35:19 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,475 bytes |
コンパイル時間 | 2,717 ms |
コンパイル使用メモリ | 80,292 KB |
実行使用メモリ | 45,100 KB |
最終ジャッジ日時 | 2025-05-16 21:35:28 |
合計ジャッジ時間 | 5,302 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 24 |
ソースコード
import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { int n = sc.nextInt(); char[] s = sc.next().toCharArray(); int a = 0; boolean ok = true; for (char c : s) { if (c == '(') a++; else { if (a == 0) { ok = false; break; } a--; } } out.println(ok?"Yes":"No"); out.close(); } static Kattio sc = new Kattio(); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static class Kattio { static BufferedReader r; static StringTokenizer st; public Kattio() { r = new BufferedReader(new InputStreamReader(System.in)); } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(r.readLine()); } return st.nextToken(); } catch (Exception e) { return null; } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }