結果

問題 No.154 市バス
ユーザー chakkuchakku
提出日時 2016-06-20 09:12:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 772 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 57,336 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:46:34
合計ジャッジ時間 1,482 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
6,816 KB
testcase_01 AC 27 ms
6,940 KB
testcase_02 AC 27 ms
6,940 KB
testcase_03 AC 26 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 24 ms
6,944 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void solve(){
    string s;cin>>s;
    int g=0,r=0,gr=0;
    int N=s.size();
    for(int i=0;i<N;i++){
        if(s[i]=='G'){
            g++;
            gr++;
        }
        if(s[i]=='R'){
            r++;
            gr--;
        }
        if(gr<0){
            cout << "impossible" <<endl;
            return;
        }
    }
    if(g!=r||g==0||r==0||s[N-1]!='R'){
        cout << "impossible" <<endl;
        return;
    }
    for(int i=N-1;i>=0;i--){
        if(s[i]=='G') break;
        if(s[i]=='W'){
            cout << "impossible" << endl;
            return;
        }
    }
    cout << "possible" << endl;
}

int main(){
    int T;
    cin>>T;
    for(int i=0;i<T;i++){
        solve();
    }
}
0