結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-02 18:48:00 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 5,000 ms |
| コード長 | 690 bytes |
| コンパイル時間 | 1,163 ms |
| コンパイル使用メモリ | 31,016 KB |
| 実行使用メモリ | 31,132 KB |
| 最終ジャッジ日時 | 2024-07-20 06:59:52 |
| 合計ジャッジ時間 | 2,716 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php
list($length, $point) = explode(" ",trim(fgets(STDIN)));
$tree = 0;
$str = trim(fgets(STDIN));
if ( $str[$point-1] == '(' ) {
$other = strlen(substr($str,0,$point-1));
$str = substr($str,$point-1);
for ( $index=0; $index<strlen($str); $index++ ) {
if ( $str[$index] == '(' ) {
++$tree;
}
else {
$tree--;
}
if ( $tree == 0 ) {
echo $other + $index+1 . PHP_EOL;
break;
}
}
}
else {
$str = substr($str,0,$point);
for ( $index=$point-1; $index>=0; $index-- ) {
if ( $str[$index] == '(' ) {
++$tree;
}
else {
$tree--;
}
if ( $tree == 0 ) {
echo $index +1 . PHP_EOL;
break;
}
}
}