結果
問題 | No.1083 余りの余り |
ユーザー |
|
提出日時 | 2022-11-22 11:47:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 973 bytes |
コンパイル時間 | 12,089 ms |
コンパイル使用メモリ | 405,412 KB |
実行使用メモリ | 18,336 KB |
最終ジャッジ日時 | 2024-09-22 21:10:01 |
合計ジャッジ時間 | 15,537 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 WA * 3 |
ソースコード
const INF: usize = 1usize << 60;fn main() {let mut nk = String::new();std::io::stdin().read_line(&mut nk).ok();let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let n = nk[0];let k = nk[1];let mut a = String::new();std::io::stdin().read_line(&mut a).ok();let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let mut other_mins = vec![INF; 1<<n];for i in 0..1<<n {other_mins[i] = (0..n).filter(|&j| ((i >> j) & 1) == 0).map(|j| a[j]).min().unwrap_or(INF);}let mut dp = vec![0usize; 1<<n];dp[0] = k;for i in 0..1<<n {for j in 0..n {if ((i >> j) & 1) == 1 { continue; }let idx = i | (1 << j);if dp[idx] % other_mins[idx] < dp[i] % a[j] % other_mins[idx] {dp[idx] = dp[idx].max(dp[i] % a[j]);}}}println!("{}", dp[(1<<n)-1]);}