結果

問題 No.154 市バス
ユーザー yomayoma
提出日時 2019-10-19 14:13:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 166,352 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 10:33:43
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int T;
    cin >> T;
    for(int i = 0;i < T;i++){
        string s;
        cin >> s;
        bool ans = true;
        int w = 0, g = 0, r = 0, cnt = 2;
        for(int j = 0;j < s.size();j++){
            if(s[j] == 'W'){
                w++;
                cnt = 2;
            }else if(s[j] == 'G'){
                g++;
                if(g > w)   ans = false;
                if(cnt == 2)    cnt--;
            }else{
                r++;
                if(r > g)   ans = false;
                if(cnt == 1)    cnt--;
            }
        }
        if(r != g || g == 0 || cnt != 0)  ans = false;
        if(ans) cout << "possible" << endl;
        else    cout << "impossible" << endl;
    }
}
0