結果

問題 No.154 市バス
ユーザー hogeover30hogeover30
提出日時 2015-02-18 00:51:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 435 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 63,624 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:57:03
合計ジャッジ時間 4,712 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <set>
using namespace std;
int main()
{
    int T; cin>>T;
    while (T--) {
        string s; cin>>s;
        int n=s.size();
        multiset<int> v;
        bool possible=true;
        for(int i=n-1;i>=0;--i) {
            if (s[i]=='R') {
                v.insert(1);
            }
            if (s[i]=='G') {
                if (v.empty() or *v.begin()!=1) { possible=false; break; }
                v.erase(v.begin());
                v.insert(2);
            }
            if (s[i]=='W') {
                if (!v.count(2) and !v.count(3)) { possible=false; break; }
                auto a=v.find(2), b=v.find(3);
                v.erase(a!=v.end()?a:b);
                v.insert(3);
            }
        }
        for(int a: v) if (a!=3) { possible=false; break; }
        cout<<(possible?"possible":"impossible")<<endl;
    }
}
0