結果

問題 No.154 市バス
ユーザー HAHAHAHAHAHA
提出日時 2015-07-03 13:08:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 84,788 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 08:39:31
合計ジャッジ時間 1,410 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<utility>
#include <fstream>
#include<set>
#include<map>
#include<cctype>
#include<cmath>
#include<algorithm>
using namespace std;


#define RALL(x) (x).rbegin(),(x).rend()
#define ALL(x) (x).begin(),(x).end()
#define repp(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define clr(a) memset((a), 0 ,sizeof(a))

typedef pair<int,int> P;
typedef vector<pair<int,string> > pii;
typedef map<string,int> mdi;


bool F(string s){
	vector<int> vc(3);
	int k,cnt=0;
	for(int i=s.size()-1;i>=0;i--){
		k=0;
		if(s[i]=='G') k=1;
		else if(s[i]=='R') k=2;
		vc[k]++;
		if(vc[0]!=0&&vc[1]==0) return false;
		else if(vc[0]!=0&&vc[2]==0) return false;
		else if(vc[2]<vc[1]) return false;
		else if(k==0) cnt=min(cnt+1,vc[1]);
	}
	if(vc[2]!=vc[1]) return false;
	else if(vc[0]<vc[1]) return false;
	else if(cnt!=vc[1]) return false;
	return true;
}

int main() {
	int n;
	string s;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s;
		if(F(s)) cout << "possible" << endl;
		else cout << "impossible" << endl;
	}
	return 0;
}
0