結果
問題 |
No.22 括弧の対応
|
ユーザー |
![]() |
提出日時 | 2016-02-18 22:06:48 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 815 bytes |
コンパイル時間 | 2,536 ms |
コンパイル使用メモリ | 78,152 KB |
実行使用メモリ | 54,496 KB |
最終ジャッジ日時 | 2024-09-22 12:04:12 |
合計ジャッジ時間 | 6,081 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; } }