結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
AoiroFukurou
|
| 提出日時 | 2016-05-22 16:49:07 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 912 bytes |
| 記録 | |
| コンパイル時間 | 2,933 ms |
| コンパイル使用メモリ | 77,116 KB |
| 実行使用メモリ | 41,360 KB |
| 最終ジャッジ日時 | 2024-10-06 20:34:06 |
| 合計ジャッジ時間 | 6,373 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 5 RE * 2 |
ソースコード
package yukicoder;
import java.util.Scanner;
public class No22 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
sc.nextLine();
String S = sc.nextLine();
sc.close();
int c = 1;
String str = S.substring(K - 1, K);
if (str.equals("(")) {
while (true) {
str = S.substring(K, K + 1);
if (c == 0) {
System.out.println(K);
break;
} else if (str.equals("(")) {
c++;
K++;
} else if (str.equals(")")) {
c--;
K++;
}
}
} else if (str.equals(")")) {
int K2 = K - 1;
while (true) {
if(K2==0){
str = S.substring(K2,K2 + 1);
System.out.println(1);
break;
}
if (c == 0) {
System.out.println(K2 + 1);
break;
}else if (str.equals(")")) {
c++;
K2--;
} else if (str.equals("(")) {
c--;
K2--;
}
}
}
}
}
AoiroFukurou