結果

問題 No.154 市バス
ユーザー chocoruskchocorusk
提出日時 2018-10-13 04:15:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,083 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 94,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 19:50:14
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
4,380 KB
testcase_01 AC 24 ms
4,380 KB
testcase_02 AC 25 ms
4,380 KB
testcase_03 AC 24 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int t;
	cin>>t;
	for(int i=0; i<t; i++){
		string s;
		cin>>s;
		vector<int> g, r;
		for(int j=0; j<s.size(); j++){
			if(s[j]=='G') g.push_back(j);
			else if(s[j]=='R') r.push_back(j);
		}
		if(g.size()!=r.size()){
			cout<<"impossible"<<endl;
			continue;
		}
		reverse(g.begin(), g.end());
		reverse(r.begin(), r.end());
		bool nuee=0;
		while(!g.empty()){
			if(g.back()>r.back()){
				cout<<"impossible"<<endl; nuee=1;
				break;
			}
			g.pop_back();
			r.pop_back();
		}
		if(nuee) continue;
		for(int j=s.size()-1; j>=0; j--){
			if(s[j]=='R') continue;
			if(s[j]!='G'){
				cout<<"impossible"<<endl; nuee=1;
				break;
			}
			break;
		}
		if(nuee) continue;
		cout<<"possible"<<endl;
	}
    return 0;
}
0