提出 #16451459


ソースコード 拡げる

// template {{{
#![allow(clippy::many_single_char_names)]

#[allow(dead_code)]
mod ngtio {
    use ::std::collections::VecDeque;

    pub struct Buffer {
        buf: VecDeque<String>,
    }

    impl Buffer {
        pub fn new() -> Self {
            Self {
                buf: VecDeque::new(),
            }
        }

        fn load(&mut self) {
            while self.buf.is_empty() {
                let mut s = String::new();
                let length = ::std::io::stdin().read_line(&mut s).unwrap();
                if length == 0 {
                    break;
                }
                self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
            }
        }

        pub fn string(&mut self) -> String {
            self.load();
            self.buf
                .pop_front()
                .unwrap_or_else(|| panic!("入力が終了したのですが。"))
        }

        pub fn string_char_vec(&mut self) -> Vec<char> {
            let s = self.string();
            s.chars().collect::<Vec<_>>()
        }

        pub fn string_char_vec_trusted_len(&mut self, len: usize) -> Vec<char> {
            let s = self.string();
            let s = s.chars().collect::<Vec<_>>();
            assert_eq!(s.len(), len, "あら、思ったのと長さ違いますね……");
            s
        }

        pub fn char(&mut self) -> char {
            let string = self.string();
            let mut chars = string.chars();
            let res = chars.next().unwrap();
            assert!(
                chars.next().is_none(),
                "char で受け取りたいのも山々なのですが、さては 2 文字以上ありますね?"
            );
            res
        }

        pub fn read<T: ::std::str::FromStr>(&mut self) -> T
        where
            <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            self.string()
                .parse::<T>()
                .expect("Failed to parse the input.")
        }

        pub fn read_vec<T: ::std::str::FromStr>(&mut self, len: usize) -> Vec<T>
        where
            <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            (0..len).map(|_| self.read::<T>()).collect()
        }
    }

    macro_rules! define_primitive_reader {
        ($($ty:tt,)*) => {
            impl Buffer {
                $(
#[inline]
                    pub fn $ty(&mut self) -> $ty {
                        self.read::<$ty>()
                    }
                )*
            }
        }
    }

    define_primitive_reader! {
        u8, u16, u32, u64, usize,
        i8, i16, i32, i64, isize,
    }

    impl Default for Buffer {
        fn default() -> Self {
            Self::new()
        }
    }
}

#[allow(unused_imports)]
use std::{collections, iter, mem};
// }}}
// gridtools {{{
#[allow(dead_code)]
mod gridtools {
    pub fn exact_size_of_grid<T>(table: &[Vec<T>]) -> (usize, usize) {
        assert!(!table.is_empty());
        let w = table.first().unwrap().len();
        assert!(table.iter().all(|v| v.len() == w));
        (table.len(), w)
    }

    pub fn transpose<T: Clone>(table: &[Vec<T>]) -> Vec<Vec<T>> {
        let (h, w) = exact_size_of_grid(&table);
        (0..w)
            .map(|j| (0..h).map(|i| table[i][j].clone()).collect::<Vec<_>>())
            .collect::<Vec<_>>()
    }

    pub fn anti_transpose<T: Clone>(table: &[Vec<T>]) -> Vec<Vec<T>> {
        let (h, w) = exact_size_of_grid(&table);
        (0..w)
            .rev()
            .map(|j| {
                (0..h)
                    .rev()
                    .map(|i| table[i][j].clone())
                    .collect::<Vec<_>>()
            })
            .collect::<Vec<_>>()
    }

    pub fn reflect_vertically<T: Clone>(table: &[Vec<T>]) -> Vec<Vec<T>> {
        table
            .iter()
            .map(|v| v.iter().rev().cloned().collect::<Vec<_>>())
            .collect::<Vec<_>>()
    }

    pub fn reflect_horizontally<T: Clone>(table: &[Vec<T>]) -> Vec<Vec<T>> {
        table.iter().rev().cloned().collect::<Vec<_>>()
    }

    pub fn rotate_right<T: Clone>(table: &[Vec<T>]) -> Vec<Vec<T>> {
        let (h, w) = exact_size_of_grid(&table);
        (0..w)
            .map(|j| {
                (0..h)
                    .rev()
                    .map(|i| table[i][j].clone())
                    .collect::<Vec<_>>()
            })
            .collect::<Vec<_>>()
    }

    pub fn rotate_left<T: Clone>(table: &[Vec<T>]) -> Vec<Vec<T>> {
        let (h, w) = exact_size_of_grid(&table);
        (0..w)
            .rev()
            .map(|j| (0..h).map(|i| table[i][j].clone()).collect::<Vec<_>>())
            .collect::<Vec<_>>()
    }

    pub fn rotate_180<T: Clone>(table: &[Vec<T>]) -> Vec<Vec<T>> {
        table
            .iter()
            .rev()
            .map(|v| v.iter().rev().cloned().collect::<Vec<_>>())
            .collect::<Vec<_>>()
    }
}
// }}}

fn main() {
    let mut buf = ngtio::Buffer::new();
    let mut h = buf.usize();
    let mut w = buf.usize();
    let a = iter::repeat_with(|| iter::repeat_with(|| buf.u32()).take(w).collect::<Vec<_>>())
        .take(h)
        .collect::<Vec<_>>();
    let a = gridtools::transpose(&a);
    mem::swap(&mut h, &mut w);
    let ans = (0..1 << w)
        .map(|bs| {
            a.iter()
                .map(|v| {
                    let x = v
                        .iter()
                        .enumerate()
                        .map(|(i, &x)| x ^ (bs >> i & 1))
                        .sum::<u32>();
                    std::cmp::max(x, w as u32 - x)
                })
                .sum::<u32>()
        })
        .max()
        .unwrap();
    println!("{}", ans);
}

提出情報

提出日時
問題 E - おせんべい
ユーザ ngtkana
言語 Rust (1.42.0)
得点 100
コード長 5911 Byte
結果 AC
実行時間 138 ms
メモリ 3204 KiB

ジャッジ結果

セット名 set01 set02 set03 set04 set05
得点 / 配点 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
結果
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
セット名 テストケース
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
ケース名 結果 実行時間 メモリ
data1 AC 9 ms 2076 KiB
data2 AC 2 ms 2056 KiB
data3 AC 4 ms 2176 KiB
data4 AC 78 ms 2652 KiB
data5 AC 138 ms 3204 KiB