結果

問題 No.154 市バス
ユーザー Iruyan_ZakIruyan_Zak
提出日時 2016-06-19 15:51:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 583 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 57,852 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 09:42:28
合計ジャッジ時間 1,602 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

string solve(string str){
    # define OK "possible"
    # define NG "impossible"
    int n = str.size(), w=0, g=0;
    if(str[n-1] != 'R') return NG;
    for(int i=0; i<n; ++i){
        char c = str[i];
             if(c == 'W') ++w;
        else if(c == 'G') ++g;
        else{
            --w, --g;
            if(w<0 || g<0) return NG;
        }
    }
    if(g != 0) return NG;
    return OK;

}

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; ++i){
		string str;
		cin >> str;
        cout << solve(str) << endl;
	}
}
0