結果

問題 No.291 黒い文字列
ユーザー t98slidert98slider
提出日時 2022-08-24 11:13:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 2,723 bytes
コンパイル時間 2,075 ms
コンパイル使用メモリ 176,040 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-04-20 02:06:22
合計ジャッジ時間 3,767 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,760 KB
testcase_01 AC 7 ms
5,888 KB
testcase_02 AC 11 ms
5,760 KB
testcase_03 AC 9 ms
5,760 KB
testcase_04 AC 6 ms
5,888 KB
testcase_05 AC 9 ms
5,760 KB
testcase_06 AC 10 ms
5,888 KB
testcase_07 AC 7 ms
5,632 KB
testcase_08 AC 9 ms
5,888 KB
testcase_09 AC 5 ms
5,632 KB
testcase_10 AC 19 ms
5,760 KB
testcase_11 AC 15 ms
5,888 KB
testcase_12 AC 13 ms
5,760 KB
testcase_13 AC 6 ms
5,888 KB
testcase_14 AC 12 ms
5,760 KB
testcase_15 AC 10 ms
5,632 KB
testcase_16 AC 53 ms
5,760 KB
testcase_17 AC 47 ms
5,760 KB
testcase_18 AC 52 ms
5,760 KB
testcase_19 AC 52 ms
5,888 KB
testcase_20 AC 52 ms
5,760 KB
testcase_21 AC 51 ms
5,888 KB
testcase_22 AC 48 ms
5,888 KB
testcase_23 AC 54 ms
5,760 KB
testcase_24 AC 52 ms
5,888 KB
testcase_25 AC 55 ms
5,760 KB
testcase_26 AC 52 ms
5,760 KB
testcase_27 AC 44 ms
5,760 KB
testcase_28 AC 52 ms
5,888 KB
testcase_29 AC 50 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vector4d(type,name,h,w,d,...) vector<vector<vector<vector<type>>>>name(h,vector<vector<vector<type>>>(w,vector<vector<type>>(d,vector<type>(__VA_ARGS__))))

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    vector4d(int,dp,21,21,21,21,-(1<<30));
    dp[0][0][0][0] = 0;
    for(int i = 0; i < n; i++){
        vector4d(int,ndp,21,21,21,21,-(1<<30));
        if(s[i] == '?'){
            for(int a = 0; a <= 20; a++){
                for(int b = 0; b <= a; b++){
                    for(int c = 0; c <= b; c++){
                        for(int d = 0; d <= c; d++){
                            ndp[a][b][c][d] = max(ndp[a][b][c][d], dp[a][b][c][d]);
                            if(a + 1 <= 20)ndp[a + 1][b][c][d] = max(ndp[a + 1][b][c][d], dp[a][b][c][d]);
                            if(b + 1 <= a)ndp[a][b + 1][c][d] = max(ndp[a][b + 1][c][d], dp[a][b][c][d]);
                            if(c + 1 <= b)ndp[a][b][c + 1][d] = max(ndp[a][b][c + 1][d], dp[a][b][c][d]);
                            if(d + 1 <= c)ndp[a][b][c][d + 1] = max(ndp[a][b][c][d + 1], dp[a][b][c][d]);
                            if(d >= 1)ndp[a-1][b-1][c-1][d-1] = max(ndp[a-1][b-1][c-1][d-1],dp[a][b][c][d]+1);
                        }
                    }
                }
            }
        }else{
            for(int a = 0; a <= 20; a++){
                for(int b = 0; b <= a; b++){
                    for(int c = 0; c <= b; c++){
                        for(int d = 0; d <= c; d++){
                            ndp[a][b][c][d] = max(ndp[a][b][c][d], dp[a][b][c][d]);
                            if(s[i] == 'K' && a + 1 <= 20)ndp[a + 1][b][c][d] = max(ndp[a + 1][b][c][d], dp[a][b][c][d]);
                            if(s[i] == 'U' && b + 1 <= a)ndp[a][b + 1][c][d] = max(ndp[a][b + 1][c][d], dp[a][b][c][d]);
                            if(s[i] == 'R' && c + 1 <= b)ndp[a][b][c + 1][d] = max(ndp[a][b][c + 1][d], dp[a][b][c][d]);
                            if(s[i] == 'O' && d + 1 <= c)ndp[a][b][c][d + 1] = max(ndp[a][b][c][d + 1], dp[a][b][c][d]);
                            if(s[i] == 'I' && d >= 1)ndp[a-1][b-1][c-1][d-1] = max(ndp[a-1][b-1][c-1][d-1],dp[a][b][c][d]+1);
                        }
                    }
                }
            }
        }
        swap(dp, ndp);
    }
    int ans = 0;
    for(int a = 0; a <= 20; a++){
        for(int b = 0; b <= a; b++){
            for(int c = 0; c <= b; c++){
                for(int d = 0; d <= c; d++){
                    ans = max(ans, dp[a][b][c][d]);
                }
            }
        }
    }
    cout << ans << '\n';
}
0