結果

問題 No.154 市バス
ユーザー mamekin
提出日時 2015-02-18 19:48:30
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 92,560 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-13 06:56:44
合計ジャッジ時間 1,336 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

bool solve(const string& s)
{
    int n = s.size();
    vector<int> cnt(3, 0);
    for(int i=n-1; i>=0; --i){
        if(s[i] == 'R'){
            ++ cnt[0];
        }
        else if(s[i] == 'G'){
            ++ cnt[1];
            if(cnt[0] < cnt[1])
                return false;
        }
        else{
            if(cnt[1] == 0)
                return false;
            ++ cnt[2];
        }
    }

    if(cnt[0] == cnt[1] && cnt[1] <= cnt[2])
        return true;
    else
        return false;
}

int main()
{
    int t;
    cin >> t;

    while(--t >= 0){
        string s;
        cin >> s;
        if(solve(s))
            cout << "possible" << endl;
        else
            cout << "impossible" << endl;
    }

    return 0;
}
0