結果

問題 No.291 黒い文字列
ユーザー milanis48663220milanis48663220
提出日時 2020-07-05 14:11:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 839 ms / 2,000 ms
コード長 2,186 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 85,672 KB
実行使用メモリ 13,672 KB
最終ジャッジ日時 2023-10-23 16:18:02
合計ジャッジ時間 14,894 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
13,296 KB
testcase_01 AC 45 ms
13,296 KB
testcase_02 AC 120 ms
13,296 KB
testcase_03 AC 83 ms
13,296 KB
testcase_04 AC 46 ms
13,296 KB
testcase_05 AC 83 ms
13,296 KB
testcase_06 AC 105 ms
13,296 KB
testcase_07 AC 60 ms
13,296 KB
testcase_08 AC 69 ms
13,296 KB
testcase_09 AC 38 ms
13,296 KB
testcase_10 AC 269 ms
13,296 KB
testcase_11 AC 189 ms
13,304 KB
testcase_12 AC 187 ms
13,296 KB
testcase_13 AC 47 ms
13,296 KB
testcase_14 AC 119 ms
13,296 KB
testcase_15 AC 84 ms
13,296 KB
testcase_16 AC 761 ms
13,392 KB
testcase_17 AC 768 ms
13,432 KB
testcase_18 AC 760 ms
13,408 KB
testcase_19 AC 795 ms
13,564 KB
testcase_20 AC 796 ms
13,612 KB
testcase_21 AC 760 ms
13,312 KB
testcase_22 AC 807 ms
13,624 KB
testcase_23 AC 839 ms
13,672 KB
testcase_24 AC 789 ms
13,508 KB
testcase_25 AC 761 ms
13,296 KB
testcase_26 AC 757 ms
13,296 KB
testcase_27 AC 754 ms
13,300 KB
testcase_28 AC 761 ms
13,316 KB
testcase_29 AC 757 ms
13,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

bool dp[2][22][22][22][22][22];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    dp[0][0][0][0][0][0] = true;
    string s;
    cin >> s;
    int ans = 0;
    for(int idx = 0; idx < s.size(); idx++){
        for(int i = 0; i <= 20; i++){
            for(int j = 0; j <= 20; j++){
                for(int k = 0; k <= 20; k++){
                    for(int l = 0; l <= 20; l++){
                        for(int m = 0; m <= 20; m++){
                            dp[(idx+1)%2][i][j][k][l][m] = dp[idx%2][i][j][k][l][m];
                        }
                    }
                }
            }
        }
        for(int i = 0; i <= 20; i++){
            for(int j = 0; j <= 20; j++){
                for(int k = 0; k <= 20; k++){
                    for(int l = 0; l <= 20; l++){
                        for(int m = 0; m <= 20; m++){
                            if(!dp[idx%2][i][j][k][l][m]) continue;
                            if(s[idx] == 'K' || s[idx] == '?'){
                                dp[(idx+1)%2][i+1][j][k][l][m] = true;
                            }
                            if((s[idx] == 'U' || s[idx] == '?') && i >= 1){
                                dp[(idx+1)%2][i-1][j+1][k][l][m] = true;
                            }
                            if((s[idx] == 'R' || s[idx] == '?') && j >= 1){
                                dp[(idx+1)%2][i][j-1][k+1][l][m] = true;
                            }
                            if((s[idx] == 'O' || s[idx] == '?') && k >= 1){
                                dp[(idx+1)%2][i][j][k-1][l+1][m] = true;
                            }
                            if((s[idx] == 'I' || s[idx] == '?') && l >= 1){
                                dp[(idx+1)%2][i][j][k][l-1][m+1] = true;
                                ans = max(ans, m+1);
                            }

                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
0