結果
問題 | No.861 ケーキカット |
ユーザー |
|
提出日時 | 2022-01-01 17:07:46 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 435 ms / 1,000 ms |
コード長 | 2,005 bytes |
コンパイル時間 | 14,044 ms |
コンパイル使用メモリ | 391,040 KB |
実行使用メモリ | 50,224 KB |
最終ジャッジ日時 | 2024-10-10 08:13:33 |
合計ジャッジ時間 | 23,614 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
use std::cmp::*;use std::collections::*;// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8macro_rules! input {($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}macro_rules! input_inner {($next:expr) => {};($next:expr,) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}macro_rules! read_value {($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));}fn main() {input!(c: [i64; 25]);let s: i64 = c.iter().sum();let mut mi = 1i64 << 50;let mut is_conn = vec![false; 1 << 25];let mut que = VecDeque::new();for i in 0..25 {que.push_back(1 << i);}while let Some(v) = que.pop_front() {if is_conn[v] { continue; }is_conn[v] = true;let mut adj = (v << 1) & 0x1ef7bde;adj |= (v >> 1) & 0xf7bdef;adj |= v << 5;adj |= v >> 5;adj &= !v;for i in 0..25 {if (adj & 1 << i) == 0 { continue; }let new = v | 1 << i;if is_conn[new] { continue; }que.push_back(new);}}for bits in 1..1 << 24 {if is_conn[bits] && is_conn[(1 << 25) - 1 - bits] {let mut tmp = s;for i in 0..25 {if (bits & 1 << i) != 0 {tmp -= 2 * c[i];}}mi = min(mi, tmp.abs());}}println!("{}", mi);}