結果

問題 No.3140 Weird Parentheses Game
ユーザー 伟国姚
提出日時 2025-05-16 21:23:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,736 bytes
コンパイル時間 3,881 ms
コンパイル使用メモリ 81,152 KB
実行使用メモリ 44,084 KB
最終ジャッジ日時 2025-05-16 21:24:08
合計ジャッジ時間 6,148 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        List<Integer> l = new ArrayList<>();
        Stack<Integer> st = new Stack<>();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            if (s[i] == '(') st.push(i);
            else {
                a[st.pop()] = i;
            }
        }
        int x = 0;
        while (x < n) {
            int r = a[x];
            l.add(r - x + 1);
            x = r + 1;
        }
        int xor = 0;
        for (int d : l) xor ^= d;
        out.println(xor!=0?"First":"Second");
        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