結果

問題 No.22 括弧の対応
ユーザー 綾地寧々綾地寧々
提出日時 2015-05-02 18:45:09
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 778 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 18,488 KB
実行使用メモリ 18,880 KB
最終ジャッジ日時 2023-09-19 05:01:59
合計ジャッジ時間 2,078 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,712 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 16 ms
18,564 KB
testcase_08 WA -
testcase_09 AC 16 ms
18,788 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 16 ms
18,720 KB
testcase_13 AC 16 ms
18,808 KB
testcase_14 AC 16 ms
18,800 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?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));
  echo "other({$other}): ";
  $str = substr($str,$point-1);
  echo $str."\n";
  for ( $index=0; $index<strlen($str); $index++ ) {
    if ( $str[$index] == '(' ) {
      echo ++$tree;
    }
    else {
      echo $tree--;
    }
    if ( $tree == 0 ) {
      echo "index({$index}): ";
      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;
    }
  }
}
0