結果

問題 No.291 黒い文字列
ユーザー motimoti
提出日時 2015-10-17 08:39:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,647 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 94,552 KB
実行使用メモリ 5,112 KB
最終ジャッジ日時 2023-09-29 13:34:18
合計ジャッジ時間 1,706 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,804 KB
testcase_01 AC 2 ms
4,936 KB
testcase_02 AC 3 ms
4,888 KB
testcase_03 AC 3 ms
4,820 KB
testcase_04 AC 2 ms
4,824 KB
testcase_05 AC 3 ms
4,808 KB
testcase_06 AC 3 ms
4,808 KB
testcase_07 AC 2 ms
4,992 KB
testcase_08 AC 2 ms
4,824 KB
testcase_09 AC 2 ms
4,932 KB
testcase_10 AC 4 ms
4,824 KB
testcase_11 AC 3 ms
4,808 KB
testcase_12 AC 4 ms
4,856 KB
testcase_13 AC 2 ms
4,828 KB
testcase_14 AC 3 ms
4,804 KB
testcase_15 AC 3 ms
4,892 KB
testcase_16 AC 9 ms
4,856 KB
testcase_17 AC 9 ms
4,856 KB
testcase_18 AC 9 ms
4,888 KB
testcase_19 AC 12 ms
4,856 KB
testcase_20 AC 13 ms
4,828 KB
testcase_21 AC 6 ms
4,940 KB
testcase_22 AC 12 ms
4,836 KB
testcase_23 AC 14 ms
4,800 KB
testcase_24 AC 11 ms
4,856 KB
testcase_25 AC 8 ms
5,112 KB
testcase_26 AC 8 ms
4,824 KB
testcase_27 AC 7 ms
4,824 KB
testcase_28 AC 7 ms
4,952 KB
testcase_29 AC 7 ms
4,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

#define chmax(a,x) a=max(a,x)

int dp[2][21][21][21][21];

int main() {

  string s; cin >> s;
  int N = s.size();

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

  rep(idx, N) {
    memset(dp[(idx+1)&1], -1, sizeof dp[(idx+1)&1]);
    rep(k, 21) rep(u, k+1) rep(r, u+1) rep(o, r+1) {
      if(dp[idx&1][k][u][r][o] < 0) { continue; }
      dp[(idx+1)&1][k][u][r][o] = max(dp[(idx+1)&1][k][u][r][o], dp[idx&1][k][u][r][o]);
      if(s[idx] == 'K' || s[idx] == '?') {
        chmax(dp[(idx+1)&1][min(20,k+1)][u][r][o], dp[idx&1][k][u][r][o]);
      }
      if(s[idx] == 'U' || s[idx] == '?') {
        chmax(dp[(idx+1)&1][k][min(20,u+1)][r][o], dp[idx&1][k][u][r][o]);
      }
      if(s[idx] == 'R' || s[idx] == '?') {
        chmax(dp[(idx+1)&1][k][u][min(20,r+1)][o], dp[idx&1][k][u][r][o]);
      }
      if(s[idx] == 'O' || s[idx] == '?') {
        chmax(dp[(idx+1)&1][k][u][r][min(20,o+1)], dp[idx&1][k][u][r][o]);
      }
      if(s[idx] == 'I' || s[idx] == '?') {
        if(o) chmax(dp[(idx+1)&1][k-1][u-1][r-1][o-1], dp[idx&1][k][u][r][o] + 1);
      }
    }
  }

  int ans = 0;
  rep(k,21)rep(u,21)rep(r,21)rep(o,21){
    ans = max(ans, dp[N&1][k][u][r][o]);
  }

  cout << ans << endl;

  return 0;
}
0