結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー tonyu0tonyu0
提出日時 2021-01-22 22:38:40
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 1,213 bytes
コンパイル時間 16,951 ms
コンパイル使用メモリ 379,836 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-28 03:37:21
合計ジャッジ時間 23,123 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

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

    let mut ans = -(1i64 << 60);
    let mut uuu: Vec<usize> = vec![];
    for bit in 1..1 << n {
        let mut tmp = 0;
        let mut tmpu = Vec::new();
        for i in 0..n {
            if bit >> i & 1 == 1 {
                tmp += a[i];
                tmpu.push(i + 1);
            }
        }
        for i in 0..n {
            for j in i + 1..n {
                if bit >> i & 1 == 1 && bit >> j & 1 == 1 {
                    tmp += b[i][j];
                }
            }
        }
        if tmp > ans {
            ans = tmp;
            uuu = tmpu;
        }
    }
    println!("{}", ans);
    for i in 0..uuu.len() {
        print!("{} ", uuu[i]);
    }
    println!("")
}
0