結果
| 問題 | 
                            No.154 市バス
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-03-05 11:17:40 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,127 bytes | 
| コンパイル時間 | 599 ms | 
| コンパイル使用メモリ | 64,936 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-23 14:11:24 | 
| 合計ジャッジ時間 | 1,680 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | WA * 1 | 
| other | AC * 7 WA * 1 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
bool solve(const std::string s) {
    int numG = std::count_if(s.begin(), s.end(), [](char c) { return c == 'G'; });
    int numR = std::count_if(s.begin(), s.end(), [](char c) { return c == 'R'; });
    if (numG != numR) return false;
    int num = numG;
    numG = 0;
    numR = 0;
    bool is_possible = true;
    for (const auto c : s) {
        if (c == 'W') {
            if (num < 1) {
                is_possible = false;
                break;
            }
        } else if (c == 'G') {
            numG++;
            num--;
        } else if (c == 'R') {
            numR++;
            if (numG < numR) {
                is_possible = false;
                break;
            }
        }
    }
    return is_possible;
}
int main(int argc, char const* argv[]) {
    int T;
    std::cin >> T;
    std::vector<std::string> s(T);
    for (int i = 0; i < T; i++) {
        std::cin >> s[i];
    }
    for (int i = 0; i < T; i++) {
        std::cout << (solve(s[i]) ? "possible" : "impossible") << std::endl;
    }
    return 0;
}