結果

問題 No.592 括弧の対応 (2)
ユーザー thesis_or_diethesis_or_die
提出日時 2017-11-24 21:06:37
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,359 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 77,448 KB
実行使用メモリ 67,388 KB
最終ジャッジ日時 2024-05-05 10:50:56
合計ジャッジ時間 8,986 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
41,284 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args){
        Main m = new Main();
        m.input();
        m.solve();
    }

    int n;
    String s;
    String[] sp;
    public void input(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        s = sc.next();
        sp = s.split("");
        sc.close();
    }

    int count;
    public void solve(){
        for(int i = 0; i < n; i++){
            if(sp[i].equals("(")){
                count = 1;
                for(int j = i + 1; j < n; j++){
                    if(sp[j].equals("(")){
                        count++;
                    }else{
                        count--;
                    }
                    if(count == 0){
                        System.out.println(j + 1);
                        break;
                    }
                }
            }else{
                count = 1;
                for(int j = i - 1; j >= 0; j--){
                    if(sp[j].equals(")")){
                        count++;
                    }else{
                        count--;
                    }
                    if(count == 0){
                        System.out.println(j + 1);
                        break;                        
                    }
                }
            }
        }
    }

}
0