結果

問題 No.291 黒い文字列
ユーザー hiyokko2hiyokko2
提出日時 2015-10-16 23:32:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,725 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 69,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 01:58:06
合計ジャッジ時間 1,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(n) rep(i,n)
typedef long long ll;
using namespace std;


signed main()
{
	string S;
	queue<int> K;
	queue<int> U;
	queue<int> R;
	queue<int> O;
	queue<int> I;
	queue<int> Q;	//?
	
	cin >> S;
	for (int i=0; i<S.length(); i++)
	{
		switch (S[i])
		{
		case 'K':
			K.push(i);
			break;
		case 'U':
			U.push(i);
			break;
		case 'R':
			R.push(i);
			break;
		case 'O':
			O.push(i);
			break;
		case 'I':
			I.push(i);
			break;
		case '?':
			Q.push(i);
			break;
		}
	}
	
	bool exit = false;
	int ans = 0;
	while (1)
	{
		int k, u, r, o, i;
		if (K.empty())
		{
			if (Q.empty()) exit = true;
			else Q.pop();
		} else {
			k = K.front();
			if (U.empty())
			{
				if (Q.empty()) exit = true;
				else Q.pop();
			}
			u = U.front();
			K.pop();
			if (k < u)
			{
				if (R.empty())
				{
					if (Q.empty()) exit = true;
					else Q.pop();
				} else {
					r = R.front();
					if (O.empty())
					{
						if (Q.empty()) exit = true;
						else Q.pop();
					}
					o = O.front();
					R.pop();
					if (u < r)
					{
						if (O.empty())
						{
							if (Q.empty()) exit = true;
							else Q.pop();
						} else {
							o = O.front();
							if (I.empty())
							{
								if (Q.empty()) exit =true;
								else Q.pop();
							}
							i = I.front();
							O.pop();
							if (r < o)
							{
								if (I.empty())
								{
									if (Q.empty()) exit = true;
									else Q.pop();
								} else {
									i = I.front();
									if (o < i) ans++;
									I.pop();
								}
							}
						}
					}
				}
			}
		}
		
		if (exit) break;
	}
	
	cout << ans << endl;
	
	return 0;
}
0