結果

問題 No.291 黒い文字列
ユーザー どららどらら
提出日時 2015-10-17 18:49:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,281 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 77,324 KB
実行使用メモリ 83,332 KB
最終ジャッジ日時 2023-09-29 16:26:50
合計ジャッジ時間 4,799 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
83,048 KB
testcase_01 AC 37 ms
83,096 KB
testcase_02 AC 40 ms
83,096 KB
testcase_03 AC 38 ms
83,048 KB
testcase_04 AC 37 ms
83,040 KB
testcase_05 AC 38 ms
83,236 KB
testcase_06 AC 39 ms
83,104 KB
testcase_07 AC 38 ms
83,256 KB
testcase_08 AC 37 ms
83,048 KB
testcase_09 AC 37 ms
83,056 KB
testcase_10 AC 44 ms
83,164 KB
testcase_11 AC 42 ms
83,160 KB
testcase_12 AC 43 ms
83,276 KB
testcase_13 AC 38 ms
83,208 KB
testcase_14 AC 40 ms
83,236 KB
testcase_15 AC 38 ms
83,040 KB
testcase_16 AC 96 ms
83,176 KB
testcase_17 AC 111 ms
83,332 KB
testcase_18 AC 100 ms
83,052 KB
testcase_19 AC 149 ms
83,160 KB
testcase_20 AC 156 ms
83,148 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 192 ms
83,048 KB
testcase_24 WA -
testcase_25 AC 95 ms
83,096 KB
testcase_26 AC 82 ms
83,072 KB
testcase_27 AC 60 ms
83,068 KB
testcase_28 AC 62 ms
83,044 KB
testcase_29 AC 65 ms
83,096 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<20) 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<20 && 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<20 && 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<20 && 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);
      }
      */

      if(S[i] == 'K' || S[i] == '?') if(a<20) 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<20 && a>0) dp[i+1][a][b+1][c][d] = max(dp[i+1][a][b+1][c][d], v);
      if(S[i] == 'R' || S[i] == '?') if(c<20 && b>0) dp[i+1][a][b][c+1][d] = max(dp[i+1][a][b][c+1][d], v);
      if(S[i] == 'O' || S[i] == '?') if(d<20 && c>0) dp[i+1][a][b][c][d+1] = max(dp[i+1][a][b][c][d+1], v);
      if(S[i] == 'I' || S[i] == '?') if(a>0 && b>0 && c>0 && d>0){
        ret = max(ret, v+1);
        dp[i+1][a-1][b-1][c-1][d-1] = max(dp[i+1][a-1][b-1][c-1][d-1], v+1);
      }

    }
  }
  cout << ret << endl;
  
  return 0;
}
0