結果

問題 No.592 括弧の対応 (2)
ユーザー papinianuspapinianus
提出日時 2017-11-14 15:36:06
言語 PHP
(8.3.4)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 12,092 KB
実行使用メモリ 39,876 KB
最終ジャッジ日時 2023-08-16 13:05:13
合計ジャッジ時間 1,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,276 KB
testcase_01 AC 70 ms
39,788 KB
testcase_02 AC 62 ms
39,876 KB
testcase_03 AC 58 ms
37,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$devnull = 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 + 1;
        $structOfStr[$prevLeft] = $i + 1;
    }
}
ksort($structOfStr);
echo implode(PHP_EOL, $structOfStr);
echo PHP_EOL;
0