結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,816 KB
testcase_01 AC 8 ms
6,940 KB
testcase_02 AC 8 ms
6,940 KB
testcase_03 AC 8 ms
6,944 KB
testcase_04 AC 8 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 5 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;
        bool ng = false;
        for (int i = 0; i < n; i++) {
            switch (s[i]) {
                case 'W':
                    w++;
                    break;
                case 'G':
                    w--;
                    if (w < 0) {
                        ng = true;
                    }
                    g++;
                    break;
                case 'R':
                    g--;
                    if (g < 0) {
                        ng = true;
                    }
                    break;
            }
            if (ng) break;
        }
        if (g > 0) ng = true;
        if (ng) cout << "impossible" << endl;
        else cout << "possible" << endl;
    }
    return 0;
}
0