結果

問題 No.1083 余りの余り
ユーザー tentententen
提出日時 2024-03-12 15:35:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 95 ms / 3,000 ms
コード長 1,742 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 54,472 KB
最終ジャッジ日時 2024-03-12 15:35:54
合計ジャッジ時間 6,207 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
52,108 KB
testcase_01 AC 50 ms
52,108 KB
testcase_02 AC 50 ms
52,156 KB
testcase_03 AC 49 ms
52,104 KB
testcase_04 AC 49 ms
52,108 KB
testcase_05 AC 49 ms
52,236 KB
testcase_06 AC 48 ms
52,112 KB
testcase_07 AC 48 ms
52,184 KB
testcase_08 AC 48 ms
52,152 KB
testcase_09 AC 62 ms
52,108 KB
testcase_10 AC 50 ms
52,116 KB
testcase_11 AC 49 ms
52,108 KB
testcase_12 AC 50 ms
52,148 KB
testcase_13 AC 49 ms
52,104 KB
testcase_14 AC 47 ms
52,108 KB
testcase_15 AC 45 ms
54,080 KB
testcase_16 AC 49 ms
52,232 KB
testcase_17 AC 50 ms
52,116 KB
testcase_18 AC 50 ms
52,116 KB
testcase_19 AC 51 ms
54,124 KB
testcase_20 AC 51 ms
52,164 KB
testcase_21 AC 52 ms
52,108 KB
testcase_22 AC 52 ms
54,136 KB
testcase_23 AC 49 ms
52,120 KB
testcase_24 AC 49 ms
54,128 KB
testcase_25 AC 49 ms
54,080 KB
testcase_26 AC 51 ms
52,368 KB
testcase_27 AC 49 ms
52,116 KB
testcase_28 AC 95 ms
54,472 KB
testcase_29 AC 47 ms
52,116 KB
testcase_30 AC 48 ms
52,248 KB
testcase_31 AC 50 ms
52,116 KB
testcase_32 AC 50 ms
52,108 KB
testcase_33 AC 48 ms
52,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    static List<Map<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[idx];
        }
        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;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0