結果
問題 | No.22 括弧の対応 |
ユーザー | yun_app |
提出日時 | 2016-05-10 12:06:37 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 50 ms / 5,000 ms |
コード長 | 1,093 bytes |
コンパイル時間 | 2,021 ms |
コンパイル使用メモリ | 72,892 KB |
実行使用メモリ | 49,700 KB |
最終ジャッジ日時 | 2023-09-27 13:05:26 |
合計ジャッジ時間 | 3,874 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,416 KB |
testcase_01 | AC | 44 ms
49,372 KB |
testcase_02 | AC | 44 ms
49,328 KB |
testcase_03 | AC | 49 ms
49,388 KB |
testcase_04 | AC | 47 ms
49,228 KB |
testcase_05 | AC | 45 ms
49,288 KB |
testcase_06 | AC | 49 ms
49,700 KB |
testcase_07 | AC | 47 ms
49,296 KB |
testcase_08 | AC | 46 ms
49,384 KB |
testcase_09 | AC | 49 ms
49,360 KB |
testcase_10 | AC | 46 ms
49,292 KB |
testcase_11 | AC | 47 ms
49,384 KB |
testcase_12 | AC | 47 ms
49,356 KB |
testcase_13 | AC | 49 ms
47,404 KB |
testcase_14 | AC | 45 ms
49,488 KB |
testcase_15 | AC | 49 ms
49,492 KB |
testcase_16 | AC | 50 ms
49,424 KB |
testcase_17 | AC | 44 ms
49,248 KB |
testcase_18 | AC | 43 ms
49,216 KB |
ソースコード
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] lines = br.readLine().split(" "); int n = Integer.parseInt(lines[0]); int k = Integer.parseInt(lines[1])-1; String line = br.readLine(); Deque<Integer> deque = new ArrayDeque<Integer>(); for(int i=0;i<n;i++){ char c = line.charAt(i); if(c == '('){ deque.addFirst(i); }else if(c == ')'){ int t = deque.removeFirst(); if(t == k){ System.out.println(i+1); break; }else if(i == k){ System.out.println(t+1); break; } } } } }