結果

問題 No.154 市バス
ユーザー tubo28tubo28
提出日時 2015-02-17 23:46:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,400 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 162,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:41:15
合計ジャッジ時間 2,324 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
5,248 KB
testcase_01 AC 53 ms
5,376 KB
testcase_02 AC 52 ms
5,376 KB
testcase_03 AC 44 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 64 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

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

    int n;
    cin >> n;
    rep(_,n){
        string s;
        cin >> s;
        dump(s);
        typedef priority_queue<int> pq;
        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 = true;
        dump(w.size() , g.size(), r.size());
        if(s.back()=='W') ok = false;
        if(ok && (r.size()==0 || g.size()==0)) ok = false;
        if(ok && r.size() != g.size()) ok = false;
        // if(ok && w.size()%r.size() != 0) ok = false;
        dump(ok);
        while(ok && r.size()){
            int a = r.top();
            r.pop();
            if(g.size()==0){
                ok = false;
                break;
            }
            int b = g.top();
            g.pop();
            if(a < b){
                ok = false;
                break;
            }
        }
        puts(ok ? "possible" : "impossible");
    }
}
0