結果

問題 No.1083 余りの余り
ユーザー tentententen
提出日時 2020-12-04 11:48:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 161 ms / 3,000 ms
コード長 1,425 bytes
コンパイル時間 3,612 ms
コンパイル使用メモリ 75,436 KB
実行使用メモリ 58,004 KB
最終ジャッジ日時 2023-10-13 00:03:52
合計ジャッジ時間 10,054 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,744 KB
testcase_01 AC 124 ms
55,784 KB
testcase_02 AC 123 ms
56,208 KB
testcase_03 AC 123 ms
55,864 KB
testcase_04 AC 126 ms
55,932 KB
testcase_05 AC 128 ms
55,544 KB
testcase_06 AC 124 ms
55,792 KB
testcase_07 AC 128 ms
56,252 KB
testcase_08 AC 128 ms
55,752 KB
testcase_09 AC 125 ms
56,412 KB
testcase_10 AC 126 ms
55,996 KB
testcase_11 AC 127 ms
55,892 KB
testcase_12 AC 128 ms
55,924 KB
testcase_13 AC 127 ms
56,004 KB
testcase_14 AC 126 ms
55,924 KB
testcase_15 AC 123 ms
55,472 KB
testcase_16 AC 123 ms
55,728 KB
testcase_17 AC 125 ms
55,816 KB
testcase_18 AC 129 ms
55,924 KB
testcase_19 AC 128 ms
56,044 KB
testcase_20 AC 126 ms
55,968 KB
testcase_21 AC 129 ms
55,720 KB
testcase_22 AC 125 ms
58,004 KB
testcase_23 AC 129 ms
55,984 KB
testcase_24 AC 130 ms
55,872 KB
testcase_25 AC 132 ms
55,688 KB
testcase_26 AC 133 ms
55,768 KB
testcase_27 AC 126 ms
55,812 KB
testcase_28 AC 161 ms
56,692 KB
testcase_29 AC 125 ms
55,788 KB
testcase_30 AC 124 ms
55,720 KB
testcase_31 AC 124 ms
55,868 KB
testcase_32 AC 125 ms
56,164 KB
testcase_33 AC 129 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[] values;
    static HashMap<Integer, HashMap<Integer, Integer>> dp = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int k = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        System.out.println(dfw((1 << n) - 1, k));
    }
    
    static int dfw(int key, int value) {
        if (key == 0) {
            return value;
        }
        if (dp.containsKey(key)) {
            if (dp.get(key).containsKey(value)) {
                return dp.get(key).get(value);
            }
        } else {
            dp.put(key, new HashMap<>());
        }
        int tmp = key;
        for (int i = 0; i < n; i++) {
            if ((tmp & (1 << i)) == 0) {
                continue;
            }
            if (values[i] > value) {
                tmp ^= (1 << i);
            }
        }
        if (tmp == 0) {
            dp.get(key).put(value, value);
            return value;
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            if ((tmp & (1 << i)) == 0) {
                continue;
            }
            max = Math.max(max, dfw(tmp ^ (1 << i), value % values[i]));
        }
        dp.get(key).put(value, max);
        return max;
    }
}
0