結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-18 00:45:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,165 bytes |
| コンパイル時間 | 522 ms |
| コンパイル使用メモリ | 61,400 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 06:40:45 |
| 合計ジャッジ時間 | 1,296 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
コンパイルメッセージ
main.cpp: In function ‘int ch2idx(char)’:
main.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
19 | }
| ^
ソースコード
#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;
}