結果

問題 No.154 市バス
ユーザー koba-e964koba-e964
提出日時 2015-06-06 18:13:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 77,776 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 10:02:43
合計ジャッジ時間 1,439 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

bool solve(const string &s) {
  int n = s.length();
  int w = 0, g = 0, r = 0;
  REP(i, 0, n) {
    switch(s[i]) {
    case 'W':
      w++; break;
    case 'G':
      g++; break;
    case 'R':
      r++; break;
    default:
      return 0;
    }
    if (w < g || w < r || g < r) {
      return 0;
    }
  }
  if (g != r || g == 0) {
    return 0;
  }
  w = g = r = 0;
  for (int i = n - 1; i >= 0; --i) {
    switch(s[i]) {
    case 'W':
      w++; break;
    case 'G':
      g++; break;
    case 'R':
      r++; break;
    default:
      return 0;
    }
    if (g > r || (g == 0 && w > 0)) {
      return 0;
    }
  }
  return 1;
}

int main(void){
  int t;
  cin >> t;
  REP (loop_var, 0, t) {
    string s;
    cin >> s;
    cout << (solve(s) ? "possible" : "impossible") << endl;
  }
}
0