結果

問題 No.154 市バス
ユーザー papinianuspapinianus
提出日時 2016-09-16 14:10:27
言語 PHP
(8.3.4)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,522 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 30,896 KB
実行使用メモリ 31,320 KB
最終ジャッジ日時 2024-04-21 09:56:41
合計ジャッジ時間 1,347 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
31,320 KB
testcase_01 AC 84 ms
31,120 KB
testcase_02 AC 85 ms
31,100 KB
testcase_03 AC 54 ms
31,084 KB
testcase_04 AC 84 ms
31,240 KB
testcase_05 AC 39 ms
31,064 KB
testcase_06 AC 44 ms
30,972 KB
testcase_07 AC 73 ms
30,924 KB
testcase_08 AC 40 ms
31,136 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++) // check as long as far there's r or g so that w lacks (such like WGGwwwRR)
        {
            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