結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-29 15:50:23 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 5,000 ms |
| コード長 | 789 bytes |
| コンパイル時間 | 952 ms |
| コンパイル使用メモリ | 31,024 KB |
| 実行使用メモリ | 31,216 KB |
| 最終ジャッジ日時 | 2024-07-20 07:16:51 |
| 合計ジャッジ時間 | 2,334 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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;
}
}