結果

問題 No.154 市バス
ユーザー snrnsidy
提出日時 2021-03-07 20:36:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,225 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 120,124 KB
最終ジャッジ日時 2025-01-19 12:50:05
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int T;

	cin >> T;

	while (T--)
	{
		string s;
		cin >> s;
		int n = s.length();
		int w = 0;
		int g = 0;
		int r = 0;
		bool ok = true;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'W')
			{
				w++;
			}
			else if (s[i] == 'G')
			{
				if (w == 0)
				{
					ok = false;
					break;
				}
				g++;
				w--;
			}
			else
			{
				if (g == 0)
				{
					ok = false;
					break;
				}
				r++;
				g--;
			}
		}
		if (s[n - 1] != 'R' || s[0] != 'W')
		{
			ok = false;
		}
		for (int i = 1; i < n; i++)
		{
			if (s[i - 1] == 'W' && s[i] == 'R')
			{
				ok = false;
				break;
			}
		}
		if (!ok)
		{
			cout << "impossible" << '\n';
		}
		else
		{
			cout << "possible" << '\n';
		}
	}
	return 0;
}
0