結果
問題 | No.2390 Udon Coupon (Hard) |
ユーザー | tenten |
提出日時 | 2023-07-24 13:35:34 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,070 bytes |
コンパイル時間 | 2,812 ms |
コンパイル使用メモリ | 95,632 KB |
実行使用メモリ | 463,136 KB |
最終ジャッジ日時 | 2024-04-08 16:32:20 |
合計ジャッジ時間 | 15,523 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
60,792 KB |
testcase_01 | AC | 55 ms
53,984 KB |
testcase_02 | AC | 85 ms
53,316 KB |
testcase_03 | AC | 649 ms
120,908 KB |
testcase_04 | AC | 625 ms
119,904 KB |
testcase_05 | AC | 56 ms
54,112 KB |
testcase_06 | AC | 54 ms
53,984 KB |
testcase_07 | AC | 54 ms
53,992 KB |
testcase_08 | AC | 56 ms
53,992 KB |
testcase_09 | AC | 62 ms
54,236 KB |
testcase_10 | AC | 56 ms
53,988 KB |
testcase_11 | AC | 55 ms
53,984 KB |
testcase_12 | AC | 68 ms
54,252 KB |
testcase_13 | AC | 61 ms
53,972 KB |
testcase_14 | AC | 57 ms
53,980 KB |
testcase_15 | AC | 54 ms
53,984 KB |
testcase_16 | AC | 71 ms
54,136 KB |
testcase_17 | AC | 75 ms
55,256 KB |
testcase_18 | AC | 129 ms
62,744 KB |
testcase_19 | AC | 112 ms
60,824 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static Coupon[] coupons = new Coupon[3]; static ArrayList<HashMap<Long, Long>> dp = new ArrayList<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong(); for (int i = 0; i < 3; i++) { coupons[i] = new Coupon(sc.nextInt(), sc.nextInt()); dp.add(new HashMap<>()); } Arrays.sort(coupons); long lcm = 1; for (Coupon x : coupons) { lcm = getLCM(x.count, lcm); } long max = 0; for (Coupon x : coupons) { max = Math.max(max, lcm / x.count * x.value); } long ans = n / lcm * max; n %= lcm; System.out.println(ans + dfw(2, n)); } static long getLCM(long x, long y) { return x / getGCD(x, y) * y; } static long getGCD(long x, long y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } static long dfw(int idx, long v) { if (v < 0) { return Long.MIN_VALUE; } if (idx == 0) { return v / coupons[0].count * coupons[0].value; } if (!dp.get(idx).containsKey(v)) { dp.get(idx).put(v, Math.max(dfw(idx - 1, v), dfw(idx, v - coupons[idx].count) + coupons[idx].value)); } return dp.get(idx).get(v); } static class Coupon implements Comparable<Coupon> { int count; int value; public Coupon(int count, int value) { this.count = count; this.value = value; } public int compareTo(Coupon another) { return count - another.count; } } } 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(); } }