結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-18 00:18:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 828 bytes |
| コンパイル時間 | 499 ms |
| コンパイル使用メモリ | 63,380 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 06:37:02 |
| 合計ジャッジ時間 | 1,170 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 2 WA * 6 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
int main() {
int t, w, g, r;
string s;
cin >> t;
vector<bool> ans(t, false);
for (int i = 0; i < t; i++) {
cin >> s;
int n = s.size();
bool isPossible;
w = g = r = 0;
for (int i = n - 1; i >= 0; i--) {
isPossible = true;
if (s[i] == 'W') {
w++;
} else if (s[i] == 'G') {
g++;
if (g <= w || g > r) {
isPossible = false;
break;
}
} else if (s[i] == 'R') {
r++;
if (r <= g || r <= w) {
isPossible = false;
break;
}
}
}
if (w == 0 || w < r || r != g) {
isPossible = false;
}
ans[i] = isPossible;
}
for (int i = 0; i < t; i++) {
cout << (ans[i] ? "possible" : "impossible") << endl;
}
return 0;
}