結果
問題 | No.154 市バス |
ユーザー | papinianus |
提出日時 | 2016-09-16 14:10:27 |
言語 | PHP (843.2) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 1,522 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 32,016 KB |
実行使用メモリ | 31,312 KB |
最終ジャッジ日時 | 2024-10-13 08:44:03 |
合計ジャッジ時間 | 1,292 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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--; }