結果

問題 No.154 市バス
コンテスト
ユーザー tokkaka
提出日時 2016-07-18 15:02:48
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,320 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 895 ms
コンパイル使用メモリ 106,220 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-30 17:39:26
合計ジャッジ時間 2,150 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 2 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:24:13: warning: 'g' may be used uninitialized [-Wmaybe-uninitialized]
   24 |         int g, r, w;
      |             ^
main.cpp:24:16: warning: 'r' may be used uninitialized [-Wmaybe-uninitialized]
   24 |         int g, r, w;
      |                ^
main.cpp:24:19: warning: 'w' may be used uninitialized [-Wmaybe-uninitialized]
   24 |         int g, r, w;
      |                   ^

ソースコード

diff #
raw source code

#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, r, w;
        for(auto c : S) {
            if(c=='G') g++;
            else if(c=='R') r++;
            else w++;
        }
        int index = 0;
        if(r != g) goto impossible;
        while(r < w) {
            if(S[index] == 'W') {
                S[index] = ' ';
                w--;
            }
            index++;
        }
        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] = ' ';
            } else if(S[i] != ' '){
                goto impossible;
            }
        }
        cout << "possible" << endl;
        continue;
impossible:
        cout << "impossible" << endl;
    }

    return 0;
}
0