結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
hu_nbk
|
| 提出日時 | 2016-06-20 00:27:26 |
| 言語 | PHP (843.2) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,057 bytes |
| コンパイル時間 | 379 ms |
| コンパイル使用メモリ | 30,772 KB |
| 実行使用メモリ | 48,340 KB |
| 最終ジャッジ日時 | 2024-10-13 08:34:06 |
| 合計ジャッジ時間 | 6,807 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | TLE * 1 -- * 7 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php
$problems=fgets(STDIN);
for($problem=0;$problem<$problems;$problem++){
$input[$problem]=trim(fgets(STDIN));
}
for($problem=0;$problem<$problems;$problem++){
$str=$input[$problem];
$result=true;
$size=strlen($str);
for($i=0; $i<strlen($str); $i++) {$m[] = mb_substr($str, $i, 1, "UTF-8");}
//数が足りているかの確認 あと順番
$counter=0;
for($i=0;$i<$size;$i++){
if(iscolor($m,2,$i)){
$counter+=1;
}else if(iscolor($m,1,$i)){
$counter-=1;
}
}
if($counter!=0){print "impossible\n"; continue;}
//Gの後ろにRがない場合と前にWがない場合除去
$tempflag=true;
for($i=0;$i<$size;$i++){//Gを見つける
if(iscolor($m,1,$i)){
if(!((in_array("W",array_slice($m,0,$i)))&& (in_array("R",array_slice($m,$i))))){$result=false;break;}//適切でない場合
}
}
if($result==false){print "impossible\n";continue;}
//Rの後ろにWがある場合
for($i=0;$i<$size;$i++){
if(iscolor($m,2,$i)){
if(in_array("W",array_slice($m,$i))){$result=false;break;}
}
}
if($result==false){print "impossible\n";continue;}
//適切な順番に並んでいるか
for($i=$size-1;$i>=0;$i--){
if(iscolor($m,2,$i)){
//Rの場合
$j=0;
for($j=$i;$j>0;$j--){
//Gを埋める
if(iscolor($m,1,$j)){$m[$j]=3;break;}
}if($j==0){$result=false;break;}
for(;$j>=0;$j--){
//Wを埋める
if(iscolor($m,0,$j)){$m[$j]=4;break;}
if($j==0){$result=false;}
}
if($result==false){break;}
}
}
if($result==false){print "impossible\n";continue;}
//結果
print "possible\n";
}
function iscolor($array,$color,$num){
if(($array[$num]=="W" && $color==0)||($array[$num]=="G" && $color==1)||($array[$num]=="R" && $color==2)){
return true;
}else{
return false;
}
}
hu_nbk