結果

問題 No.154 市バス
ユーザー sei0osei0o
提出日時 2017-10-18 21:17:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 92,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 10:26:26
合計ジャッジ時間 1,726 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        string S;
        cin >> S;

        int w = 0, g = 0, r = 0, d = 0;
        bool possible = true;
        for (int k = 0; k < S.length(); k++) {
            switch (S[k]) {
                case 'W':
                    w++;
                    d++;
                    break;
                case 'G':
                    g++;
                    d = 0;
                    if (w < g) possible = false;
                    break;
                case 'R':
                    r++;
                    if (w < r || g < r) possible = false;
                    break;
            }
            if (!possible) break;
        }
        if (d > 0 || ((g == 0 || r == 0) && w > 0) || (g != r)) {
            possible = false;
        }

        cout << (possible ? "possible" : "impossible") << endl;
    }

    return 0;
}
0