結果

問題 No.291 黒い文字列
ユーザー roiti46roiti46
提出日時 2015-10-17 03:04:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 146,912 KB
実行使用メモリ 96,896 KB
最終ジャッジ日時 2023-09-29 13:29:07
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
96,716 KB
testcase_01 AC 25 ms
96,736 KB
testcase_02 AC 27 ms
96,688 KB
testcase_03 AC 26 ms
96,896 KB
testcase_04 AC 25 ms
96,660 KB
testcase_05 AC 25 ms
96,876 KB
testcase_06 AC 26 ms
96,752 KB
testcase_07 AC 24 ms
96,888 KB
testcase_08 AC 25 ms
96,764 KB
testcase_09 AC 25 ms
96,712 KB
testcase_10 AC 31 ms
96,648 KB
testcase_11 AC 28 ms
96,660 KB
testcase_12 AC 28 ms
96,648 KB
testcase_13 AC 24 ms
96,704 KB
testcase_14 AC 26 ms
96,672 KB
testcase_15 AC 25 ms
96,880 KB
testcase_16 AC 43 ms
96,736 KB
testcase_17 AC 45 ms
96,800 KB
testcase_18 AC 44 ms
96,660 KB
testcase_19 AC 48 ms
96,664 KB
testcase_20 AC 50 ms
96,656 KB
testcase_21 AC 40 ms
96,668 KB
testcase_22 AC 52 ms
96,660 KB
testcase_23 AC 59 ms
96,720 KB
testcase_24 AC 46 ms
96,652 KB
testcase_25 AC 50 ms
96,704 KB
testcase_26 AC 42 ms
96,648 KB
testcase_27 AC 41 ms
96,644 KB
testcase_28 AC 42 ms
96,712 KB
testcase_29 AC 44 ms
96,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

string S;
int dp[102][22][22][22][22];

inline void update(int &a, int b) {
  a = max(a, b);
}

int main(void) {
  cin >> S;
  int N = S.size();
  memset(dp, -1, sizeof(dp));
  dp[0][0][0][0][0] = 0;
  rep(i, N) rep(k, 21) rep(u, 21) rep(r, 21) rep(o, 21) {
    if (dp[i][k][u][r][o] == -1) continue;
    update(dp[i + 1][k][u][r][o], dp[i][k][u][r][o]);
    if (S[i] == 'K' || S[i] == '?') update(dp[i + 1][k + 1][u][r][o], dp[i][k][u][r][o]);
    if ((S[i] == 'U' || S[i] == '?') && k) update(dp[i + 1][k - 1][u + 1][r][o], dp[i][k][u][r][o]);
    if ((S[i] == 'R' || S[i] == '?') && u) update(dp[i + 1][k][u - 1][r + 1][o], dp[i][k][u][r][o]);
    if ((S[i] == 'O' || S[i] == '?') && r) update(dp[i + 1][k][u][r - 1][o + 1], dp[i][k][u][r][o]);
    if ((S[i] == 'I' || S[i] == '?') && o) update(dp[i + 1][k][u][r][o - 1], dp[i][k][u][r][o] + 1);
  }

  int ans = 0;
  rep(k, 21)rep(u, 21) rep(r, 21) rep(o, 21) update(ans, dp[N][k][u][r][o]);
  cout << ans << endl;

  return 0;
}
0