結果
| 問題 |
No.158 奇妙なお使い
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-01-26 17:15:48 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,492 bytes |
| コンパイル時間 | 2,855 ms |
| コンパイル使用メモリ | 89,860 KB |
| 実行使用メモリ | 336,448 KB |
| 最終ジャッジ日時 | 2024-06-27 10:17:15 |
| 合計ジャッジ時間 | 10,572 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 WA * 10 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
static int db;
static int b1000;
static int b100;
static int b1;
static int dc;
static int c1000;
static int c100;
static int c1;
static HashMap<Long, Integer> dpb = new HashMap<>();
static HashMap<Long, Integer> dpc = new HashMap<>();
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int a1000 = sc.nextInt();
int a100 = sc.nextInt();
int a1 = sc.nextInt();
db = sc.nextInt();
b1000 = sc.nextInt();
b100 = sc.nextInt();
b1 = sc.nextInt();
dc = sc.nextInt();
c1000 = sc.nextInt();
c100 = sc.nextInt();
c1 = sc.nextInt();
System.out.println(dfwb(a1000, a100, a1));
}
static int dfwb(int x1000, int x100, int x1) {
long key = getKey(x1000, x100, x1);
if (!dpb.containsKey(key)) {
int ans = dfwc(x1000, x100, x1);
for (int i = 0; i <= x1000 && i * 1000 <= db; i++) {
for (int j = 0; j <= x100 && j * 100 <= db - i * 1000; j++) {
int value = db - i * 1000 - j * 100;
if (x1 >= value) {
ans = Math.max(ans, dfwb(x1000 - i + b1000, x100 - j + b100, x1 - value + b1) + 1);
}
}
}
dpb.put(key, ans);
}
return dpb.get(key);
}
static int dfwc(int x1000, int x100, int x1) {
long key = getKey(x1000, x100, x1);
if (!dpc.containsKey(key)) {
int ans = 0;
for (int i = 0; i <= x1000 && i * 1000 <= dc; i++) {
for (int j = 0; j <= x100 && j * 100 <= dc - i * 1000; j++) {
int value = dc - i * 1000 - j * 100;
if (x1 >= value) {
ans = Math.max(ans, dfwc(x1000 - i + c1000, x100 - j + c100, x1 - value + c1) + 1);
}
}
}
dpc.put(key, ans);
}
return dpc.get(key);
}
static long getKey(int x1000, int x100, int x1) {
return x1000 * 100000000L + x100 * 100000L + x1;
}
}
class Utilities {
static String arrayToLineString(Object[] arr) {
return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
}
static String arrayToLineString(int[] arr) {
return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public int[] nextIntArray() throws Exception {
return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten