結果

問題 No.154 市バス
ユーザー LayCurseLayCurse
提出日時 2015-02-17 01:54:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 750 bytes
コンパイル時間 1,234 ms
コンパイル使用メモリ 158,180 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 07:30:51
合計ジャッジ時間 2,436 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
6,816 KB
testcase_01 AC 93 ms
6,944 KB
testcase_02 AC 91 ms
6,944 KB
testcase_03 AC 71 ms
6,940 KB
testcase_04 AC 84 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 99 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int T;
string S;

int main(){
  int i, j, k;
  int W, G, R;

  cin >> T;
  while(T--){
    cin >> S;
    for(;;){
      rep(R,S.size()) if(S[R]=='R') break;
      if(R==S.size()) break;
      rep(G,R) if(S[G]=='G') break;
      if(G==R) break;
      for(W=G;W>=0;W--) if(S[W]=='W') break;
      if(W<0) break;

      if(R==S.size()-1 && G==S.size()-2){
        rep(i,G) if(S[i]!='W') break;
        if(i==G) S = "";
        break;
      }

      S.erase(S.begin()+R);
      S.erase(S.begin()+G);
      S.erase(S.begin()+W);
//      cout << S << endl;
    }
    if(S.size()==0) puts("possible"); else puts("impossible");
  }

  return 0;
}
0