結果

問題 No.154 市バス
ユーザー ebicochinealebicochineal
提出日時 2016-06-20 19:29:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 65,504 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:46:53
合計ジャッジ時間 1,477 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
    string s;
    cin >> s;
    while ( cin >> s ) {
        int w = 0, g = 0, r = 0, l = 0;
        for ( char i : s ) { l += i == 'R' ? 1 : 0; }
        int f = s[0] != 'W' ? 1 : 0;
        for ( char i : s ) {
            if ( i == 'W' ) {
                w += 1;
                if ( l == 0 ) {
                    f = 1;
                }
            }
            if ( i == 'G' ) {
                if ( l > 0 && w > 0 ) {
                    w -= 1; l -= 1; g += 1;
                } else {
                    f = 1;
                }
            }
            if ( i == 'R' ) {
                if ( g > 0 ) {
                    g -= 1; r += 1;
                } else {
                    f = 1;
                }
            }
            if ( f ) { break; }
        }
        string o = !f && g == 0 ? "possible" : "impossible";
        cout << o << endl;
    }
    return 0;
}
0