結果
問題 | No.2390 Udon Coupon (Hard) |
ユーザー | tenten |
提出日時 | 2023-07-24 13:35:34 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,070 bytes |
コンパイル時間 | 3,186 ms |
コンパイル使用メモリ | 90,796 KB |
実行使用メモリ | 370,748 KB |
最終ジャッジ日時 | 2024-10-01 08:44:16 |
合計ジャッジ時間 | 11,421 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
50,264 KB |
testcase_01 | AC | 59 ms
50,468 KB |
testcase_02 | AC | 88 ms
51,660 KB |
testcase_03 | AC | 657 ms
118,052 KB |
testcase_04 | AC | 639 ms
117,856 KB |
testcase_05 | AC | 57 ms
37,324 KB |
testcase_06 | AC | 56 ms
37,264 KB |
testcase_07 | AC | 56 ms
37,188 KB |
testcase_08 | AC | 54 ms
37,280 KB |
testcase_09 | AC | 61 ms
37,956 KB |
testcase_10 | AC | 58 ms
37,264 KB |
testcase_11 | AC | 55 ms
37,060 KB |
testcase_12 | AC | 67 ms
38,440 KB |
testcase_13 | AC | 60 ms
37,528 KB |
testcase_14 | AC | 59 ms
37,224 KB |
testcase_15 | AC | 55 ms
37,320 KB |
testcase_16 | AC | 60 ms
37,640 KB |
testcase_17 | AC | 89 ms
51,768 KB |
testcase_18 | AC | 123 ms
56,980 KB |
testcase_19 | AC | 126 ms
58,868 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(); } }