結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
atkrym
|
| 提出日時 | 2016-11-07 18:07:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 185 ms / 5,000 ms |
| コード長 | 944 bytes |
| コンパイル時間 | 2,525 ms |
| コンパイル使用メモリ | 75,616 KB |
| 実行使用メモリ | 41,880 KB |
| 最終ジャッジ日時 | 2024-07-20 07:18:11 |
| 合計ジャッジ時間 | 6,624 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
import java.util.*;
public class Main {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws Exception {
int n = sc.nextInt();
int k = sc.nextInt();
String s = sc.next();
Stack<Pair> stack = new Stack<>();
for (int i = 1;i <= s.length();i++) {
char c = s.charAt(i-1);
Pair p;
if (c=='(') {
stack.push(new Pair(i==k,i));
} else {
p = stack.pop();
if (i==k) {
System.out.println(p.c);
return;
} else if (p.b) {
System.out.println(i);
return;
}
}
}
}
static class Pair {
boolean b;
int c;
public Pair(boolean b, int c) {
this.b = b;
this.c = c;
}
}
}
atkrym