結果

問題 No.1416 ショッピングモール
ユーザー tzyvrntzyvrn
提出日時 2021-03-05 22:55:23
言語 Rust
(1.72.1)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 6,978 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 165,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-29 03:28:46
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: function `usize1` is never used
   --> Main.rs:139:12
    |
139 |     pub fn usize1(n: usize) -> usize {
    |            ^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: function `bytes` is never used
   --> Main.rs:144:12
    |
144 |     pub fn bytes(s: String) -> Vec<u8> {
    |            ^^^^^

warning: 2 warnings emitted

ソースコード

diff #

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };

    let mut a = a;
    a.sort();
    a.reverse();

    // let mut size = 1i64;
    let mut ans = 0i64;
    for (i, ai) in a.iter().copied().enumerate() {
        ans += ai * (bit_len(i + 1) - 1);
    }
    println!("{}", ans);
}

pub fn bit_len(n: usize) -> i64 {
    let mut len = 0;
    loop {
        if (1 << len) > n {
            break;
        }
        len += 1;
    }

    len
}

// from https://github.com/qryxip/competitive-programming-library/blob/master/crates/io/sourcefiles/input.rs
mod input {
    //! Provides `input!` macro.
    //!
    //! # Example
    //!
    //! ```no_run
    //! #[macro_use]
    //! extern crate input as _;
    //!
    //! fn main() {
    //!     // https://atcoder.jp/contests/abc166/tasks/abc166_b
    //!
    //!     input! {
    //!         n: usize,
    //!         ass: [[{ input::usize1 }]],
    //!     }
    //!
    //!     let _: usize = n;
    //!     let _: Vec<Vec<usize>> = ass;
    //! }
    //! ```

    use std::{
        cell::RefCell,
        fmt::Debug,
        io::{self, BufRead, Read},
        rc::Rc,
        str::{FromStr, SplitWhitespace},
    };

    #[macro_export]
    macro_rules! input {
        (from $scanner:ident; $($tt:tt)*) => {
            $crate::input_inner!(@scanner($scanner), @tts($($tt)*))
        };
        ($($tt:tt)*) => {
            let __scanner = $crate::input::DEFAULT_SCANNER.with(|__scanner| __scanner.clone());
            let mut __scanner_ref = __scanner.borrow_mut();
            if let $crate::input::Scanner::Uninited = *__scanner_ref {
                *__scanner_ref = $crate::input::Scanner::stdin_auto().unwrap();
            }
            $crate::input_inner!(@scanner(__scanner_ref), @tts($($tt)*));
            ::std::mem::drop(__scanner_ref);
            ::std::mem::drop(__scanner);
        };
    }

    #[macro_export]
    macro_rules! input_inner {
        (@scanner($scanner:ident), @tts()) => {};
        (@scanner($scanner:ident), @tts(mut $single_tt_pat:tt : $readable:tt)) => {
            let mut $single_tt_pat = $crate::read!(from $scanner { $readable });
        };
        (@scanner($scanner:ident), @tts($single_tt_pat:tt : $readable:tt)) => {
            let $single_tt_pat = $crate::read!(from $scanner { $readable });
        };
        (@scanner($scanner:ident), @tts(mut $single_tt_pat:tt : $readable:tt, $($rest:tt)*)) => {
            $crate::input_inner!(@scanner($scanner), @tts(mut $single_tt_pat: $readable));
            $crate::input_inner!(@scanner($scanner), @tts($($rest)*));
        };
        (@scanner($scanner:ident), @tts($single_tt_pat:tt : $readable:tt, $($rest:tt)*)) => {
            $crate::input_inner!(@scanner($scanner), @tts($single_tt_pat: $readable));
            $crate::input_inner!(@scanner($scanner), @tts($($rest)*));
        };
    }

