結果

問題 No.291 黒い文字列
ユーザー btkbtk
提出日時 2015-10-17 03:51:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,867 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 64,540 KB
実行使用メモリ 5,064 KB
最終ジャッジ日時 2023-09-29 13:31:22
合計ジャッジ時間 3,259 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,792 KB
testcase_01 AC 5 ms
4,876 KB
testcase_02 AC 14 ms
4,936 KB
testcase_03 AC 9 ms
4,768 KB
testcase_04 AC 5 ms
4,816 KB
testcase_05 AC 8 ms
4,864 KB
testcase_06 AC 9 ms
4,844 KB
testcase_07 AC 8 ms
4,860 KB
testcase_08 AC 13 ms
4,844 KB
testcase_09 AC 8 ms
4,936 KB
testcase_10 AC 29 ms
4,792 KB
testcase_11 AC 40 ms
4,792 KB
testcase_12 AC 35 ms
4,800 KB
testcase_13 AC 6 ms
4,908 KB
testcase_14 AC 14 ms
4,940 KB
testcase_15 AC 11 ms
4,768 KB
testcase_16 AC 102 ms
4,876 KB
testcase_17 AC 110 ms
4,876 KB
testcase_18 AC 104 ms
4,772 KB
testcase_19 AC 134 ms
5,064 KB
testcase_20 AC 137 ms
4,936 KB
testcase_21 AC 77 ms
4,848 KB
testcase_22 AC 122 ms
4,856 KB
testcase_23 AC 165 ms
4,900 KB
testcase_24 AC 125 ms
4,848 KB
testcase_25 AC 83 ms
4,876 KB
testcase_26 AC 85 ms
4,856 KB
testcase_27 AC 73 ms
4,848 KB
testcase_28 AC 75 ms
4,796 KB
testcase_29 AC 73 ms
4,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stdio.h>

using namespace std;
int*pv,*nt;
int dp1[21][21][21][21];
int dp2[21][21][21][21];
const int INF = 1e6;
#define id(a,b,c,d) (a)*21*21*21+(b)*21*21+(c)*21+(d)
int main() {
    string str;
    cin>>str;
    int n=str.size();
    pv=(int*)dp1;
    nt=(int*)dp2;

    for(int i = 0; i < 21; i++)
        for(int j = 0; j < 21; j++)
            for(int k = 0; k < 21; k++)
                for(int l = 0; l < 21; l++)
                    pv[id(i,j,k,l)]=-INF;
    pv[id(0,0,0,0)]=0;

    int res=0;
    for(int m = 0; m < n; m++){
        for(int i = 0; i <21 ; i++)
            for(int j = 0; j < 21; j++)
                for(int k = 0; k < 21; k++)
                    for(int l = 0; l < 21; l++){
                        nt[id(i,j,k,l)]=pv[id(i,j,k,l)];
                        if(str[m]=='K'||str[m]=='?')
                            nt[id(i,j,k,l)]=max((i>0)?pv[id(i-1,j,k,l)]:-INF,nt[id(i,j,k,l)]);
                        if(str[m]=='U'||str[m]=='?')
                            nt[id(i,j,k,l)]=max((j>0&&i<20)?pv[id(i+1,j-1,k,l)]:-INF,nt[id(i,j,k,l)]);
                        if(str[m]=='R'||str[m]=='?')
                            nt[id(i,j,k,l)]=max((k>0&&j<20)?pv[id(i,j+1,k-1,l)]:-INF,nt[id(i,j,k,l)]);
                        if(str[m]=='O'||str[m]=='?')
                            nt[id(i,j,k,l)]=max((l>0&&k<20)?pv[id(i,j,k+1,l-1)]:-INF,nt[id(i,j,k,l)]);
                        if(str[m]=='I'||str[m]=='?')
                            nt[id(i,j,k,l)]=max((l<20)?(pv[id(i,j,k,l+1)]+1):-INF,nt[id(i,j,k,l)]);
                        res=max(res,nt[id(i,j,k,l)]);
                    //   printf("%d:dp[%d][%d][%d][%d]=%d\n",m,i,j,k,l,nt[id(i,j,k,l)]);
                        }
        swap(pv,nt);
    }
    cout<<res<<endl;

    return 0;
}
0