結果

問題 No.154 市バス
ユーザー naimonon77naimonon77
提出日時 2016-02-05 23:05:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,068 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 66,712 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:07:29
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <set>
#include <string>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

bool possible(char S[]) {
  int i;
  int n = strlen(S);
  int Gcnt = 0,Rcnt = 0,Wcnt = 0;
  bool possible = true;
  // R より Gの方が先に来てないか判定
  rep(i,n) {
    if(S[i] == 'G') Gcnt++;
    else if(S[i] == 'R') Rcnt++;
    else Wcnt++;
    if(Gcnt < Rcnt) {
      possible = false;
      break;
    }
  }
  if(Rcnt != Gcnt) possible = false;
  if(S[n-1] != 'R') possible = false;
  for(i=n-2;i>-1;i--) {
    if(S[i] == 'W') possible = false;
    else if(S[i] == 'B') break;
  }
  // 3本以上走ってるか
  return possible;
}
int main(void)
{
  int i,j,k,l;
  int T;
  char S[1005] = "";
  cin >> T;
  while(cin >> S) {
    if(possible(S)) puts("possible");
    else puts("impossible");
  }
  return 0;
}
0