結果

問題 No.291 黒い文字列
ユーザー sugim48sugim48
提出日時 2015-10-16 22:59:04
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,068 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 84,740 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-21 20:11:08
合計ジャッジ時間 5,274 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:56: warning: iteration 21 invokes undefined behavior [-Waggressive-loop-optimizations]
   41 |                                         dp[k][u][r][o] = -1;
      |                                         ~~~~~~~~~~~~~~~^~~~
main.cpp:40:51: note: within this loop
   40 |                                 for (int o = 0; o <= 25; o++) {
      |                                                 ~~^~~~~
main.cpp:41:56: warning: iteration 21 invokes undefined behavior [-Waggressive-loop-optimizations]
   41 |                                         dp[k][u][r][o] = -1;
      |                                         ~~~~~~~~~~~~~~~^~~~
main.cpp:37:27: note: within this loop
   37 |         for (int k = 0; k <= 100; k++)
      |                         ~~^~~~~~
main.cpp:41:56: warning: iteration 21 invokes undefined behavior [-Waggressive-loop-optimizations]
   41 |                                         dp[k][u][r][o] = -1;
      |                                         ~~~~~~~~~~~~~~~^~~~
main.cpp:38:35: note: within this loop
   38 |                 for (int u = 0; u <= 50; u++)
      |                                 ~~^~~~~
main.cpp:41:56: warning: iteration 21 invokes undefined behavior [-Waggressive-loop-optimizations]
   41 |                                         dp[k][u][r][o] = -1;
      |                                         ~~~~~~~~~~~~~~~^~~~
main.cpp:39:43: note: within this loop
   39 |                         for (int r = 0; r <= 33; r++)
      |                                         ~~^~~~~

ソースコード

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[21][21][21][21], _dp[21][21][21][21];

int main() {
	for (int k = 0; k <= 100; k++)
		for (int u = 0; u <= 50; u++)
			for (int r = 0; r <= 33; r++)
				for (int o = 0; o <= 25; o++) {
					dp[k][u][r][o] = -1;
					_dp[k][u][r][o] = -1;
				}
	dp[0][0][0][0] = 0;
	string S; cin >> S;
	for (int i = 0; i < S.length(); i++) {
		char c = S[i];
		for (int k = 0; k <= 20; k++)
		for (int u = 0; u <= 20; u++)
			for (int r = 0; r <= 20; r++)
				for (int o = 0; o <= 20; 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 <= 100; k++)
		for (int u = 0; u <= 50; u++)
			for (int r = 0; r <= 33; r++)
				for (int o = 0; o <= 25; o++)
					maxi = max(maxi, dp[k][u][r][o]);
	cout << maxi << endl;
}
0