結果

問題 No.22 括弧の対応
ユーザー Ruizi_LuigiRuizi_Luigi
提出日時 2015-07-24 23:01:26
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 508 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 18,584 KB
実行使用メモリ 19,096 KB
最終ジャッジ日時 2023-09-22 22:47:32
合計ジャッジ時間 2,750 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
18,892 KB
testcase_01 AC 16 ms
18,800 KB
testcase_02 AC 15 ms
18,748 KB
testcase_03 AC 17 ms
18,824 KB
testcase_04 AC 16 ms
18,796 KB
testcase_05 AC 16 ms
18,868 KB
testcase_06 AC 17 ms
18,852 KB
testcase_07 WA -
testcase_08 AC 16 ms
18,848 KB
testcase_09 AC 17 ms
18,912 KB
testcase_10 AC 17 ms
18,848 KB
testcase_11 AC 16 ms
18,864 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 15 ms
18,916 KB
testcase_15 AC 16 ms
18,820 KB
testcase_16 AC 17 ms
18,860 KB
testcase_17 AC 15 ms
18,620 KB
testcase_18 AC 16 ms
18,964 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

    list($N, $K) = explode(' ', trim(fgets(STDIN)));
    $S = trim(fgets(STDIN));

    $list = array(1);
    $pairing = 1;
    for ($i = 1; $i < $N; $i++) {
    	if ($S[$i] == $S[$i-1])
        	$pairing += ($S[$i] === "(" ? 1 : -1);	
    	$list[] = $pairing;
    }
    $search = $list[$K-1];
    if ($S[$K-1] === "(") {
    	echo (array_keys(array_slice($list, $K, NULL, true), $search)[0] + 1) . "\n";
    } else {
     	echo (end(array_keys(array_slice($list, 0, $K-2), $search)) + 1) . "\n";
    }
0