結果

問題 No.154 市バス
ユーザー mocobtmocobt
提出日時 2018-06-09 20:45:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 65,604 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 02:22:35
合計ジャッジ時間 1,395 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

int main(){
    int T;
    cin >> T;
    for(int i=0; i<T; i++){
        string s;
        cin >> s;
        if(s.size()<3){
            cout << "impossible" << endl;
            continue;
        }
        
        auto r_cnt = 0, g_cnt = 0, w_cnt = 0;
        bool ans = true, f = false;
        for(int j=0;j<s.size();j++){
            switch(s[j]){
                case 'R':
                    r_cnt++;
                    break;
                case 'G':
                    f=true;
                    g_cnt++;
                    break;
                case 'W':
                    f=false;
                    w_cnt++;
                    break;
            }
            if(!(w_cnt>=g_cnt&&g_cnt>=r_cnt)){
                ans = false;
                break;
            }
        }
        if(g_cnt!=r_cnt||!f) ans = false;

        if(ans) cout<<"possible" << endl;
        else cout << "impossible" << endl;
    }
}
0