結果
| 問題 |
No.1083 余りの余り
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2020-06-19 21:46:39 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 765 bytes |
| コンパイル時間 | 2,443 ms |
| コンパイル使用メモリ | 77,316 KB |
| 実行使用メモリ | 63,584 KB |
| 最終ジャッジ日時 | 2024-07-03 14:14:23 |
| 合計ジャッジ時間 | 7,404 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 TLE * 1 -- * 28 |
ソースコード
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];
}
}
ks2m