結果
問題 | No.22 括弧の対応 |
ユーザー | chiho_miyako |
提出日時 | 2015-04-10 12:58:57 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 125 ms / 5,000 ms |
コード長 | 1,049 bytes |
コンパイル時間 | 1,673 ms |
コンパイル使用メモリ | 72,040 KB |
実行使用メモリ | 56,340 KB |
最終ジャッジ日時 | 2023-09-27 12:51:42 |
合計ジャッジ時間 | 4,872 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 113 ms
56,052 KB |
testcase_01 | AC | 117 ms
55,484 KB |
testcase_02 | AC | 115 ms
56,096 KB |
testcase_03 | AC | 125 ms
56,340 KB |
testcase_04 | AC | 122 ms
55,736 KB |
testcase_05 | AC | 119 ms
56,012 KB |
testcase_06 | AC | 120 ms
55,996 KB |
testcase_07 | AC | 123 ms
56,156 KB |
testcase_08 | AC | 119 ms
56,052 KB |
testcase_09 | AC | 121 ms
55,900 KB |
testcase_10 | AC | 123 ms
56,156 KB |
testcase_11 | AC | 122 ms
56,264 KB |
testcase_12 | AC | 124 ms
56,192 KB |
testcase_13 | AC | 125 ms
55,720 KB |
testcase_14 | AC | 114 ms
55,840 KB |
testcase_15 | AC | 124 ms
56,292 KB |
testcase_16 | AC | 121 ms
55,672 KB |
testcase_17 | AC | 108 ms
56,008 KB |
testcase_18 | AC | 108 ms
56,092 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner koko = new Scanner(System.in); int n = koko.nextInt(); int x = koko.nextInt(); String a = koko.next(); char[] aa = a.toCharArray(); int count = 0; if(aa[x-1]=='('){ for(int i=0; i<n-x+1; i++){ if(aa[x-1+i]=='('){ count = count + 1; }else{ count = count - 1; if(count==0){ System.out.println(x+i); break; } } } }else{ for(int i=x-1; i>=0; i--){ if(aa[i]==')'){ count = count + 1; }else{ count = count - 1; if(count==0){ System.out.println(i+1); break; } } } } } }