結果

問題 No.154 市バス
ユーザー 0w10w1
提出日時 2016-11-21 00:22:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 165,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 12:05:20
合計ジャッジ時間 2,419 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,376 KB
testcase_01 AC 25 ms
4,376 KB
testcase_02 AC 25 ms
4,376 KB
testcase_03 AC 25 ms
4,376 KB
testcase_04 AC 25 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 22 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const string msg[] = { "impossible", "possible" };

signed main(){
  int T; cin >> T;
  for( int i = 0; i < T; ++i ){
    int ng = 0;
    string S; cin >> S;
    int w = 0, g = 0, r = 0, zg = 0;
    for( int j = S.size() - 1; j >= 0; --j ){
      if( S[ j ] == 'R' ) ++r;
      if( S[ j ] == 'G' ){
        if( --r < 0 ) ng = 1;
        ++g, ++zg;
      }
      if( S[ j ] == 'W' ){
        if( g == 0 ) ng = 1;
        if( zg > 0 ) --zg;
      }
    }
    ng |= zg > 0;
    ng |= r > 0;
    cout << msg[ not ng ] << endl;
  }
  return 0;
}
0