結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
kuramu
|
| 提出日時 | 2016-01-20 10:21:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 5,000 ms |
| コード長 | 1,047 bytes |
| コンパイル時間 | 2,062 ms |
| コンパイル使用メモリ | 82,820 KB |
| 実行使用メモリ | 37,200 KB |
| 最終ジャッジ日時 | 2024-07-20 07:08:18 |
| 合計ジャッジ時間 | 3,859 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
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