結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー StrorkisStrorkis
提出日時 2021-01-22 21:45:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 2,445 bytes
コンパイル時間 3,537 ms
コンパイル使用メモリ 153,984 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 18:27:00
合計ジャッジ時間 10,464 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 22 ms
4,376 KB
testcase_25 AC 101 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 101 ms
4,384 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 10 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 101 ms
4,380 KB
testcase_34 AC 101 ms
4,376 KB
testcase_35 AC 101 ms
4,380 KB
testcase_36 AC 102 ms
4,380 KB
testcase_37 AC 101 ms
4,376 KB
testcase_38 AC 101 ms
4,376 KB
testcase_39 AC 101 ms
4,380 KB
testcase_40 AC 101 ms
4,376 KB
testcase_41 AC 100 ms
4,376 KB
testcase_42 AC 101 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 100 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 101 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{BufRead, Write};

struct Lines<B> { b: B, buf: Vec<u8> }
 
impl<B: BufRead> Lines<B> {
    fn next(&mut self) -> &str {
        self.buf.clear();
        self.b.read_until(b'\n', &mut self.buf).ok();
        if self.buf.ends_with(&[b'\n']) {
            self.buf.pop();
            if self.buf.ends_with(&[b'\r']) {
                self.buf.pop();
            }
        }
        std::str::from_utf8(&self.buf).unwrap()
    }
}

macro_rules! parse {
    ($s:expr, Usize1) => (parse!($s, usize) - 1);
    ($s:expr, Bytes) => ($s.as_bytes().to_vec());
    ($s:expr, Chars) => ($s.chars().collect::<Vec<_>>());
    ($s:expr, $t:ty) => ($s.parse::<$t>().unwrap());
}

macro_rules! scan {
    ($iter:expr, ($($t:ident),*)) => (
        ($(scan!($iter, $t)),*)
    );
    ($iter:expr, [$t:ident]) => (
        $iter.map(|s| parse!(s, $t)).collect::<Vec<_>>()
    );
    ($iter:expr, $t:ident) => (
        parse!($iter.next().unwrap(), $t)
    );
}

macro_rules! read {
    ($lines:expr, [$t:tt; $n:expr]) => (
        (0..$n).map(|_| read!($lines, $t)).collect::<Vec<_>>()
    );
    ($lines:expr, $t:tt) => ({
        let iter = &mut $lines.next().split(' ');
        scan!(iter, $t)
    });
}

fn run<B: BufRead, W: Write>(mut lines: Lines<B>, mut writer: W) {
    let n = read!(lines, usize);
    let a = read!(lines, [i64]);
    let b = read!(lines, [[i64]; n]);

    let mut ans: usize = 0;
    let mut max = i64::MIN;
    for i in 1..(1 << n) {
        let mut res = 0;
        for (j, (a, b)) in a.iter().zip(b.iter()).enumerate() {
            if i >> j & 1 == 0 { continue; }
            res += a;
            for (k, b) in b.iter().enumerate() {
                if j == k { break; }
                if i >> k & 1 == 0 { continue; }
                res += b;
            }
        }
        if max < res {
            ans = i;
            max = res;
        }
    }

    writeln!(writer, "{}", max).ok();
    let m = ans.count_ones() as usize;
    let mut buf = Vec::with_capacity(m);
    for i in 0..n {
        if ans >> i & 1 == 0 { continue; }
        buf.push(i + 1);
    }
    for i in buf.iter().take(m.saturating_sub(1)) {
        write!(writer, "{} ", i).ok();
    }
    writeln!(writer, "{}", buf.last().unwrap()).ok();
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let lines = Lines { b: stdin.lock(), buf: Vec::new() };
    run(lines, std::io::BufWriter::new(stdout.lock()));
}
0