結果

問題 No.291 黒い文字列
ユーザー pekempeypekempey
提出日時 2015-10-16 23:03:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 161,328 KB
実行使用メモリ 47,604 KB
最終ジャッジ日時 2023-09-29 01:33:29
合計ジャッジ時間 4,578 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 4 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 AC 213 ms
14,272 KB
testcase_20 AC 478 ms
24,272 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,132 ms
47,604 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

string s;
int N;
typedef tuple<int, int, int, int, int, int> P;

map<P, int> dp;

int dfs(int i, int j, int k, int l, int m, int n) {
	if (j < 0 || k < 0 || l < 0 || m < 0 || n < 0) return 0;
	if (j > 20 || k > 20 || l > 20 || m > 20 || n > 20) return 0;
	P key(i, j, k, l, m, n);
	if (i == N) return n;
	if (dp.count(key)) return dp[key];
	int res = 0;
	if (s[i] == 'K') {
		chmax(res, dfs(i + 1, j + 1, k, l, m, n));
	} else if (s[i] == 'U') {
		chmax(res, dfs(i + 1, j - 1, k + 1, l, m, n));
	} else if (s[i] == 'R') {
		chmax(res, dfs(i + 1, j, k - 1, l + 1, m, n));
	} else if (s[i] == 'O') {
		chmax(res, dfs(i + 1, j, k, l - 1, m + 1, n));
	} else if (s[i] == 'I') {
		chmax(res, dfs(i + 1, j, k, l, m - 1, n + 1));
	} else if (s[i] == '?') {
		chmax(res, dfs(i + 1, j + 1, k, l, m, n));
		chmax(res, dfs(i + 1, j - 1, k + 1, l, m, n));
		chmax(res, dfs(i + 1, j, k - 1, l + 1, m, n));
		chmax(res, dfs(i + 1, j, k, l - 1, m + 1, n));
		chmax(res, dfs(i + 1, j, k, l, m - 1, n + 1));
	}
	return dp[key] = res;
}

int main() {
	cin >> s;
	N = s.length();
	vector<bool> valid(N);
	rep (i, N) {
		valid[i] = s[i] == 'K' || s[i] == 'U' || s[i] == 'R' || s[i] == 'O' || s[i] == 'I' || s[i] == '?';
	}
	string t;
	rep (i, N) {
		if (valid[i]) t += s[i];
	}
	s = t;
	N = s.length();
	cout << dfs(0, 0, 0, 0, 0, 0) << endl;
	return 0;
}
0