結果
問題 | No.22 括弧の対応 |
ユーザー | koukonko |
提出日時 | 2015-12-07 13:08:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 104 ms / 5,000 ms |
コード長 | 1,076 bytes |
コンパイル時間 | 1,978 ms |
コンパイル使用メモリ | 73,976 KB |
実行使用メモリ | 52,508 KB |
最終ジャッジ日時 | 2023-09-27 12:58:38 |
合計ジャッジ時間 | 4,239 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
49,260 KB |
testcase_01 | AC | 40 ms
49,372 KB |
testcase_02 | AC | 40 ms
49,628 KB |
testcase_03 | AC | 75 ms
52,204 KB |
testcase_04 | AC | 67 ms
52,244 KB |
testcase_05 | AC | 65 ms
52,056 KB |
testcase_06 | AC | 83 ms
52,076 KB |
testcase_07 | AC | 70 ms
52,508 KB |
testcase_08 | AC | 54 ms
51,244 KB |
testcase_09 | AC | 78 ms
51,996 KB |
testcase_10 | AC | 64 ms
51,964 KB |
testcase_11 | AC | 67 ms
51,672 KB |
testcase_12 | AC | 79 ms
51,984 KB |
testcase_13 | AC | 104 ms
52,384 KB |
testcase_14 | AC | 53 ms
51,064 KB |
testcase_15 | AC | 85 ms
52,096 KB |
testcase_16 | AC | 80 ms
51,688 KB |
testcase_17 | AC | 39 ms
49,724 KB |
testcase_18 | AC | 39 ms
49,364 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { String[] str = buff.readLine().split(" "); int N = Integer.parseInt(str[0]); int K = Integer.parseInt(str[1]) - 1; String s = buff.readLine(); StringBuilder line = new StringBuilder(s); boolean flag = true; int ans = -1; for (int i = 0; i < N && flag; ++i) { if (line.charAt(i) == '(') { for (int j = i + 1; j < N; ++j) { if (line.charAt(j) == '(') { break; } if (line.charAt(j) == ')') { if (i == K) { ans = j; flag = false; } else if (j == K) { ans = i; flag = false; } else { line.setCharAt(i, ' '); line.setCharAt(j, ' '); i = -1; } break; } } } } System.out.println(ans + 1); } catch (NumberFormatException e) { } catch (IOException e) { } } }