結果

問題 No.291 黒い文字列
ユーザー pekempeypekempey
提出日時 2015-10-16 22:54:43
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,610 bytes
コンパイル時間 2,557 ms
コンパイル使用メモリ 158,204 KB
実行使用メモリ 123,784 KB
最終ジャッジ日時 2023-09-29 01:25:51
合計ジャッジ時間 7,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 (i < 0 || j < 0 || k < 0 || l < 0 || m < 0 || n < 0) return 0;
	P key(i, j, k, l, m, n);
	if (i == N) return n;
	if (dp.count(key)) return dp[key];
	int res = dfs(i + 1, j, k, l, m, n);
	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();
	cout << dfs(0, 0, 0, 0, 0, 0) << endl;
	return 0;
}
0