結果

問題 No.291 黒い文字列
ユーザー kimiyukikimiyuki
提出日時 2016-06-22 03:48:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,927 bytes
コンパイル時間 1,183 ms
コンパイル使用メモリ 86,708 KB
実行使用メモリ 814,464 KB
最終ジャッジ日時 2024-04-20 00:14:22
合計ジャッジ時間 4,228 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 34 ms
24,576 KB
testcase_11 AC 10 ms
8,832 KB
testcase_12 AC 10 ms
8,960 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 219 ms
191,744 KB
testcase_17 AC 448 ms
370,304 KB
testcase_18 AC 301 ms
265,600 KB
testcase_19 MLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
template <class T> bool setmax(T & l, T const & r) { if (not (l < r)) return false; l = r; return true; }
using namespace std;
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }

string s;
vector<vector<vector<vector<vector<int> > > > > memo;
int go(int i, int k, int ku, int kur, int kuro) {
    if (i == s.length()) return 0;
    if (memo[i][k][ku][kur][kuro] != -1) return memo[i][k][ku][kur][kuro];
    if (s[i] == 'K') { bool d = true; return memo[i][k][ku][kur][kuro] = go(i+1,   k+d, ku, kur, kuro); }
    if (s[i] == 'U') { bool d = k;    return memo[i][k][ku][kur][kuro] = go(i+1, k-d, ku+d, kur, kuro); }
    if (s[i] == 'R') { bool d = ku;   return memo[i][k][ku][kur][kuro] = go(i+1, k, ku-d, kur+d, kuro); }
    if (s[i] == 'O') { bool d = kur;  return memo[i][k][ku][kur][kuro] = go(i+1, k, ku, kur-d, kuro+d); }
    if (s[i] == 'I') { bool d = kuro; return memo[i][k][ku][kur][kuro] = go(i+1, k, ku, kur, kuro-d)+d; }
    int acc = 0;
    if (true) setmax(acc, go(i+1,   k+1, ku, kur, kuro));
    if (k)    setmax(acc, go(i+1, k-1, ku+1, kur, kuro));
    if (ku)   setmax(acc, go(i+1, k, ku-1, kur+1, kuro));
    if (kur)  setmax(acc, go(i+1, k, ku, kur-1, kuro+1));
    if (kuro) setmax(acc, go(i+1, k, ku, kur, kuro-1)+1);
    return memo[i][k][ku][kur][kuro] = acc;
};
int main() {
    cin >> s;
    s.erase(whole(remove_if, s, [&](char c) { return string("KUROI?").find(c) == string::npos; }), s.end());
    int n = s.length();
    memo = vectors(-1, n+1, n+1, n/2+1, n/3+1, n/4+1);
    cout << go(0, 0, 0, 0, 0) << endl;
    return 0;
}
0