結果

問題 No.291 黒い文字列
ユーザー ぴろずぴろず
提出日時 2015-10-17 18:18:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 700 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 2,647 ms
コンパイル使用メモリ 74,480 KB
実行使用メモリ 110,416 KB
最終ジャッジ日時 2023-09-29 16:19:04
合計ジャッジ時間 11,095 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,876 KB
testcase_01 AC 111 ms
56,348 KB
testcase_02 AC 112 ms
55,412 KB
testcase_03 AC 111 ms
55,776 KB
testcase_04 AC 111 ms
55,712 KB
testcase_05 AC 112 ms
55,668 KB
testcase_06 AC 113 ms
55,772 KB
testcase_07 AC 112 ms
54,436 KB
testcase_08 AC 110 ms
56,168 KB
testcase_09 AC 112 ms
56,080 KB
testcase_10 AC 115 ms
55,964 KB
testcase_11 AC 115 ms
55,520 KB
testcase_12 AC 114 ms
55,612 KB
testcase_13 AC 111 ms
56,144 KB
testcase_14 AC 119 ms
56,228 KB
testcase_15 AC 118 ms
55,544 KB
testcase_16 AC 431 ms
78,104 KB
testcase_17 AC 442 ms
80,720 KB
testcase_18 AC 370 ms
81,044 KB
testcase_19 AC 579 ms
101,272 KB
testcase_20 AC 528 ms
102,508 KB
testcase_21 AC 235 ms
66,888 KB
testcase_22 AC 700 ms
110,416 KB
testcase_23 AC 287 ms
66,544 KB
testcase_24 AC 556 ms
99,616 KB
testcase_25 AC 411 ms
99,424 KB
testcase_26 AC 287 ms
79,344 KB
testcase_27 AC 121 ms
56,000 KB
testcase_28 AC 163 ms
59,656 KB
testcase_29 AC 230 ms
66,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no291;

import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		s = sc.next().toCharArray();
		n = s.length;
		System.out.println(dfs(0,0,0,0,0));
	}

	static int n ;
	static char[] s;
	static HashMap<Long,Integer> hm = new HashMap<>();
	public static int dfs(int i,int U,int R,int O,int I) {
		if (i == n) {
			return 0;
		}
		long h = i + U * 101 + R * 101 * 101 + O * 101 * 101 * 101 + (long) I * 101 * 101 * 101 * 101;
		Integer memo = hm.get(h);
		if (memo != null) {
			return memo;
		}
		int ret = 0;
		if (s[i] != '?') {
			ret = Math.max(ret,dfs(i+1,U,R,O,I));
		}
		if (U + R + O + I < n / 5 && (s[i] == 'K' || s[i] == '?')) {
			ret = Math.max(ret,dfs(i+1,U+1,R,O,I));
		}
		if ((s[i] == 'U' || s[i] == '?') && U > 0) {
			ret = Math.max(ret,dfs(i+1,U-1,R+1,O,I));
		}
		if ((s[i] == 'R' || s[i] == '?') && R > 0) {
			ret = Math.max(ret,dfs(i+1,U,R-1,O+1,I));
		}
		if ((s[i] == 'O' || s[i] == '?') && O > 0) {
			ret = Math.max(ret,dfs(i+1,U,R,O-1,I+1));
		}
		if ((s[i] == 'I' || s[i] == '?') && I > 0) {
			ret = Math.max(ret,dfs(i+1,U,R,O,I-1) + 1);
		}
		hm.put(h,ret);

		return ret;
	}
}
0