結果

問題 No.22 括弧の対応
ユーザー michirumichiru
提出日時 2019-12-02 22:11:54
言語 PHP
(8.3.4)
結果
TLE  
実行時間 -
コード長 665 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 12,024 KB
実行使用メモリ 21,216 KB
最終ジャッジ日時 2023-08-16 10:55:53
合計ジャッジ時間 14,395 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
list($n, $k) = explode(" ", (trim(fgets(STDIN))));
$s = str_split(trim(fgets(STDIN)));
$count = 1;
 // "("始まりで"次が("ならカウンタを+1,")"なら-1,0になったら対応箇所
if ($s[$k-1] == "(") {
    while ($count > 0) {
        $p = $s[$k++];
        if ($p == "(") {
            $count++;
        } elseif ($p == ")") {
            $count--;
        }
    }
 // ")"始まりなら上記のカウンタ増加を逆にしただけ
} elseif ($s[$k-1] == ")") {
    while ($count > 0) {
        $p = $s[$k++];
        if ($p == "(") {
            $count--;
        } elseif ($p == ")") {
            $count++;
        }
    }
}

echo $k."\n";
0