結果

問題 No.154 市バス
ユーザー 小指が強い人小指が強い人
提出日時 2015-11-23 18:35:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 52,772 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 11:04:54
合計ジャッジ時間 1,282 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        string str;
        cin >> str;
        int stack = 0;
        int wstack = 0;
        int size = str.size();
        bool flag = false;
        if(size < 3 || str[size - 1] == 'W')
        {
            cout <<  "impossible" << endl;
            continue;
        }
        for(int j = 0; j < size; j++)
        {
            if(str[j] == 'G')
            {
                stack++;
                wstack--;
                flag = false;
                if(wstack < 0)
                    break;
            }
            else if(str[j] == 'R')
            {
                stack--;
                if(stack < 0)
                    break;
            }
            else if(str[j] == 'W')
            {
                wstack++;
                flag = true;
            }
        }
        if(stack == 0 && wstack >= 0 && !flag)
            cout << "possible" << endl;
        else
            cout << "impossible" << endl;
    }
    return 0;
}
0