結果

問題 No.291 黒い文字列
ユーザー hirokazu1020hirokazu1020
提出日時 2015-10-17 00:40:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,596 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 94,376 KB
実行使用メモリ 5,328 KB
最終ジャッジ日時 2023-09-29 12:30:51
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,108 KB
testcase_01 AC 4 ms
5,328 KB
testcase_02 AC 7 ms
5,132 KB
testcase_03 AC 6 ms
5,212 KB
testcase_04 AC 5 ms
5,172 KB
testcase_05 AC 5 ms
5,132 KB
testcase_06 AC 7 ms
5,216 KB
testcase_07 AC 5 ms
5,168 KB
testcase_08 AC 5 ms
5,116 KB
testcase_09 AC 4 ms
5,272 KB
testcase_10 AC 12 ms
5,212 KB
testcase_11 AC 10 ms
5,268 KB
testcase_12 AC 10 ms
5,168 KB
testcase_13 AC 5 ms
5,216 KB
testcase_14 AC 7 ms
5,168 KB
testcase_15 AC 6 ms
5,216 KB
testcase_16 AC 30 ms
5,168 KB
testcase_17 AC 31 ms
5,176 KB
testcase_18 AC 31 ms
5,136 KB
testcase_19 AC 38 ms
5,164 KB
testcase_20 AC 41 ms
5,112 KB
testcase_21 AC 29 ms
5,116 KB
testcase_22 AC 46 ms
5,272 KB
testcase_23 AC 57 ms
5,200 KB
testcase_24 AC 37 ms
5,152 KB
testcase_25 AC 31 ms
5,132 KB
testcase_26 AC 30 ms
5,140 KB
testcase_27 AC 29 ms
5,324 KB
testcase_28 AC 28 ms
5,200 KB
testcase_29 AC 29 ms
5,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


int dp[2][22][22][22][22];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int (*cur)[22][22][22],(*nxt)[22][22][22];
	cur = dp[0];
	nxt = dp[1];
	
	memset(cur, -1, sizeof(dp[0]));
	cur[0][0][0][0] = 0;
	rep(i,s.size()) {
		memset(nxt,-1,sizeof(dp[0]));
		rep(a,21)rep(b,21)rep(c,21)rep(d,21){
			int v = cur[d][c][b][a];
			if (v == -1)continue;
			nxt[d][c][b][a] = max(nxt[d][c][b][a], v);
			if (s[i] == 'K' || s[i] == '?')        nxt[d][c][b][a + 1] = max(nxt[d][c][b][a + 1], v);
			if ((s[i] == 'U' || s[i] == '?') && a) nxt[d][c][b + 1][a - 1] = max(nxt[d][c][b + 1][a - 1], v);
			if ((s[i] == 'R' || s[i] == '?') && b) nxt[d][c + 1][b - 1][a] = max(nxt[d][c + 1][b - 1][a], v);
			if ((s[i] == 'O' || s[i] == '?') && c) nxt[d + 1][c - 1][b][a] = max(nxt[d + 1][c - 1][b][a], v);
			if ((s[i] == 'I' || s[i] == '?') && d) nxt[d - 1][c][b][a] = max(nxt[d - 1][c][b][a], v + 1);
		}
		swap(cur, nxt);
	}
	cout << *max_element((int*)cur[0], (int*)cur[22]) << endl;

	return 0;
}
0