結果
| 問題 |
No.1360 [Zelkova 4th Tune] 協和音
|
| コンテスト | |
| ユーザー |
Strorkis
|
| 提出日時 | 2021-01-22 21:45:05 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 145 ms / 2,000 ms |
| コード長 | 2,445 bytes |
| コンパイル時間 | 14,464 ms |
| コンパイル使用メモリ | 378,348 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-27 23:26:15 |
| 合計ジャッジ時間 | 21,202 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 |
ソースコード
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()));
}
Strorkis