結果

問題 No.22 括弧の対応
ユーザー Ruizi_LuigiRuizi_Luigi
提出日時 2015-07-24 23:04:30
言語 PHP
(8.3.4)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 508 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 32,544 KB
実行使用メモリ 32,800 KB
最終ジャッジ日時 2023-11-27 18:23:14
合計ジャッジ時間 2,516 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 46 ms
32,668 KB
testcase_02 AC 45 ms
32,668 KB
testcase_03 AC 46 ms
32,668 KB
testcase_04 AC 46 ms
32,668 KB
testcase_05 AC 46 ms
32,668 KB
testcase_06 AC 45 ms
32,668 KB
testcase_07 WA -
testcase_08 AC 45 ms
32,668 KB
testcase_09 WA -
testcase_10 AC 46 ms
32,668 KB
testcase_11 AC 45 ms
32,668 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 45 ms
32,668 KB
testcase_16 AC 45 ms
32,668 KB
testcase_17 AC 52 ms
32,668 KB
testcase_18 AC 45 ms
32,668 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-1), $search)) + 1) . "\n";
    }
0