結果

問題 No.154 市バス
ユーザー mizzsigmizzsig
提出日時 2018-02-04 15:28:44
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 32,016 KB
実行使用メモリ 32,144 KB
最終ジャッジ日時 2024-04-21 10:32:02
合計ジャッジ時間 1,652 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
30,928 KB
testcase_01 AC 89 ms
30,852 KB
testcase_02 AC 88 ms
31,124 KB
testcase_03 WA -
testcase_04 AC 88 ms
30,756 KB
testcase_05 AC 44 ms
30,936 KB
testcase_06 AC 44 ms
31,264 KB
testcase_07 AC 84 ms
31,328 KB
testcase_08 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
  $n = trim(fgets(STDIN));

  for ($i = 0; $i < $n; $i++) {
    $str = trim(fgets(STDIN));

    $length = strlen($str);

    $isPossible = true;
    $noMustW = 0;
    $w = 0;
    $g = 0;
    // 各バスの状態を保存する
    $bus = [];

    // それぞれのテストケースを確認
    for ($l = 0; $l < $length; $l++) {
      switch ($str[$l]) {
        case 'W':
          if ($w == 0) { $w++; }
          else { $noMustW++; }
          break;
        case 'G':
          if ($w > 0) {
              $w--;
              $g++;
          } else if ($noMustW > 0) {
              $noMustW--;
              $g++;
          } else $isPossible = false;
          break;
        case 'R':
          if ($g > 0) {
              $g--;
          } else $isPossible = false;
          break;
      }
      if (!$isPossible) break;
    }

    // 結果出力
    if ($isPossible && ($w == 0)) {
        echo 'possible' . "\n";
    } else {
        echo 'impossible' . "\n";
    }
  }
0