結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
kuramu
|
| 提出日時 | 2016-01-20 10:21:20 |
| 言語 | Java (openjdk 27.0.1.0.3 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 49 ms / 5,000 ms |
| + 822µs | |
| コード長 | 1,047 bytes |
| 記録 | |
| コンパイル時間 | 2,083 ms |
| コンパイル使用メモリ | 98,432 KB |
| 実行使用メモリ | 41,164 KB |
| 最終ジャッジ日時 | 2026-11-10 18:53:31 |
| 合計ジャッジ時間 | 4,261 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
try {
String[] elements = stdReader.readLine().split(" ");
int N = Integer.parseInt(elements[0]);
int K = Integer.parseInt(elements[1])-1;
String c = stdReader.readLine();
int count = 0;
if((""+c.charAt(K)).equals("(")){
for(int i=K;i<N;i++){
if((""+c.charAt(i)).equals("(")) count++;
else count--;
if(count == 0){
System.out.println(i+1);
break;
}
}
}else{
for(int i=K;0<=i;i--){
if((""+c.charAt(i)).equals(")"))count++;
else count--;
if(count == 0){
System.out.println(i+1);
break;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
kuramu