結果

問題 No.154 市バス
ユーザー chakkuchakku
提出日時 2016-06-20 09:16:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 57,276 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:46:36
合計ジャッジ時間 1,225 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
        }
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        if(s[i]=='W') cnt++;
        if(s[i]=='G') cnt--;
        if(cnt<0){
            cout << "impossible" << endl;
            return;
        }
    }
    cout << "possible" << endl;
}

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