結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-03-31 01:34:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,386 bytes |
| コンパイル時間 | 543 ms |
| コンパイル使用メモリ | 68,868 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 07:17:33 |
| 合計ジャッジ時間 | 1,383 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 6 WA * 1 RE * 1 |
ソースコード
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
void possible()
{
cout << "possible" << endl;
}
void impossible()
{
cout << "impossible" << endl;
}
void resolve(const string& s)
{
vector<string::size_type> index_list(s.length());
string::size_type indexR = string::npos;
string::size_type indexG = string::npos;
string::size_type indexW = string::npos;
int countR = 0;
int countG = 0;
int countW = 0;
for (string::size_type i = 0; i < s.length(); i++) {
char ch = s[i];
switch (ch) {
case 'R':
countR++;
index_list[i] = indexR;
indexR = i;
break;
case 'G':
countG++;
index_list[i] = indexG;
indexG = i;
break;
case 'W':
countW++;
index_list[i] = indexW;
indexW = i;
break;
}
}
if (countR != countG || countG > countW) {
impossible();
return;
}
while (countR > 0) {
if (countG > countW) {
impossible();
return;
}
if (indexR < indexG || indexG < indexW) {
impossible();
return;
}
indexR = index_list[indexR];
countR--;
indexG = index_list[indexG];
countG--;
do {
indexW = index_list[indexW];
countW--;
} while (indexW > indexG);
}
possible();
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
resolve(s);
}
return 0;
}