結果
| 問題 |
No.592 括弧の対応 (2)
|
| コンテスト | |
| ユーザー |
thesis_or_die
|
| 提出日時 | 2017-11-24 21:06:37 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,359 bytes |
| コンパイル時間 | 2,003 ms |
| コンパイル使用メモリ | 77,768 KB |
| 実行使用メモリ | 134,588 KB |
| 最終ジャッジ日時 | 2024-11-27 07:09:37 |
| 合計ジャッジ時間 | 16,524 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 TLE * 2 |
ソースコード
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;
}
}
}
}
}
}
thesis_or_die