結果

問題 No.291 黒い文字列
ユーザー GrenacheGrenache
提出日時 2015-10-17 01:13:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 2,464 bytes
コンパイル時間 3,344 ms
コンパイル使用メモリ 74,792 KB
実行使用メモリ 60,556 KB
最終ジャッジ日時 2023-09-29 12:39:25
合計ジャッジ時間 12,570 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
59,012 KB
testcase_01 AC 158 ms
58,520 KB
testcase_02 AC 189 ms
58,800 KB
testcase_03 AC 187 ms
58,812 KB
testcase_04 AC 159 ms
58,296 KB
testcase_05 AC 186 ms
59,044 KB
testcase_06 AC 195 ms
58,940 KB
testcase_07 AC 154 ms
58,652 KB
testcase_08 AC 155 ms
58,736 KB
testcase_09 AC 156 ms
58,268 KB
testcase_10 AC 208 ms
58,804 KB
testcase_11 AC 211 ms
58,864 KB
testcase_12 AC 238 ms
59,232 KB
testcase_13 AC 149 ms
58,700 KB
testcase_14 AC 193 ms
58,656 KB
testcase_15 AC 187 ms
59,004 KB
testcase_16 AC 280 ms
59,092 KB
testcase_17 AC 274 ms
59,660 KB
testcase_18 AC 282 ms
59,544 KB
testcase_19 AC 462 ms
59,860 KB
testcase_20 AC 494 ms
60,556 KB
testcase_21 AC 269 ms
59,300 KB
testcase_22 AC 318 ms
59,128 KB
testcase_23 AC 460 ms
60,452 KB
testcase_24 AC 288 ms
59,040 KB
testcase_25 AC 269 ms
59,252 KB
testcase_26 AC 272 ms
56,864 KB
testcase_27 AC 265 ms
58,860 KB
testcase_28 AC 268 ms
59,060 KB
testcase_29 AC 268 ms
58,976 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