結果
| 問題 | No.1083 余りの余り | 
| コンテスト | |
| ユーザー |  Strorkis | 
| 提出日時 | 2020-06-19 23:13:29 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,083 bytes | 
| コンパイル時間 | 13,191 ms | 
| コンパイル使用メモリ | 400,616 KB | 
| 実行使用メモリ | 206,716 KB | 
| 最終ジャッジ日時 | 2024-07-03 15:35:02 | 
| 合計ジャッジ時間 | 26,778 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 WA * 1 | 
ソースコード
fn main() {
    let (n, k): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };
    let mut dp = vec![vec![0; n]; 1 << n];
    for i in 0..n {
        dp[1 << i][i] = k % a[i];
    }
    for s in 1..(1 << n) {
        for i in 0..n {
            if (s & (1 << i)) != 0 { continue; }
            for j in 0..n {
                dp[s | (1 << i)][i] = {
                    std::cmp::max(
                        dp[s | (1 << i)][i],
                        dp[s][j] % a[i],
                    )
                }
            }
        }
    }
    
    let ans = dp[(1 << n) - 1].iter().max().unwrap();
    println!("{}", ans);
}
            
            
            
        