結果

問題 No.154 市バス
ユーザー sekiya9311sekiya9311
提出日時 2016-06-12 00:57:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,670 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 104,024 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:34:32
合計ジャッジ時間 1,637 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>

#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(long (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(long (i)=(a)-1;(i)>=(b);(i)--)
#define MOD 1000000007
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define PII pair<int,int>
#define PLL pair<long,long>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).begin(),(a).end(),greater<int>())

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

bool func(string s){
    if(s[0]!='W'||s.back()!='R') return false;
    int gcnt=0,rcnt=0,wcnt=0,bus=0;

    RREP(i,s.size()){
        if(s[i]=='R') {
            rcnt++;
        }
        if(s[i]=='G') {
            gcnt++;
            if(!rcnt) return false;
            rcnt--;
        }
        if(s[i]=='W') {
            if(!gcnt && !wcnt) return false;
            if(gcnt>0){
                gcnt--; wcnt++;
            }

        }
    }
    return !rcnt && !gcnt;
}

int main(void){
    int T; cin>>T;
    vector<string> S(T);
    REP(i,T) cin>>S[i];
    REP(i,T){
        if(func(S[i])) cout<<"possible"<<endl;
        else cout<<"impossible"<<endl;
    }
}
0