結果

問題 No.1083 余りの余り
ユーザー tentententen
提出日時 2022-08-12 18:24:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 89 ms / 3,000 ms
コード長 1,529 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 79,244 KB
実行使用メモリ 55,028 KB
最終ジャッジ日時 2023-10-24 04:19:30
合計ジャッジ時間 5,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,688 KB
testcase_01 AC 56 ms
53,688 KB
testcase_02 AC 55 ms
53,696 KB
testcase_03 AC 56 ms
53,696 KB
testcase_04 AC 56 ms
53,680 KB
testcase_05 AC 57 ms
53,700 KB
testcase_06 AC 57 ms
53,680 KB
testcase_07 AC 55 ms
53,696 KB
testcase_08 AC 56 ms
52,588 KB
testcase_09 AC 57 ms
53,692 KB
testcase_10 AC 59 ms
52,580 KB
testcase_11 AC 57 ms
53,680 KB
testcase_12 AC 57 ms
51,644 KB
testcase_13 AC 55 ms
53,696 KB
testcase_14 AC 55 ms
53,648 KB
testcase_15 AC 56 ms
53,688 KB
testcase_16 AC 56 ms
53,692 KB
testcase_17 AC 57 ms
52,576 KB
testcase_18 AC 58 ms
53,696 KB
testcase_19 AC 57 ms
53,700 KB
testcase_20 AC 57 ms
53,696 KB
testcase_21 AC 56 ms
53,636 KB
testcase_22 AC 57 ms
53,680 KB
testcase_23 AC 56 ms
53,640 KB
testcase_24 AC 59 ms
53,700 KB
testcase_25 AC 57 ms
53,700 KB
testcase_26 AC 59 ms
52,620 KB
testcase_27 AC 57 ms
53,696 KB
testcase_28 AC 89 ms
55,028 KB
testcase_29 AC 57 ms
53,696 KB
testcase_30 AC 57 ms
53,692 KB
testcase_31 AC 56 ms
53,684 KB
testcase_32 AC 57 ms
52,616 KB
testcase_33 AC 58 ms
53,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static ArrayList<HashMap<Integer, Integer>> dp = new ArrayList<>();
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
            dp.add(new HashMap<>());
        }
        Arrays.sort(values);
        System.out.println(dfw(n - 1, k));
    }
    
    static int dfw(int idx, int v) {
        if (idx == 0) {
            return v % values[0];
        }
        if (!dp.get(idx).containsKey(v)) {
            dp.get(idx).put(v, Math.max(dfw(idx - 1, v), dfw(idx - 1, v % values[idx])));
        }
        return dp.get(idx).get(v);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0