    #[macro_export]
    macro_rules! read {
        (from $scanner:ident { [$tt:tt] }) => {
            $crate::read!(from $scanner { [$tt; $crate::read!(from $scanner { usize })] })
        };
        (from $scanner:ident  { [$tt:tt; $n:expr] }) => {
            (0..$n).map(|_| $crate::read!(from $scanner { $tt })).collect::<Vec<_>>()
        };
        (from $scanner:ident { ($($tt:tt),+) }) => {
            ($($crate::read!(from $scanner { $tt })),*)
        };
        (from $scanner:ident { { $f:expr } }) => {
            $crate::input::FnOnceExt::<_>::call_once_from_reader($f, &mut $scanner)
        };
        (from $scanner:ident { $ty:ty }) => {
            <$ty as $crate::input::Readable>::read_from_scanner(&mut $scanner)
        };
    }

    #[macro_export]
    macro_rules! readable {
    ($name:ident; |$scanner:ident| { $($body:tt)* }) => {
        $crate::readable!($name; |$scanner| -> () { $($body)* });
    };
    ($name:ident; |$scanner:ident| $expr:expr) => {
        $crate::readable!($name; |$scanner| -> () { $expr });
    };
    ($name:ident; |$scanner:ident| -> $output:ty { $($body:tt)* }) => {
        enum $name {}

        impl $crate::input::Readable for $name {
            type Output = $output;

            fn read_from_scanner(mut $scanner: &mut $crate::input::Scanner) -> $output {
                $($body)*
            }
        }
    };
}

    #[inline]
    pub fn usize1(n: usize) -> usize {
        n - 1
    }

    #[inline]
    pub fn bytes(s: String) -> Vec<u8> {
        s.into()
    }

    #[doc(hidden)]
    pub trait FnOnceExt<A> {
        type Output;
        fn call_once_from_reader(this: Self, scanner: &mut Scanner) -> Self::Output;
    }

    impl<A, O, F> FnOnceExt<A> for F
    where
        A: FromStr,
        A::Err: Debug,
        F: FnOnce(A) -> O,
    {
        type Output = O;

        #[inline]
        fn call_once_from_reader(this: Self, scanner: &mut Scanner) -> O {
            this(A::read_from_scanner(scanner))
        }
    }

    pub enum Scanner {
        Uninited,
        Once {
            words: SplitWhitespace<'static>,
        },
        Lines {
            rdr: Box<dyn BufRead>,
            words: SplitWhitespace<'static>,
        },
    }

    impl Scanner {
        pub fn stdin_auto() -> io::Result<Self> {
            if cfg!(debug_assertions) {
                Ok(Self::lines(Box::leak(Box::new(io::stdin())).lock()))
            } else {
                Self::once(io::stdin())
            }
        }

        pub fn once<R: Read>(mut rdr: R) -> io::Result<Self> {
            let mut buf = String::with_capacity(1024);
            rdr.read_to_string(&mut buf)?;
            let words = Box::leak(buf.into_boxed_str()).split_whitespace();
            Ok(Self::Once { words })
        }

        pub fn lines<R: BufRead + 'static>(rdr: R) -> Self {
            Self::Lines {
                rdr: Box::new(rdr),
                words: "".split_whitespace(),
            }
        }

        pub fn parse_next_unwrap<T: FromStr>(&mut self) -> T
        where
            T::Err: Debug,
        {
            match self {
                Self::Uninited => None,
                Self::Once { words } => words.next(),
                Self::Lines { rdr, words } => words.next().or_else(|| {
                    let mut line = "".to_owned();
                    rdr.read_line(&mut line).unwrap();
                    *words = Box::leak(line.into_boxed_str()).split_whitespace();
                    words.next()
                }),
            }
            .expect("reached EOF")
            .parse()
            .unwrap()
        }
    }

    thread_local! {
        pub static DEFAULT_SCANNER: Rc<RefCell<Scanner>> = Rc::new(RefCell::new(Scanner::Uninited));
    }

    pub trait Readable {
        type Output;

        fn read_from_scanner(scanner: &mut Scanner) -> Self::Output;
    }

    impl<T: FromStr> Readable for T
    where
        T::Err: Debug,
    {
        type Output = Self;

        fn read_from_scanner(scanner: &mut Scanner) -> Self {
            scanner.parse_next_unwrap()
        }
    }
}
0