結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー phspls
提出日時 2022-10-08 12:06:26
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,264 bytes
コンパイル時間 12,744 ms
コンパイル使用メモリ 402,112 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 13:13:43
合計ジャッジ時間 17,790 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: isize = 1isize << 60;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let b = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<isize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            temp
        })
        .collect::<Vec<_>>();

    let mut pairs = 0usize;
    let mut result = -INF;
    for i in 1..1usize<<n {
        let mut score = (0..n).filter(|&j| ((i >> j) & 1) == 1).map(|j| a[j]).sum::<isize>();
        for j in 0..n {
            if ((i >> j) & 1) == 0 { continue; }
            for k in j+1..n {
                if ((i >> k) & 1) == 0 { continue; }
                score += b[j][k];
            }
        }
        if score > result {
            result = score;
            pairs = i;
        }
    }
    println!("{}", result);
    println!("{}", (0..n).filter(|&i| ((pairs >> i) & 1) == 1).map(|i| (i+1).to_string()).collect::<Vec<_>>().join(" "));
}
0