結果

問題 No.3144 Parentheses Modification and Rotation (01 Ver.)
ユーザー 伟国姚
提出日時 2025-05-16 21:45:17
言語 Java
(openjdk 23)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,450 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 80,092 KB
実行使用メモリ 45,060 KB
最終ジャッジ日時 2025-06-28 12:47:21
合計ジャッジ時間 6,453 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

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 r = sc.nextInt(), m = sc.nextInt();
        int a = 0, b = 0;
        for (char c : s) {
            if (c == '(') a++;
            else b++;
        }
        if (n % 2 == 0) {
            out.println(Math.abs(a - (n / 2)));
        } else {
            out.println(-1);
        }

        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());
        }
    }
}
0