結果

問題 No.22 括弧の対応
ユーザー ねずねず
提出日時 2018-01-28 22:53:37
言語 PHP
(8.3.4)
結果
AC  
実行時間 407 ms / 5,000 ms
コード長 542 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 12,012 KB
実行使用メモリ 12,380 KB
最終ジャッジ日時 2023-09-27 13:22:58
合計ジャッジ時間 2,785 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,300 KB
testcase_01 AC 7 ms
12,256 KB
testcase_02 AC 7 ms
12,324 KB
testcase_03 AC 125 ms
12,284 KB
testcase_04 AC 31 ms
12,224 KB
testcase_05 AC 24 ms
12,292 KB
testcase_06 AC 151 ms
12,264 KB
testcase_07 AC 32 ms
12,264 KB
testcase_08 AC 9 ms
12,244 KB
testcase_09 AC 134 ms
12,380 KB
testcase_10 AC 15 ms
12,240 KB
testcase_11 AC 25 ms
12,224 KB
testcase_12 AC 91 ms
12,304 KB
testcase_13 AC 407 ms
12,368 KB
testcase_14 AC 10 ms
12,300 KB
testcase_15 AC 87 ms
12,260 KB
testcase_16 AC 158 ms
12,300 KB
testcase_17 AC 7 ms
12,320 KB
testcase_18 AC 7 ms
12,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
function deleteBrackets (&$s, $len) {
	$left = -1;
	for ($i = 0; $i < $len; $i++) {
		if ($s[$i] == '-') continue;
		if ($left == -1) {
			if ($s[$i] == '(') $left = $i;
			continue;
		}
		if ($s[$i] == '(') {
			$left = $i;
		} else {
			$s[$left] = '-';
			$s[$i] = '-';
			return array($left + 1, $i + 1);
		}
	}
}
list($n, $k) = explode(' ', trim(fgets(STDIN)));
$s = trim(fgets(STDIN));
while (true) {
	$res = deleteBrackets($s, $n);
	if ($res[0] == $k || $res[1] == $k) {
		echo $res[0] == $k ? $res[1] : $res[0];
		break;
	}
}
?>
0