結果

問題 No.154 市バス
ユーザー papinianuspapinianus
提出日時 2016-09-16 13:51:35
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,445 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 30,716 KB
実行使用メモリ 31,216 KB
最終ジャッジ日時 2024-04-21 09:56:31
合計ジャッジ時間 1,315 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
31,216 KB
testcase_01 AC 86 ms
30,984 KB
testcase_02 AC 86 ms
31,028 KB
testcase_03 AC 54 ms
31,016 KB
testcase_04 WA -
testcase_05 AC 43 ms
31,144 KB
testcase_06 AC 45 ms
31,020 KB
testcase_07 AC 76 ms
30,908 KB
testcase_08 AC 41 ms
31,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$trial = trim(fgets(STDIN));
while($trial)
{
    $ans = "im";
    while(true)
    {
        $str = trim(fgets(STDIN));
        $wpos = strpos($str, "W");
        $gpos = strpos($str, "G");
        $rpos = strpos($str, "R");
        $len = strlen($str);
        if($wpos !== 0 || $gpos === false || $rpos === false || $rpos < $gpos ) // must : start with w , g r exist , r after g
        {
            break;
        }
        $str = strrev($str);
        $len = strlen($str);
        $wpos = strpos($str, "W");
        $gpos = strpos($str, "G");
        $rpos = strpos($str, "R");
        if($rpos !== 0 || $wpos < $gpos) { break; }
        $wcount = substr_count($str, "W");
        $rcount = substr_count($str, "R");
        $gcount = substr_count($str, "G");
        if($rcount != $gcount || $wcount < $gcount) { break; } // must : num(r) = num(g) , num(w) >= num (g) and num (r)
        for($i = 0; $rcount && $gcount; $i++)
        {
            switch($str[$i])
            {
                case "R":
                    $rcount--;
                    break;
                case "G":
                    $gcount--;
                    break;
                case "W":
                    $wcount--;
            }
            if($rcount > $gcount || $wcount < $gcount) {break 2;} // too much g after r, too much w after g
        }
        $ans = "";
        break;
    }
    echo $ans."possible";
    echo PHP_EOL;
    $trial--;
}
0