結果

問題 No.154 市バス
ユーザー かにかに
提出日時 2016-02-01 00:47:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,754 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 162,952 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:07:27
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
5,248 KB
testcase_01 AC 24 ms
5,376 KB
testcase_02 AC 23 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
testcase_04 AC 24 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 23 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:76:17: warning: ‘lastg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   76 |             REP(j,lastg,s.length()){
      |                 ^

ソースコード

diff #

#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define pi 3.1415926535
#define IINF 1e9
#define LINF 1e18
#define vi vector<int>
#define mp make_pair

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

unsigned long long sttoi(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ull gcd(ull a, ull b){
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}

void solve() {
  int n;
  cin >> n;
  rep(i,n){
    string s;
    cin >> s;
    int green = 0;
    int g=0,r=0,w=0;
    bool f = false;
    bool atleast = false;
    int lastg;
    rep(j,s.length()){
      if(s[j] == 'G'){
        green++;
        g++;
        if(w < g){
          P("impossible");
          f = true;
          break;
        }
        atleast = true;
        lastg = j;
      }else if(s[j] == 'R'){
        green--;
        r++;
        if(green < 0){
          P("impossible");
          f = true;
          break;
        }
      }else{
        w++;
      }
    }
    if(!f)
      {
        if(green == 0)
          {
            
            if(!atleast){
              P("impossible");
              continue;
            }
            bool f2 = false;
            REP(j,lastg,s.length()){
              if(s[j]=='W')f2 = true;
            }
            if(f2){
              P("impossible");
            }else{
              P("possible");
            }
          }else{
            P("impossible");
          }
      }
  }
}

int main() {
	solve();
	return 0;
}
0