結果

問題 No.291 黒い文字列
ユーザー どららどらら
提出日時 2015-10-17 18:38:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 77,024 KB
実行使用メモリ 83,432 KB
最終ジャッジ日時 2023-09-29 16:25:52
合計ジャッジ時間 5,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
83,284 KB
testcase_01 AC 44 ms
83,284 KB
testcase_02 AC 46 ms
83,180 KB
testcase_03 AC 45 ms
83,216 KB
testcase_04 AC 44 ms
83,368 KB
testcase_05 AC 45 ms
83,220 KB
testcase_06 AC 45 ms
83,180 KB
testcase_07 AC 44 ms
83,156 KB
testcase_08 AC 45 ms
83,176 KB
testcase_09 AC 44 ms
83,096 KB
testcase_10 AC 50 ms
83,432 KB
testcase_11 AC 47 ms
83,176 KB
testcase_12 AC 48 ms
83,096 KB
testcase_13 AC 44 ms
83,108 KB
testcase_14 AC 46 ms
83,180 KB
testcase_15 AC 45 ms
83,112 KB
testcase_16 AC 66 ms
83,104 KB
testcase_17 AC 67 ms
83,104 KB
testcase_18 AC 66 ms
83,380 KB
testcase_19 AC 73 ms
83,172 KB
testcase_20 AC 76 ms
83,096 KB
testcase_21 AC 64 ms
83,096 KB
testcase_22 AC 78 ms
83,116 KB
testcase_23 AC 84 ms
83,180 KB
testcase_24 AC 71 ms
83,100 KB
testcase_25 AC 66 ms
83,104 KB
testcase_26 AC 60 ms
83,236 KB
testcase_27 AC 63 ms
83,092 KB
testcase_28 AC 60 ms
83,096 KB
testcase_29 AC 61 ms
83,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;


int dp[105][21][21][21][21];

int main(){
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  rep(i,105) rep(a,21) rep(b,21) rep(c,21) rep(d,21) dp[i][a][b][c][d] = -1;
  
  int ret = 0;
  dp[0][0][0][0][0] = 0;
  
  rep(i,S.length()){
    rep(a,21) rep(b,21) rep(c,21) rep(d,21){
      int v = dp[i][a][b][c][d];
      if(v < 0) continue;
      //cout << i << " " << a << " " << b << " " << c << " " << d << "  " << v << endl;
      dp[i+1][a][b][c][d] = max(dp[i+1][a][b][c][d], dp[i][a][b][c][d]);
      if(S[i] == 'K' || S[i] == '?') if(a<21) dp[i+1][a+1][b][c][d] = max(dp[i+1][a+1][b][c][d], v);
      if(S[i] == 'U' || S[i] == '?') if(b<21 && a>0) dp[i+1][a-1][b+1][c][d] = max(dp[i+1][a-1][b+1][c][d], v);
      if(S[i] == 'R' || S[i] == '?') if(c<21 && b>0) dp[i+1][a][b-1][c+1][d] = max(dp[i+1][a][b-1][c+1][d], v);
      if(S[i] == 'O' || S[i] == '?') if(d<21 && c>0) dp[i+1][a][b][c-1][d+1] = max(dp[i+1][a][b][c-1][d+1], v);
      if(S[i] == 'I' || S[i] == '?') if(d>0){
        ret = max(ret, v+1);
        dp[i+1][a][b][c][d-1] = max(dp[i+1][a][b][c][d-1], v+1);
      }
    }
  }
  cout << ret << endl;
  
  return 0;
}
0