結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-29 00:58:24 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 5,000 ms |
| コード長 | 908 bytes |
| コンパイル時間 | 1,934 ms |
| コンパイル使用メモリ | 76,540 KB |
| 実行使用メモリ | 37,192 KB |
| 最終ジャッジ日時 | 2024-07-20 07:12:20 |
| 合計ジャッジ時間 | 4,468 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
String[] str = br.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
String a = br.readLine();
int[] f = new int[n/2];
int[] l = new int[n/2];
int cnt = 0;
int pos = -1;
for(int i = 0; i < n; i++){
char c = a.charAt(i);
if(c=='('){
f[cnt]=i+1;
if(i+1==k)pos = cnt;
cnt++;
}else{
cnt--;
l[cnt]=i+1;
if(i+1==k){
sb.append(f[cnt]);
System.out.println(sb);
return;
}
if(pos==cnt){
sb.append(l[cnt]);
System.out.println(sb);
return;
}
}
}
}
}