結果

問題 No.154 市バス
ユーザー HachimoriHachimori
提出日時 2015-02-18 00:45:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 61,532 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:55:54
合計ジャッジ時間 1,432 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
5,248 KB
testcase_01 AC 36 ms
5,376 KB
testcase_02 AC 35 ms
5,376 KB
testcase_03 AC 28 ms
5,376 KB
testcase_04 AC 34 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 26 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int ch2idx(char)’:
main.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
   19 | }
      | ^

ソースコード

diff #

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


string s;

void read() {
    cin >> s;
}


int ch2idx(char ch) {
    switch(ch) {
    case 'W': return 0;
    case 'G': return 1;
    case 'R': return 2;
    }
}

void work() {
    int val[3] = {0, 0, 0};
    
    for (int i = 0; i < s.size(); ++i) {
        ++val[ch2idx(s[i])];
        if (!(val[0] >= val[1] && val[1] >= val[2])) {
            cout << "impossible" << endl;
            return;
        }
    }

    vector<int> wIdx, gIdx;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'W') wIdx.push_back(i);
        if (s[i] == 'G') gIdx.push_back(i);
    }
    
    for (int i = 0, j = 0; i < wIdx.size(); ++i) {
        while (j < gIdx.size() && wIdx[i] > gIdx[j])
            ++j;
        if (j == gIdx.size()) {
            cout << "impossible" << endl;
            return;
        }
    }

    if (val[0] >= val[1] && val[1] == val[2] && val[2] > 0 && s[s.size() - 1])
        cout << "possible" << endl;
    else
        cout << "impossible" << endl;
}


int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        read();
        work();
    }
    return 0;
}
0