結果

問題 No.154 市バス
ユーザー 👑 CleyL
提出日時 2020-02-05 20:30:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 625 ms
コンパイル使用メモリ 68,068 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 22:29:18
合計ジャッジ時間 1,454 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int t;cin>>t;
    while(t--){
        string s;cin>>s;
        reverse(s.begin(),s.end());
        int nw = 0;
        bool ok = false;
        bool ans = true;
        int wnw = 0;
        for(int i = 0; s.size() > i; i++){
            if(s[i] == 'R')nw++;
            else if(s[i] == 'G'){
                nw--;
                ok = true;
                if(nw < 0){
                    ans = false;
                    break;
                }
                wnw++;
            }else{
                wnw=max(0,wnw-1);
                if(!ok){
                    ans = false;
                    break;
                }
            }
        }
        cout << (ans&&ok&&!wnw&&!nw?"possible":"impossible") << endl;
    }
}
0