結果

問題 No.291 黒い文字列
ユーザー GrenacheGrenache
提出日時 2015-10-17 01:12:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 472 ms / 2,000 ms
コード長 2,464 bytes
コンパイル時間 4,130 ms
コンパイル使用メモリ 75,816 KB
実行使用メモリ 59,820 KB
最終ジャッジ日時 2023-09-29 12:37:54
合計ジャッジ時間 10,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
59,104 KB
testcase_01 AC 130 ms
58,936 KB
testcase_02 AC 141 ms
58,780 KB
testcase_03 AC 152 ms
59,092 KB
testcase_04 AC 140 ms
58,648 KB
testcase_05 AC 141 ms
58,860 KB
testcase_06 AC 177 ms
58,920 KB
testcase_07 AC 130 ms
58,928 KB
testcase_08 AC 137 ms
59,304 KB
testcase_09 AC 132 ms
58,572 KB
testcase_10 AC 185 ms
59,156 KB
testcase_11 AC 235 ms
59,744 KB
testcase_12 AC 151 ms
59,820 KB
testcase_13 AC 139 ms
58,544 KB
testcase_14 AC 176 ms
59,268 KB
testcase_15 AC 169 ms
59,376 KB
testcase_16 AC 193 ms
59,248 KB
testcase_17 AC 246 ms
59,264 KB
testcase_18 AC 283 ms
59,512 KB
testcase_19 AC 303 ms
59,448 KB
testcase_20 AC 312 ms
59,508 KB
testcase_21 AC 193 ms
59,532 KB
testcase_22 AC 316 ms
59,264 KB
testcase_23 AC 472 ms
58,144 KB
testcase_24 AC 296 ms
59,140 KB
testcase_25 AC 180 ms
59,208 KB
testcase_26 AC 176 ms
59,356 KB
testcase_27 AC 172 ms
59,288 KB
testcase_28 AC 173 ms
59,128 KB
testcase_29 AC 170 ms
59,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;


public class Main_yukicoder291 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int[][][][][] dp = new int[2][20 + 1][20 + 1][20 + 1][20 + 1];
        for (int i = 0; i < 2; i++) {
    	for (int jk = 0; jk <= 20; jk++) {
        	for (int ju = 0; ju <= 20; ju++) {
            	for (int jr = 0; jr <= 20; jr++) {
//                	for (int jo = 0; jo <= 20; jo++) {
                		Arrays.fill(dp[i][jk][ju][jr], -1);
//                	}
            	}
        	}
    	}
        }
    	dp[0][0][0][0][0] = 0;

    	int ret = 0;
        for (int i = 0; i < n; i++) {
        	int now = i % 2;
        	int next = (i + 1) % 2;
        	for (int jk = 0; jk <= 20; jk++) {
            	for (int ju = 0; ju <= 20; ju++) {
                	for (int jr = 0; jr <= 20; jr++) {
                    	for (int jo = 0; jo <= 20; jo++) {
                    		int d = dp[now][jk][ju][jr][jo];
                    		if (d < 0) {
                    			continue;
                    		}

                    		dp[next][jk][ju][jr][jo] = Math.max(dp[next][jk][ju][jr][jo], d);
                    		if ((s[i] == 'K' || s[i] == '?') && jk < 20) {
                    			dp[next][jk + 1][ju][jr][jo] = Math.max(dp[next][jk + 1][ju][jr][jo], d);
                    		}
                    		if ((s[i] == 'U' || s[i] == '?') && ju < 20 && jk > 0) {
                    			dp[next][jk - 1][ju + 1][jr][jo] = Math.max(dp[next][jk - 1][ju + 1][jr][jo], d);
                    		}
                    		if ((s[i] == 'R' || s[i] == '?') && jr < 20 && ju > 0) {
                    			dp[next][jk][ju - 1][jr + 1][jo] = Math.max(dp[next][jk][ju - 1][jr + 1][jo], d);
                    		}
                    		if ((s[i] == 'O' || s[i] == '?') && jo < 20 && jr > 0) {
                    			dp[next][jk][ju][jr - 1][jo + 1] = Math.max(dp[next][jk][ju][jr - 1][jo + 1], d);
                    		}
                    		if ((s[i] == 'I' || s[i] == '?') && jo > 0) {
                    			dp[next][jk][ju][jr][jo - 1] = Math.max(dp[next][jk][ju][jr][jo - 1], d + 1);
                    			ret = Math.max(ret, dp[next][jk][ju][jr][jo - 1]);
                    		}
                    	}
                	}
            	}
        	}
        }

        System.out.println(ret);

        sc.close();
    }
}
0