結果

問題 No.291 黒い文字列
ユーザー hirokazu1020hirokazu1020
提出日時 2015-10-16 23:46:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,452 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 92,368 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-29 02:01:41
合計ジャッジ時間 1,951 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:29:11: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 char *c = "KUROI";
           ^~~~~~~

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


char *c = "KUROI";

int count(string s) {
	int cnt = 0;
	while (1) {
		int i = 0;
		bool k = false;
		rep(j, s.size()) {
			if (c[i] == s[j]) {
				i++;
				if (i == 5) {
					i = 0;
					cnt++;
					k = true;
				}
				s[j] = '.';
			}
		}
		if (!k)break;
	}
	return cnt;
}
bool f(string s, int n) {
	int a[5] = {};
	rep(i, s.size()) {
		if (s[i] != '?') {
			if (s[i] == 'K')a[0]++;
			else if (s[i] == 'U'&&a[0]>a[1])a[1]++;
			else if (s[i] == 'R'&&a[1]>a[2])a[2]++;
			else if (s[i] == 'O'&&a[2]>a[3])a[3]++;
			else if (s[i] == 'I'&&a[3]>a[4])a[4]++;
		}
		else {
			rep(j, 5) {
				if (a[j]<n) {
					s[i] = c[j];
					a[j]++;
					break;
				}
			}
		}
	}
	return n <= count(s);
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int ans = 0;
	rep(i, s.size() / 5 + 1) {
		if (f(s, i))ans = i;
	}
	cout << ans << endl;

	return 0;
}
0