結果

問題 No.154 市バス
ユーザー satanicsatanic
提出日時 2016-05-07 00:02:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 70,528 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:27:50
合計ジャッジ時間 1,343 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int t;
    std::cin >> t;
    for(int i=0; i<t; ++i){
        std::vector<int> imos;
        std::string str;
        std::cin >> str;
        int cntW = 0, cntG = 0, cntR = 0;
        bool flag = true;
        for(auto c : str){
            switch(c){
                case 'W': ++cntW; break;
                case 'G': imos.push_back( 1); ++cntG; --cntW; break;
                case 'R': imos.push_back(-1); ++cntR; break;
            }
            if(cntW<0){
                flag = false;
                break;
            }
        }
        std::cout << (([&]() -> bool {
            for(auto rit=str.rbegin(); rit!=str.rend(); ++rit){
                if(*rit=='W') return false;
                if(*rit=='G') break;
            }
            if(imos[0]==-1) return false;
            for(size_t j=1; j<imos.size(); ++j){
                imos[j] += imos[j-1];
                if(imos[j]<0) return false;
            }
            if(imos.back()!=0) return false;
            return true;
        }()&flag)? "possible\n" : "impossible\n");
    }
        
    return 0;
}
0