結果

問題 No.22 括弧の対応
ユーザー beatdjambeatdjam
提出日時 2016-09-29 15:50:23
言語 PHP
(8.3.4)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 18,480 KB
実行使用メモリ 18,976 KB
最終ジャッジ日時 2023-09-27 13:08:56
合計ジャッジ時間 1,903 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
18,972 KB
testcase_01 AC 15 ms
18,776 KB
testcase_02 AC 13 ms
18,768 KB
testcase_03 AC 15 ms
18,976 KB
testcase_04 AC 15 ms
18,784 KB
testcase_05 AC 14 ms
18,736 KB
testcase_06 AC 15 ms
18,848 KB
testcase_07 AC 13 ms
18,716 KB
testcase_08 AC 13 ms
18,804 KB
testcase_09 AC 14 ms
18,844 KB
testcase_10 AC 14 ms
18,848 KB
testcase_11 AC 16 ms
18,968 KB
testcase_12 AC 16 ms
18,844 KB
testcase_13 AC 14 ms
18,796 KB
testcase_14 AC 15 ms
18,772 KB
testcase_15 AC 16 ms
18,872 KB
testcase_16 AC 15 ms
18,812 KB
testcase_17 AC 15 ms
18,772 KB
testcase_18 AC 15 ms
18,764 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$input_lines = trim(fgets(STDIN));
$input_lines = str_replace(array("\r\n","\r","\n"), "", $input_lines);
do {
    $tmpStr[] = $input_lines;
    $input_lines = trim(fgets(STDIN));
    $input_lines = str_replace(array("\r\n","\r","\n"), "", $input_lines);
} while ($input_lines !== "");

$tmp = $tmpStr[1];
$tmpPos = explode(" ",$tmpStr[0])[1];
$s = str_split($tmp);

$tmpCnt = 0;
if($s[$tmpPos - 1] === "("){
	$max = count($s);
	
	for($i = $tmpPos - 1;$i < $max ;$i++){
		$tmpCnt += getCountVal($s[$i]);
		
		if($tmpCnt === 0){
			break;
		}
	}
}else{
	for($i = $tmpPos - 1;$i >= 0 ;$i--){
		$tmpCnt += getCountVal($s[$i]);
		
		if($tmpCnt === 0){
			break;
		}
	}
}

print $i + 1;

function getCountVal($i_string){
		if($i_string === "("){
			return 1;
		}else{
			return -1;
		}
}
0