結果

問題 No.154 市バス
ユーザー alpha_virginisalpha_virginis
提出日時 2016-08-09 15:13:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 164,636 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:54:50
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

template<typename T> T in() { abort(); return T(); }
template<> std::string in() { std::string str; std::cin >> str; return str; }
template<> int in() { int x; scanf("%d", &x); return x; }

template<typename T> void out(T x) { abort(); }
template<> void out(const char* x) { printf("%s\n", x); }
template<> void out(std::string x) { std::cout << x << std::endl; }
template<> void out(int x) { printf("%d\n", x); }
template<> void out(long x) { printf("%ld\n", x); }

bool check(std::string str) {
  if( str.size() < 2 ) return false;
  if( str[(int)str.size()-1] != 'R' ) return false;
  for(int i = (int)str.size() - 1; i >= 0; --i) {
    if( str[i] == 'G' ) break;
    if( str[i] == 'W' ) return false;
  }  
  int nWr = 0, nG = 0, nR = 0;
  for(int i = 0; i < (int)str.size(); ++i) {
    if( str[i] == 'W' ) nWr += 1;
    if( str[i] == 'G' ) {
      nG += 1;
      nWr -= 1;
      if( nWr < 0 ) return false;
    }
    if( str[i] == 'R' ) nR += 1;
    if( not ( nR <= nG ) ) return false;
  }
  if( nR != nG ) return false;
  return true;
}

int main() {
  int n = in<int>(); 
  std::string str;
  for(int i = 0; i < n; ++i) {
    str = in<std::string>();
    out(check(str) ? "possible" : "impossible");
  }
  
  return 0;
}
0