結果

問題 No.154 市バス
ユーザー tubo28tubo28
提出日時 2015-02-18 00:22:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,318 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 169,824 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 07:52:19
合計ジャッジ時間 2,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

typedef priority_queue<int> pq;

string s;
bool check1(pq w, pq g, pq r){
    if(r.size()==0 || g.size()==0) return false;
    if(r.size() != g.size()) return false;

    while(1){
        int a,b,c;
        if(min({w.size(),g.size(),r.size()})==0){
            break;
        }
        tie(a,b,c) = tie(w.top(),g.top(),r.top());
        a=-a, b=-b, c=-c;
        dump(a,b,c);
        w.pop(),g.pop(),r.pop();
        if(a < b && b < c) continue;
        return false;
    }

    bool ok = true;
    if(g.size() || r.size()) ok = false;

    int n=s.size();
    if(s[n-1]=='W') return false;
    if(s[n-2]=='W') return false;

    return ok;
}


int main(){
#ifdef LOCAL
    freopen("in","r",stdin);
#endif


    int n;
    cin >> n;
    rep(_,n){
        cin >> s;
        dump(s);
        pq r,g,w;
        rep(i,s.size()){
            if(s[i]=='R') r.push(-i);
            if(s[i]=='G') g.push(-i);
            if(s[i]=='W') w.push(-i);
        }
        bool ok = check1(w,g,r);
        puts(ok ? "possible" : "impossible");
    }
}
0