結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2016-02-18 22:06:48 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 815 bytes |
| 記録 | |
| コンパイル時間 | 2,079 ms |
| コンパイル使用メモリ | 83,860 KB |
| 実行使用メモリ | 44,116 KB |
| 最終ジャッジ日時 | 2026-04-10 18:00:49 |
| 合計ジャッジ時間 | 3,955 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 15 |
ソースコード
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner scan = new Scanner(System.in)) {
int N = scan.nextInt();
int K = scan.nextInt();
String S = scan.next();
ArrayList<Node> list = new ArrayList<>();
int count = 0;
for(int i=0; i<S.length(); i++) {
if(S.charAt(i) == '(') {
list.add(new Node(i+1));
count++;
} else if(S.charAt(i) == ')') {
count--;
list.get(count).end = i+1;
}
}
for(int i=0; i<list.size(); i++) {
if(list.get(i).first == K) {
System.out.println(list.get(i).end);
} else if(list.get(i).end == K) {
System.out.println(list.get(i).first);
}
}
}
}
}
class Node {
int first;
int end;
Node(int f) {
first = f;
end = -1;
}
}
jp_ste