結果
| 問題 | No.154 市バス |
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-02-18 00:10:11 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 1,095 bytes |
| 記録 | |
| コンパイル時間 | 994 ms |
| コンパイル使用メモリ | 106,652 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-30 15:03:33 |
| 合計ジャッジ時間 | 2,488 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
void solve(){
char c[2000];
scanf("%s", c);
string s = c;
deque<int> w;
deque<int> g;
deque<int> r;
int n = s.size();
for(int i=0; i<n; i++){
if(s[i] == 'W'){
w.push_back(i);
}else if(s[i] == 'G'){
if(w.size() > 0){
w.pop_front();
g.push_back(i);
}else{
cout << "impossible" << endl;
return;
}
}else if(s[i] == 'R'){
if(g.size() > 0){
g.pop_front();
r.push_back(i);
}else{
cout << "impossible" << endl;
return;
}
}
}
if(g.size()>0 || r.size()==0){
cout << "impossible" << endl;
return;
}
if(w.size()>0 && r.size()>0 && w.back() > r.back()){
cout << "impossible" << endl;
return;
}
for(int i=r.back(); i>=0; i--){
if(s[i] == 'G') break;
else if(s[i] == 'W'){
cout << "impossible" << endl;
return;
}
}
cout << "possible" << endl;
}
int main(){
int T;
cin >> T;
while(T--){
solve();
}
}
koyumeishi