結果

問題 No.291 黒い文字列
ユーザー Kmcode1Kmcode1
提出日時 2015-10-16 23:19:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 2,585 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 95,904 KB
実行使用メモリ 95,948 KB
最終ジャッジ日時 2023-09-29 01:50:04
合計ジャッジ時間 3,161 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,672 KB
testcase_01 AC 4 ms
5,532 KB
testcase_02 AC 7 ms
9,816 KB
testcase_03 AC 5 ms
7,884 KB
testcase_04 AC 3 ms
5,624 KB
testcase_05 AC 5 ms
7,576 KB
testcase_06 AC 6 ms
9,632 KB
testcase_07 AC 5 ms
7,720 KB
testcase_08 AC 5 ms
7,832 KB
testcase_09 AC 3 ms
5,540 KB
testcase_10 AC 15 ms
19,044 KB
testcase_11 AC 14 ms
18,096 KB
testcase_12 AC 13 ms
17,060 KB
testcase_13 AC 3 ms
5,480 KB
testcase_14 AC 8 ms
10,140 KB
testcase_15 AC 6 ms
7,692 KB
testcase_16 AC 73 ms
78,700 KB
testcase_17 AC 77 ms
82,216 KB
testcase_18 AC 78 ms
81,628 KB
testcase_19 AC 90 ms
91,688 KB
testcase_20 AC 92 ms
93,132 KB
testcase_21 AC 60 ms
67,204 KB
testcase_22 AC 85 ms
87,000 KB
testcase_23 AC 98 ms
95,948 KB
testcase_24 AC 81 ms
83,852 KB
testcase_25 AC 83 ms
88,676 KB
testcase_26 AC 59 ms
66,340 KB
testcase_27 AC 41 ms
50,512 KB
testcase_28 AC 52 ms
61,932 KB
testcase_29 AC 72 ms
80,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;

string s;
int dp[102][25][25][25][25];
bool use[102][25][25][25][25];
int main() {
	cin >> s;
	int ans = 0;
	use[0][0][0][0][0] = true;
	for (int i = 0;i < s.size();i++) {
		for (int j = 0;j <= 20;j++) {
			for (int k = 0;k <= 20;k++) {
				for (int kk = 0;kk <= 20;kk++) {
					for (int kkk = 0;kkk <= 20;kkk++) {
						if (use[i][j][k][kk][kkk]) {
						//	cout << j << " " << k << " " << kk << " " << kkk << endl;
							dp[i + 1][j][k][kk][kkk] = max(dp[i + 1][j][k][kk][kkk], dp[i][j][k][kk][kkk]);
							use[i + 1][j][k][kk][kkk] = true;
							if (s[i] == 'K'||s[i]=='?') {
								if (j+ 1 <= 25) {
									dp[i + 1][j + 1][k][kk][kkk] = max(dp[i + 1][j + 1][k][kk][kkk], dp[i][j][k][kk][kkk]);
									use[i + 1][j + 1][k][kk][kkk] = true;
									//continue;
								}
							}
							int mint = j;
							if (s[i] == 'U' || s[i] == '?') {
								if (min(mint,k + 1) <= 25) {
									dp[i + 1][j][min(mint,k+1)][kk][kkk] = max(dp[i + 1][j][min(mint,k+1)][kk][kkk], dp[i][j][k][kk][kkk]);
									use[i + 1][j][min(mint,k + 1)][kk][kkk] = true;
									//continue;
								}
							}
							mint = min(mint, k);
							if (s[i] == 'R' || s[i] == '?') {
								if (kk + 1 <= 25) {
									dp[i + 1][j][k][min(mint,kk+1)][kkk] = max(dp[i + 1][j][k][min(kk+1,mint)][kkk], dp[i][j][k][kk][kkk]);
									use[i + 1][j][k][min(mint,kk + 1)][kkk] = true;
								//	continue;
								}
							}
							mint = min(mint, kk);
							if (s[i] == 'O' || s[i] == '?') {
								if (min(mint,kkk + 1) <= 25) {
									dp[i + 1][j][k][kk][min(mint,kkk+1)] = max(dp[i + 1][j][k][kk][min(mint,kkk+1)], dp[i][j][k][kk][kkk]);
									use[i + 1][j][k][kk][min(mint,kkk + 1)] = true;
								//	continue;
								}
							}
							mint = min(mint, kkk);
							if (s[i] == 'I' || s[i] == '?') {
								if (j&&k&&kk&&kkk) {
									dp[i + 1][j-1][k-1][kk-1][kkk-1] = max(dp[i + 1][j-1][k-1][kk-1][kkk-1], dp[i][j][k][kk][kkk] + 1);
									ans = max(ans, dp[i + 1][j-1][k-1][kk-1][kkk-1]);
									use[i + 1][j-1][k-1][kk-1][kkk-1] = true;
								}
							}
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0