結果
問題 | No.1083 余りの余り |
ユーザー |
|
提出日時 | 2022-11-22 11:55:03 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 959 bytes |
コンパイル時間 | 13,315 ms |
コンパイル使用メモリ | 383,324 KB |
実行使用メモリ | 18,216 KB |
最終ジャッジ日時 | 2024-09-22 21:17:15 |
合計ジャッジ時間 | 15,904 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 WA * 1 |
ソースコード
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[i] % a[j];}}}println!("{}", dp[(1<<n)-1]);}