結果

問題 No.291 黒い文字列
ユーザー sugim48sugim48
提出日時 2015-10-16 23:15:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,139 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 78,756 KB
実行使用メモリ 10,916 KB
最終ジャッジ日時 2023-09-29 01:48:48
合計ジャッジ時間 4,591 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
10,576 KB
testcase_01 AC 13 ms
10,692 KB
testcase_02 AC 26 ms
10,604 KB
testcase_03 AC 20 ms
10,564 KB
testcase_04 AC 14 ms
10,548 KB
testcase_05 AC 20 ms
10,620 KB
testcase_06 AC 24 ms
10,844 KB
testcase_07 AC 16 ms
10,640 KB
testcase_08 AC 17 ms
10,640 KB
testcase_09 AC 12 ms
10,696 KB
testcase_10 AC 52 ms
10,576 KB
testcase_11 AC 38 ms
10,608 KB
testcase_12 AC 38 ms
10,640 KB
testcase_13 AC 13 ms
10,652 KB
testcase_14 AC 26 ms
10,844 KB
testcase_15 AC 19 ms
10,576 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 137 ms
10,752 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 146 ms
10,612 KB
testcase_25 AC 139 ms
10,676 KB
testcase_26 AC 138 ms
10,612 KB
testcase_27 AC 136 ms
10,552 KB
testcase_28 AC 139 ms
10,576 KB
testcase_29 AC 140 ms
10,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, c; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int dp[31][31][31][31], _dp[31][31][31][31];

int main() {
	for (int k = 0; k <= 30; k++)
		for (int u = 0; u <= 30; u++)
			for (int r = 0; r <= 30; r++)
				for (int o = 0; o <= 30; o++) {
					dp[k][u][r][o] = -1;
					_dp[k][u][r][o] = -1;
				}
	dp[0][0][0][0] = 0;
	string S; cin >> S;
	if (S.length() > 100) return 1;
	for (int i = 0; i < S.length(); i++) {
		char c = S[i];
		for (int k = 0; k <= 30; k++)
		for (int u = 0; u <= 30; u++)
			for (int r = 0; r <= 30; r++)
				for (int o = 0; o <= 30; o++) {
						if (dp[k][u][r][o] == -1) continue;
						_dp[k][u][r][o] = max(_dp[k][u][r][o], dp[k][u][r][o]);
						if (c == 'K' || c == '?')
							_dp[k + 1][u][r][o] = max(_dp[k + 1][u][r][o], dp[k][u][r][o]);
						if ((c == 'U' || c == '?') && k >= 1)
							_dp[k - 1][u + 1][r][o] = max(_dp[k - 1][u + 1][r][o], dp[k][u][r][o]);
						if ((c == 'R' || c == '?') && u >= 1)
							_dp[k][u - 1][r + 1][o] = max(_dp[k][u - 1][r + 1][o], dp[k][u][r][o]);
						if ((c == 'O' || c == '?') && r >= 1)
							_dp[k][u][r - 1][o + 1] = max(_dp[k][u][r - 1][o + 1], dp[k][u][r][o]);
						if ((c == 'I' || c == '?') && o >= 1)
							_dp[k][u][r][o - 1] = max(_dp[k][u][r][o - 1], dp[k][u][r][o] + 1);
					}
		swap(dp, _dp);
	}
	int maxi = 0;
	for (int k = 0; k <= 30; k++)
		for (int u = 0; u <= 30; u++)
			for (int r = 0; r <= 30; r++)
				for (int o = 0; o <= 30; o++)
					maxi = max(maxi, dp[k][u][r][o]);
	cout << maxi << endl;
	if (maxi > 20) cout << "UNKO" << endl;
}
0