結果

問題 No.291 黒い文字列
ユーザー しらっ亭しらっ亭
提出日時 2016-03-14 17:57:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,512 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 161,924 KB
実行使用メモリ 12,360 KB
最終ジャッジ日時 2024-04-08 11:19:18
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 5 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 6 ms
6,676 KB
testcase_11 AC 8 ms
8,008 KB
testcase_12 AC 7 ms
7,368 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 27 ms
12,232 KB
testcase_17 AC 28 ms
12,360 KB
testcase_18 AC 27 ms
12,232 KB
testcase_19 AC 34 ms
12,360 KB
testcase_20 AC 37 ms
12,360 KB
testcase_21 AC 20 ms
10,440 KB
testcase_22 AC 41 ms
12,360 KB
testcase_23 AC 42 ms
12,360 KB
testcase_24 AC 35 ms
12,360 KB
testcase_25 AC 29 ms
12,360 KB
testcase_26 AC 25 ms
12,360 KB
testcase_27 AC 14 ms
6,676 KB
testcase_28 AC 14 ms
7,240 KB
testcase_29 AC 22 ms
11,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FORR(x,arr) for(auto&& x:arr)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
typedef long long ll;
// -------------------------------------

string s;
int dp[2][21][21][21][21][21];

int main() {
  cin >> s;

  dp[0][0][0][0][0][0] = 1;

  int len = SZ(s);
  int ans = 0;
  REP(x, len) {
    char c = s[x];
    int y = x % 2;
    int z = !y;
    REP(k, 21) REP(u, k+1) REP(r, u+1) REP(o, r+1) REP(i, o+1) if (dp[y][k][u][r][o][i]) {
      if ((c == 'K' || c == '?') && k < 20) dp[z][k+1][u][r][o][i] = dp[y][k][u][r][o][i];
      if ((c == 'U' || c == '?') && u < k) dp[z][k][u+1][r][o][i] = dp[y][k][u][r][o][i];
      if ((c == 'R' || c == '?') && r < u) dp[z][k][u][r+1][o][i] = dp[y][k][u][r][o][i];
      if ((c == 'O' || c == '?') && o < r) dp[z][k][u][r][o+1][i] = dp[y][k][u][r][o][i];
      if ((c == 'I' || c == '?') && i < o) dp[z][k][u][r][o][i+1] = dp[y][k][u][r][o][i], ans = max(ans, i+1);
      else dp[z][k][u][r][o][i] = dp[y][k][u][r][o][i];
    }
  }

  cout << ans << endl;

  return 0;
}
0