結果

問題 No.154 市バス
ユーザー papinianuspapinianus
提出日時 2016-09-16 14:10:27
言語 PHP
(8.3.4)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,522 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 18,572 KB
実行使用メモリ 18,992 KB
最終ジャッジ日時 2023-08-03 12:01:39
合計ジャッジ時間 1,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
18,916 KB
testcase_01 AC 81 ms
18,992 KB
testcase_02 AC 80 ms
18,912 KB
testcase_03 AC 36 ms
18,752 KB
testcase_04 AC 78 ms
18,952 KB
testcase_05 AC 16 ms
18,988 KB
testcase_06 AC 16 ms
18,708 KB
testcase_07 AC 66 ms
18,948 KB
testcase_08 AC 16 ms
18,984 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