結果

問題 No.154 市バス
ユーザー sugarrrsugarrr
提出日時 2018-03-10 23:26:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,520 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 80,392 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 18:31:11
合計ジャッジ時間 1,384 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)
const double EPS=1E-8;

////////////////////////////////////////


int main() {
    int n;cin>>n;
    while(n--){
        char s[1005];cin>>s;
        int len=strlen(s);
        bool flag=true;
        int x,y,z;x=y=z=0;
        for(int i=len-1;i>=0;i--){
            if(s[i]=='W'){
                x++;
                if(y==0||z==0)flag=false;
            }else if(s[i]=='G'){
                y++;
                if(y>z)flag=false;
            }else{
                z++;
            }
            if(!flag)break;
        }
        if(y!=z)flag=false;
        if(x<y)flag=false;
        x=y=z=0;
        for(int i=0;i<=len-1;i++){
            if(s[i]=='W'){
                x++;
            }else if(s[i]=='G'){
                y++;
                if(y>x)flag=false;
            }else{
                z++;
                if(z>x||z>y)flag=false;
            }
            if(!flag)break;
        }
        if(flag)cout<<"possible"<<endl;
        else cout<<"impossible"<<endl;
    }
    return 0;
}
0