結果

問題 No.154 市バス
ユーザー tokkakatokkaka
提出日時 2016-07-18 16:01:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 94,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:50:44
合計ジャッジ時間 1,618 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>

using namespace std;

int main()
{
    int T;
    cin >> T;
    for(int i=0; i<T; i++) {
        string S;
        cin >> S;
        int g=0, r=0, w=0;
        for(auto c : S) {
            if(c=='G') g++;
            else if(c=='R') r++;
            else w++;
        }
        int count = 0;
        if(r != g) goto impossible;
        for(int i=0; i<S.size(); i++) {
            if(S[i]=='W') {
                S[i] = ' ';
                size_t gpos = S.find('G', i);
                if(gpos==string::npos) goto impossible;
                S[gpos] = ' ';
                size_t rpos = S.find('R', gpos);
                if(rpos==string::npos) goto impossible;
                S[rpos] = ' ';
                count++;
                if(count == g) {
                    if(rpos+1 < S.size() || S.find('W', gpos) != string::npos) goto impossible;
                    break;
                }
            } else if(S[i] != ' '){
                goto impossible;
            }
        }
        cout << "possible" << endl;
        continue;
impossible:
        cout << "impossible" << endl;
    }

    return 0;
}
0