結果

問題 No.291 黒い文字列
ユーザー ぴろずぴろず
提出日時 2015-10-17 16:55:35
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,165 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 80,500 KB
実行使用メモリ 313,304 KB
最終ジャッジ日時 2023-09-29 16:08:34
合計ジャッジ時間 17,577 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
60,360 KB
testcase_01 AC 119 ms
55,960 KB
testcase_02 AC 120 ms
55,824 KB
testcase_03 AC 118 ms
55,848 KB
testcase_04 AC 118 ms
55,832 KB
testcase_05 AC 118 ms
55,284 KB
testcase_06 AC 117 ms
53,924 KB
testcase_07 AC 118 ms
55,492 KB
testcase_08 AC 118 ms
55,604 KB
testcase_09 AC 117 ms
55,596 KB
testcase_10 AC 122 ms
55,504 KB
testcase_11 AC 152 ms
59,108 KB
testcase_12 AC 146 ms
56,876 KB
testcase_13 AC 117 ms
56,092 KB
testcase_14 AC 118 ms
55,412 KB
testcase_15 AC 117 ms
55,868 KB
testcase_16 AC 551 ms
100,892 KB
testcase_17 AC 757 ms
107,104 KB
testcase_18 AC 573 ms
98,308 KB
testcase_19 AC 1,883 ms
193,500 KB
testcase_20 TLE -
testcase_21 AC 253 ms
66,780 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
		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