結果

問題 No.154 市バス
ユーザー ty70ty70
提出日時 2015-05-27 12:23:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,519 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 94,516 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 08:32:56
合計ジャッジ時間 1,808 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);

	int T; cin >> T;
	while (T-- ){
		string S = ""; cin >> S;
		int w = (int)count (ALL (S ), 'W' );
		int g = (int)count (ALL (S ), 'G' );
		int r = (int)count (ALL (S ), 'R' );
		bool ok = true;
		if (g != r || (g == r && w < g ) ) ok = false;
		if (ok ){
			stack<char> st;
			rep (i, S.length() ){
				if (S[i] == 'G' ) st.push (S[i] );
				else
				if (S[i] == 'R' ){
					if (st.empty() ){
						ok = false;
						break;
					}else{
						st.pop();
					} // end if
				} // end if
			} // end rep
			if (!st.empty() ) ok = false;
		} // end if
		cout << (ok ? "possible" : "impossible" ) << endl;
	} // end while

	return 0;
}
0