結果

問題 No.154 市バス
ユーザー mayoko_mayoko_
提出日時 2015-04-09 18:30:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,301 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 159,072 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 08:29:56
合計ジャッジ時間 1,962 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        int n = s.size();
        int g = 0, w = 0, r = 0;
        int cnt = 0;
        bool ng = false;
        bool after = false;
        for (int i = 0; i < n; i++) {
            switch (s[i]) {
                case 'W':
                    w++;
                    after = true;
                    break;
                case 'G':
                    g++;
                    if (w < g) {
                        ng = true;
                    }
                    break;
                case 'R':
                    r++;
                    if (g < r) {
                        ng = true;
                    } else if (r == g) {
                        after = false;
                    }
                    cnt++;
                    break;
            }
            if (ng) break;
        }
        if (g != r || cnt == 0 || after) ng = true;
        if (ng) cout << "impossible" << endl;
        else cout << "possible" << endl;
    }
    return 0;
}
0