結果
問題 | No.22 括弧の対応 |
ユーザー | history_Bass |
提出日時 | 2017-03-03 13:11:56 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 166 ms / 5,000 ms |
コード長 | 1,086 bytes |
コンパイル時間 | 3,179 ms |
コンパイル使用メモリ | 73,900 KB |
実行使用メモリ | 56,240 KB |
最終ジャッジ日時 | 2023-09-27 13:12:40 |
合計ジャッジ時間 | 6,682 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 113 ms
56,240 KB |
testcase_01 | AC | 118 ms
56,092 KB |
testcase_02 | AC | 120 ms
55,792 KB |
testcase_03 | AC | 166 ms
55,772 KB |
testcase_04 | AC | 148 ms
54,300 KB |
testcase_05 | AC | 155 ms
55,660 KB |
testcase_06 | AC | 162 ms
56,044 KB |
testcase_07 | AC | 155 ms
55,760 KB |
testcase_08 | AC | 157 ms
55,992 KB |
testcase_09 | AC | 153 ms
55,980 KB |
testcase_10 | AC | 160 ms
55,724 KB |
testcase_11 | AC | 132 ms
55,784 KB |
testcase_12 | AC | 151 ms
56,064 KB |
testcase_13 | AC | 160 ms
55,580 KB |
testcase_14 | AC | 132 ms
56,204 KB |
testcase_15 | AC | 164 ms
56,172 KB |
testcase_16 | AC | 166 ms
55,644 KB |
testcase_17 | AC | 117 ms
55,852 KB |
testcase_18 | AC | 114 ms
55,416 KB |
ソースコード
import java.util.Scanner; public class arc { public static void main(String args[]){ //文字の読み込み Scanner sc=new Scanner(System.in); String line1=sc.nextLine(); String line2=sc.nextLine(); //文字の分割 String[] ch1=line1.split(" ",0);//ch1[0]=the amount ch1[1]=question String[] ch2=line2.split("",0);//arcs int judge=0; int i=Integer.parseInt(ch1[1]);//=Integer.parseInt(ch1[1]);//この括弧のついの括弧の番号を求める int j=Integer.parseInt(ch1[0]);//括弧の総数 if(ch2[i-1].equals("(")){ for(i=i-1;i<j;i++){ switch(ch2[i]){ case "(": judge++; break; case ")": judge--; break; } if(judge==0){ break; } if(i==(j-1)){ i=-1; } } }else if(ch2[i-1].equals(")")){ for(i=i-1;i<j;i--){ switch(ch2[i]){ case "(": judge++; break; case ")": judge--; break; } if(judge==0){ break; } if(i==(j-1)){ i=1; } } } System.out.println(i+1); } }