結果
問題 | No.1083 余りの余り |
ユーザー |
![]() |
提出日時 | 2020-12-04 11:31:03 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,057 bytes |
コンパイル時間 | 2,494 ms |
コンパイル使用メモリ | 84,500 KB |
実行使用メモリ | 268,320 KB |
最終ジャッジ日時 | 2024-09-14 21:47:20 |
合計ジャッジ時間 | 7,974 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 2 TLE * 1 -- * 28 |
ソースコード
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;}}