結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2016-06-02 16:46:04 |
言語 | PHP (843.2) |
結果 |
AC
|
実行時間 | 44 ms / 5,000 ms |
コード長 | 402 bytes |
コンパイル時間 | 2,332 ms |
コンパイル使用メモリ | 30,636 KB |
実行使用メモリ | 32,012 KB |
最終ジャッジ日時 | 2024-07-20 07:13:41 |
合計ジャッジ時間 | 3,716 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php list($len, $target) = explode(' ', trim(fgets(STDIN))); $str = str_split(trim(fgets(STDIN))); $lefts = []; $structOfStr = []; foreach($str as $i => $char) { if($char == '(') { array_push($lefts, $i); } else { // ')' $prevLeft = array_pop($lefts); $structOfStr[$i] = $prevLeft; $structOfStr[$prevLeft] = $i; } } echo ($structOfStr[$target-1]+1).PHP_EOL;