結果

問題 No.154 市バス
ユーザー mamekinmamekin
提出日時 2015-02-18 19:57:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 93,624 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:10:54
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

bool solve(const string& s)
{
    int n = s.size();
    vector<int> cnt(3, 0);
    int x = 0;
    for(int i=n-1; i>=0; --i){
        if(s[i] == 'R'){
            ++ cnt[0];
        }
        else if(s[i] == 'G'){
            ++ cnt[1];
            if(cnt[0] < cnt[1])
                return false;
            x = max(0, x) + 1;
        }
        else{
            if(cnt[1] == 0)
                return false;
            ++ cnt[2];
            -- x;
        }
    }

    if(cnt[0] == cnt[1] && cnt[1] <= cnt[2] && x <= 0)
        return true;
    else
        return false;
}

int main()
{
    int t;
    cin >> t;

    while(--t >= 0){
        string s;
        cin >> s;
        if(solve(s))
            cout << "possible" << endl;
        else
            cout << "impossible" << endl;
    }

    return 0;
}
0