結果

問題 No.154 市バス
コンテスト
ユーザー hogeover30
提出日時 2016-06-12 02:20:59
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 18 ms / 2,000 ms
+ 350µs
コード長 857 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 314 ms
コンパイル使用メモリ 78,932 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-15 13:12:49
合計ジャッジ時間 1,459 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    int T; cin>>T;
    while (T--) {
        string s; cin>>s;
        reverse(begin(s), end(s));

        bool res=true;
        int a[3]={};
        for(auto& c: s) {
            if (c=='R') {
                ++a[0];
            }
            if (c=='G') {
                if (!a[0]) {
                    res=false; break;
                }
                else {
                    --a[0]; ++a[1];
                }
            }
            if (c=='W') {
                if (!a[1]) {
                    if (!a[2]) { res=false; break; }
                }
                else {
                    --a[1]; ++a[2];
                }
            }
        }
        if (a[0] or a[1]) res=false;

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