結果

問題 No.1083 余りの余り
ユーザー ks2mks2m
提出日時 2020-06-19 21:46:39
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 765 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 73,588 KB
実行使用メモリ 61,760 KB
最終ジャッジ日時 2023-09-16 13:49:54
合計ジャッジ時間 7,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
60,496 KB
testcase_01 AC 122 ms
55,820 KB
testcase_02 AC 134 ms
56,048 KB
testcase_03 AC 124 ms
55,588 KB
testcase_04 AC 165 ms
55,688 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.Scanner;

public class Main {
	static int n, k, n2;
	static int[] a, memo;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		n2 = 1 << n;
		memo = new int[n2];
		int ans = dfs(k, 0);
		System.out.println(ans);
	}

	static int dfs(int x, int bit) {
		if (x <= memo[bit]) {
			return memo[bit];
		}
		if (bit == n2 - 1) {
			return x;
		}

		int max = 0;
		for (int i = 0; i < n; i++) {
			if ((bit >> i & 1) == 0) {
				int val = dfs(x % a[i], bit + (1 << i));
				max = Math.max(max, val);
			}
		}
		memo[bit] = Math.max(memo[bit], max);
		return memo[bit];
	}
}
0