結果

問題 No.1083 余りの余り
ユーザー ks2m
提出日時 2020-06-19 22:02:51
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 574 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 74,628 KB
実行使用メモリ 58,432 KB
最終ジャッジ日時 2024-07-03 14:38:35
合計ジャッジ時間 8,654 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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

		int n2 = 1 << n;
		int[] dp = new int[n2];
		dp[0] = k;
		for (int i = 1; i < n2; i++) {
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					int pre = i - (1 << j);
					dp[i] = Math.max(dp[i], dp[pre] % a[j]);
				}
			}
		}
		System.out.println(dp[n2 - 1]);
	}
}
0