結果

問題 No.154 市バス
ユーザー snrnsidysnrnsidy
提出日時 2021-03-07 20:44:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,359 bytes
コンパイル時間 1,339 ms
コンパイル使用メモリ 122,236 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 10:46:15
合計ジャッジ時間 2,066 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
		bool flag1 = true;
		bool flag2 = true;
		bool flag3 = false;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'W')
			{
				flag1 = false;
				w++;
			}
			else if (s[i] == 'G')
			{
				if (w == 0)
				{
					ok = false;
					break;
				}
				flag1 = true;
				flag2 = false;
				g++;
				w--;
			}
			else
			{
				if (g == 0)
				{
					ok = false;
					break;
				}
				flag2 = true;
				flag3 = true;
				r++;
				g--;
			}
		}
		if (s[n - 1] != 'R' || s[0] != 'W')
		{
			ok = false;
		}
		if (!flag1 || !flag2 || !flag3)
		{
			ok = false;
		}
		if (g > 0)
		{
			ok = false;
		}
		if (!ok)
		{
			cout << "impossible" << '\n';
		}
		else
		{
			cout << "possible" << '\n';
		}
	}
	return 0;
}
0