結果

問題 No.291 黒い文字列
ユーザー krotonkroton
提出日時 2015-06-18 00:27:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 55,412 KB
実行使用メモリ 5,016 KB
最終ジャッジ日時 2023-09-21 09:24:43
合計ジャッジ時間 1,712 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,868 KB
testcase_01 AC 3 ms
4,852 KB
testcase_02 AC 4 ms
4,832 KB
testcase_03 AC 3 ms
4,828 KB
testcase_04 AC 3 ms
4,864 KB
testcase_05 AC 4 ms
5,016 KB
testcase_06 AC 3 ms
4,832 KB
testcase_07 AC 4 ms
4,820 KB
testcase_08 AC 3 ms
4,820 KB
testcase_09 AC 3 ms
4,972 KB
testcase_10 AC 4 ms
4,876 KB
testcase_11 AC 4 ms
4,824 KB
testcase_12 AC 4 ms
4,876 KB
testcase_13 AC 3 ms
4,828 KB
testcase_14 AC 4 ms
4,844 KB
testcase_15 AC 3 ms
4,872 KB
testcase_16 AC 9 ms
4,932 KB
testcase_17 AC 9 ms
4,928 KB
testcase_18 AC 9 ms
5,000 KB
testcase_19 AC 11 ms
4,876 KB
testcase_20 AC 11 ms
5,008 KB
testcase_21 AC 7 ms
4,916 KB
testcase_22 AC 11 ms
4,824 KB
testcase_23 AC 12 ms
4,824 KB
testcase_24 AC 10 ms
4,864 KB
testcase_25 AC 9 ms
4,820 KB
testcase_26 AC 8 ms
4,824 KB
testcase_27 AC 7 ms
4,876 KB
testcase_28 AC 6 ms
4,876 KB
testcase_29 AC 7 ms
4,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;

bool useable(char c, char required) {
	return (c == required || c == '?');
}
void update(int &a, int b){
	if(b > a)a = b;
}

int dp[2][21][21][21][21];

int main() {
	string S;
	cin >> S;

	int crr = 0, nxt = 1;

	memset(dp[crr], -1, sizeof(dp[crr]));
	dp[crr][0][0][0][0] = 0;

	for(char c : S) {
		memset(dp[nxt], -1, sizeof(dp[nxt]));

		for(int K=0;K<=20;K++)
		for(int U=0;U<=K;U++)
		for(int R=0;R<=U;R++)
		for(int O=0;O<=R;O++){
			int now = dp[crr][K][U][R][O];
			if(now == -1)
				continue;

			update(dp[nxt][K][U][R][O], now);

			if(useable(c, 'K') && K + 1 <= 20)
				update(dp[nxt][K+1][U][R][O], now);
			if(useable(c, 'U') && U + 1 <= K)
				update(dp[nxt][K][U+1][R][O], now);
			if(useable(c, 'R') && R + 1 <= U)
				update(dp[nxt][K][U][R+1][O], now);
			if(useable(c, 'O') && O + 1 <= R)
				update(dp[nxt][K][U][R][O+1], now);

			if(useable(c, 'I') && now + 1 <= O)
				update(dp[nxt][K][U][R][O], now + 1);
		}

		swap(crr, nxt);
	}

	int res = 0;
	for(int K=0;K<=20;K++)
	for(int U=0;U<=K;U++)
	for(int R=0;R<=U;R++)
	for(int O=0;O<=R;O++){
		res = max(res, dp[crr][K][U][R][O]);
	}

	cout << res << endl;
	return 0;
}
0