結果

問題 No.154 市バス
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-05 01:49:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 54,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:49:35
合計ジャッジ時間 1,360 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int T;
string S;

/*
 * ありえないケースは
 * (1) w_cnt < g_cnt
 * (2) g_cnt < r_cnt
 * (3) 全て終わったあとに g_cnt != r_cnt
 * (4) 最後のWが出てから一度もGが出てきていない場合
 */
void Solve() {
    int w_cnt = 0, g_cnt = 0, r_cnt = 0;
    bool not_terminated = false;

    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'W') {
            w_cnt++;
            not_terminated = true;
        } else if (S[i] == 'G') {
            g_cnt++;
            not_terminated = false;
        } else {
            r_cnt++;
        }
        if (w_cnt < g_cnt || g_cnt < r_cnt) {
            cout << "impossible" << endl;
            return;
        }
    }
    if (!not_terminated && g_cnt == r_cnt) cout << "possible" << endl;
    else cout << "impossible" << endl;
}

int main() {
    cin >> T;

    while (T--) {
        cin >> S;

        Solve();
    }

    return 0;
}
0