結果
問題 |
No.22 括弧の対応
|
ユーザー |
![]() |
提出日時 | 2017-06-11 22:41:52 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 765 bytes |
コンパイル時間 | 2,189 ms |
コンパイル使用メモリ | 75,060 KB |
実行使用メモリ | 56,220 KB |
最終ジャッジ日時 | 2024-09-24 16:37:04 |
合計ジャッジ時間 | 5,715 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 8 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); String s = sc.next(); int[] coresspond = new int[N]; int a = 0; int b = N - 1; while(a < b) { boolean flg = true; if(s.charAt(a + 1) == ')') { coresspond[a] = a + 1; coresspond[a + 1] = a; a += 2; flg = false; } if(s.charAt(b - 1) == '(') { coresspond[b] = b - 1; coresspond[b - 1] = b; b -= 2; flg = false; } if(flg) { coresspond[a] = b; coresspond[b] = a; a++; b--; } } System.out.println(coresspond[K - 1] + 1); } }