結果
| 問題 |
No.291 黒い文字列
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-10-17 15:59:35 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,054 bytes |
| コンパイル時間 | 2,264 ms |
| コンパイル使用メモリ | 77,896 KB |
| 実行使用メモリ | 121,912 KB |
| 最終ジャッジ日時 | 2024-07-22 10:14:19 |
| 合計ジャッジ時間 | 8,663 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 12 WA * 14 |
ソースコード
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] == '?')) {
ret = dfs(i+1,U+1,R,O,I);
}
if ((s[i] == 'U' || s[i] == '?') && U > 0) {
ret = dfs(i+1,U-1,R+1,O,I);
}
if ((s[i] == 'R' || s[i] == '?') && R > 0) {
ret = dfs(i+1,U,R-1,O+1,I);
}
if ((s[i] == 'O' || s[i] == '?') && O > 0) {
ret = dfs(i+1,U,R,O-1,I+1);
}
if ((s[i] == 'I' || s[i] == '?') && I > 0) {
ret = dfs(i+1,U,R,O,I-1) + 1;
}
hm.put(h,ret);
return ret;
}
}
ぴろず