結果

問題 No.1083 余りの余り
ユーザー tentententen
提出日時 2020-12-04 11:31:03
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,057 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 85,148 KB
実行使用メモリ 279,664 KB
最終ジャッジ日時 2023-10-12 23:43:28
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
63,156 KB
testcase_01 AC 125 ms
56,408 KB
testcase_02 AC 131 ms
55,480 KB
testcase_03 AC 124 ms
56,112 KB
testcase_04 AC 164 ms
59,832 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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