結果

問題 No.291 黒い文字列
ユーザー simansiman
提出日時 2023-03-29 18:51:20
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,596 bytes
コンパイル時間 3,574 ms
コンパイル使用メモリ 131,368 KB
実行使用メモリ 87,004 KB
最終ジャッジ日時 2023-10-21 09:23:29
合計ジャッジ時間 4,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
87,004 KB
testcase_01 AC 23 ms
87,004 KB
testcase_02 WA -
testcase_03 AC 24 ms
87,004 KB
testcase_04 AC 23 ms
87,004 KB
testcase_05 WA -
testcase_06 AC 24 ms
87,004 KB
testcase_07 WA -
testcase_08 AC 24 ms
87,004 KB
testcase_09 AC 23 ms
87,004 KB
testcase_10 WA -
testcase_11 AC 26 ms
87,004 KB
testcase_12 AC 26 ms
87,004 KB
testcase_13 AC 23 ms
87,004 KB
testcase_14 AC 25 ms
87,004 KB
testcase_15 AC 24 ms
87,004 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 42 ms
87,004 KB
testcase_24 WA -
testcase_25 AC 37 ms
87,004 KB
testcase_26 AC 38 ms
87,004 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int dp[110][21][21][21][21];

int main() {
  string S;
  cin >> S;
  int N = S.size();

  memset(dp, -1, sizeof(dp));
  dp[0][0][0][0][0] = 0;
  int ans = 0;

  for (int i = 0; i < N; ++i) {
    char ch = 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) {
            int cnt = dp[i][k][u][r][o];
            if (cnt < 0) continue;

            if ((ch == 'K' || ch == '?') && k < 20) {
              dp[i + 1][k + 1][u][r][o] = max(dp[i + 1][k + 1][u][r][o], cnt);
            }
            if ((ch == 'U' || ch == '?') && u < 20 && k > 0) {
              dp[i + 1][k - 1][u + 1][r][o] = max(dp[i + 1][k - 1][u + 1][r][o], cnt);
            }
            if ((ch == 'R' || ch == '?') && r < 20 && u > 0) {
              dp[i + 1][k][u - 1][r + 1][o] = max(dp[i + 1][k][u - 1][r + 1][o], cnt);
            }
            if ((ch == 'O' || ch == '?') && o < 20 && r > 0) {
              dp[i + 1][k][u][r - 1][o + 1] = max(dp[i + 1][k][u][r - 1][o + 1], cnt);
            }
            if ((ch == 'I' || ch == '?') && o > 0) {
              ans = max(ans, cnt + 1);
              dp[i + 1][k][u][r][o - 1] = max(dp[i + 1][k][u][r][o - 1], cnt + 1);
            }
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0