結果

問題 No.154 市バス
ユーザー tatsukawatatsukawa
提出日時 2016-07-22 19:41:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,460 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 161,092 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:53:46
合計ジャッジ時間 2,325 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

using namespace std;

typedef int64_t ll;

const int INF = 1e8;
const double EPS = 1e-10;

int main() {
    ios_base::sync_with_stdio(false);
    string s;
    int n;
    cin >> n;

    while(n--) {
        int r = 0, g = 0, w = 0;
        bool ok = true;
        cin >> s;

        for(int i = 0; i < s.size(); i++) {
            char c = s[i];
            if(c == 'W') {
                w++;
            }
            if(c == 'G') {
                g++;
                if(g > w) {
                    ok = false;
                }
            } 
            if(c == 'R') {
                r++;
                if(r > g) {
                    ok = false;
                }
            }
        }

        if(s.back() != 'R') ok = false;
        if(g > w) ok = false;
        if(r > g) ok = false;

        for(int i = 0; i < s.size(); i++) {
            char c = s[i];
            if(c == 'W') {
                if(r == 0 or g == 0) {
                    ok = false;
                }
                w--;
            }
            if(c == 'G') {
                if(r == 0) {
                    ok = false;
                }
                g--;
            }
            if(c == 'R') {
                r--;
            }
        }

        if(ok) {
            cout << "possible" << endl;
        } else {
            cout << "impossible" << endl;
        }

    }

}
0