結果

問題 No.154 市バス
コンテスト
ユーザー 紙ぺーぱー
提出日時 2016-06-20 01:10:53
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 400 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 936 ms
コンパイル使用メモリ 182,868 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-30 17:34:37
合計ジャッジ時間 1,783 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
bool f(string s){
  int w=0,g=0,r=0,R=0;
  for(auto x :s)R+=x=='R';
  bool ok=1;
  for(auto x :s){
    if(x=='G'){ g++; ok&=w>=g+r;}
    else if(x=='R'){g--;r++;ok&=g>=0;}
    else{w++; ok&=r+g<R;}
  }
  ok&=g==0&&r==R;
  return ok;
}
int main(){
 int T; cin>>T;
 while(T--){
    string s;cin>>s;
    if(!f(s))cout<<"im";
    cout<<"possible"<<endl;
 }
}
0