結果

問題 No.291 黒い文字列
ユーザー ctyl_0ctyl_0
提出日時 2015-10-20 02:35:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 2,588 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 88,488 KB
実行使用メモリ 5,100 KB
最終ジャッジ日時 2023-09-29 16:53:09
合計ジャッジ時間 4,371 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,940 KB
testcase_01 AC 7 ms
4,816 KB
testcase_02 AC 16 ms
4,880 KB
testcase_03 AC 12 ms
4,820 KB
testcase_04 AC 7 ms
4,824 KB
testcase_05 AC 12 ms
4,948 KB
testcase_06 AC 15 ms
4,832 KB
testcase_07 AC 9 ms
5,092 KB
testcase_08 AC 11 ms
4,816 KB
testcase_09 AC 6 ms
4,956 KB
testcase_10 AC 35 ms
4,976 KB
testcase_11 AC 26 ms
4,828 KB
testcase_12 AC 25 ms
5,100 KB
testcase_13 AC 7 ms
4,888 KB
testcase_14 AC 17 ms
4,960 KB
testcase_15 AC 12 ms
4,820 KB
testcase_16 AC 101 ms
4,836 KB
testcase_17 AC 103 ms
4,956 KB
testcase_18 AC 102 ms
4,904 KB
testcase_19 AC 111 ms
4,824 KB
testcase_20 AC 115 ms
4,884 KB
testcase_21 AC 100 ms
4,888 KB
testcase_22 AC 117 ms
4,940 KB
testcase_23 AC 132 ms
4,884 KB
testcase_24 AC 110 ms
4,980 KB
testcase_25 AC 100 ms
4,888 KB
testcase_26 AC 99 ms
4,888 KB
testcase_27 AC 98 ms
4,888 KB
testcase_28 AC 97 ms
4,940 KB
testcase_29 AC 98 ms
5,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template
int dp[2][21][21][21][21];

int main() {
    // source code
    string s;
    cin >> s;
    
    rep(i, 2){
        rep(o, 21) rep(r, 21) rep(u, 21) rep(k, 21){
            dp[i][o][r][u][k] = -1;
        }
    }
    
    dp[0][0][0][0][0] = 0;
    
    int ret = 0;
    
    
    
    rep(i, s.size()){
        int od = i % 2;
        int nw = od ^ 1;
        
        rep(k, 21) rep(u, 21) rep(r, 21) rep(o, 21){
            dp[nw][o][r][u][k] = dp[od][o][r][u][k];
        }
        
        rep(k, 21) rep(u, 21) rep(r, 21) rep(o, 21){
            
            if(dp[od][o][r][u][k] >= 0) {
                
                if (s[i] == 'K' || s[i] == '?'){
                    if (k < 20) dp[nw][o][r][u][k + 1] = max(dp[nw][o][r][u][k + 1], dp[od][o][r][u][k]);
                }
                if (s[i] == 'U' || s[i] == '?') {
                    if (u < 20 && k > 0) dp[nw][o][r][u + 1][k - 1] = max(dp[nw][o][r][u + 1][k - 1], dp[od][o][r][u][k]);
                }
                if (s[i] == 'R' || s[i] == '?') {
                    if (r < 20 && u > 0) dp[nw][o][r + 1][u - 1][k] = max(dp[nw][o][r + 1][u - 1][k], dp[od][o][r][u][k]);
                }
                
                if (s[i] == 'O' || s[i] == '?') {
                    if (o < 20 && r > 0) dp[nw][o + 1][r - 1][u][k] = max(dp[nw][o + 1][r - 1][u][k], dp[od][o][r][u][k]);
                }
                
                if (s[i] == 'I' || s[i] == '?') {
                    if (o > 0) {
                        dp[nw][o - 1][r][u][k] = max(dp[nw][o - 1][r][u][k], dp[od][o][r][u][k] + 1);
//                        cout << "I: " << i << ", ";
//                        output(dp[nw][o - 1][r][u][k], 0);
                        ret = max(ret, dp[nw][o - 1][r][u][k]);
                    }
                }
                
            }
        }
    }
    
    output(ret, 0);
    
    
    return 0;
}
0