結果

問題 No.291 黒い文字列
ユーザー ぴろずぴろず
提出日時 2015-10-17 17:55:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,266 bytes
コンパイル時間 4,862 ms
コンパイル使用メモリ 83,564 KB
実行使用メモリ 132,420 KB
最終ジャッジ日時 2023-09-29 16:14:51
合計ジャッジ時間 11,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,964 KB
testcase_01 AC 113 ms
55,892 KB
testcase_02 AC 114 ms
56,016 KB
testcase_03 AC 115 ms
55,620 KB
testcase_04 AC 114 ms
55,676 KB
testcase_05 AC 112 ms
55,580 KB
testcase_06 AC 114 ms
55,972 KB
testcase_07 AC 113 ms
55,568 KB
testcase_08 AC 114 ms
55,572 KB
testcase_09 AC 115 ms
53,260 KB
testcase_10 WA -
testcase_11 AC 140 ms
56,540 KB
testcase_12 AC 118 ms
55,332 KB
testcase_13 AC 118 ms
55,560 KB
testcase_14 AC 116 ms
58,228 KB
testcase_15 AC 115 ms
56,088 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 385 ms
72,736 KB
testcase_20 AC 588 ms
90,312 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 987 ms
132,420 KB
testcase_24 WA -
testcase_25 AC 115 ms
56,132 KB
testcase_26 AC 115 ms
55,956 KB
testcase_27 AC 115 ms
55,744 KB
testcase_28 WA -
testcase_29 AC 116 ms
56,056 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] != 'K' && s[i] != 'U' && s[i] != 'R' && s[i] != 'O' && s[i] != 'I' && s[i] != '?') {
			ret = Math.max(ret,dfs(i+1,U,R,O,I));
		}
		if ((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