結果

問題 No.2561 みんな大好きmod 998
ユーザー ikdikd
提出日時 2023-12-02 15:01:09
言語 Rust
(1.77.0)
結果
AC  
実行時間 255 ms / 4,000 ms
コード長 5,231 bytes
コンパイル時間 1,109 ms
コンパイル使用メモリ 192,172 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-02 15:01:18
合計ジャッジ時間 5,421 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 10 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 255 ms
6,548 KB
testcase_04 AC 253 ms
6,548 KB
testcase_05 AC 253 ms
6,548 KB
testcase_06 AC 251 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 1 ms
6,548 KB
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 1 ms
6,548 KB
testcase_11 AC 38 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 1 ms
6,548 KB
testcase_14 AC 0 ms
6,548 KB
testcase_15 AC 252 ms
6,548 KB
testcase_16 AC 1 ms
6,548 KB
testcase_17 AC 1 ms
6,548 KB
testcase_18 AC 1 ms
6,548 KB
testcase_19 AC 179 ms
6,548 KB
testcase_20 AC 1 ms
6,548 KB
testcase_21 AC 1 ms
6,548 KB
testcase_22 AC 1 ms
6,548 KB
testcase_23 AC 1 ms
6,548 KB
testcase_24 AC 1 ms
6,548 KB
testcase_25 AC 1 ms
6,548 KB
testcase_26 AC 52 ms
6,548 KB
testcase_27 AC 254 ms
6,548 KB
testcase_28 AC 71 ms
6,548 KB
testcase_29 AC 19 ms
6,548 KB
testcase_30 AC 58 ms
6,548 KB
testcase_31 AC 125 ms
6,548 KB
testcase_32 AC 30 ms
6,548 KB
testcase_33 AC 20 ms
6,548 KB
testcase_34 AC 254 ms
6,548 KB
testcase_35 AC 18 ms
6,548 KB
testcase_36 AC 18 ms
6,548 KB
testcase_37 AC 9 ms
6,548 KB
testcase_38 AC 38 ms
6,548 KB
testcase_39 AC 58 ms
6,548 KB
testcase_40 AC 58 ms
6,548 KB
testcase_41 AC 38 ms
6,548 KB
testcase_42 AC 71 ms
6,548 KB
testcase_43 AC 9 ms
6,548 KB
testcase_44 AC 28 ms
6,548 KB
testcase_45 AC 181 ms
6,548 KB
testcase_46 AC 24 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub use __cargo_equip::prelude::*;

use next_permutation::NextPermutation;
use scanner::Scanner;
use std::io;

fn main() {
    let mut scanner = Scanner::from(io::stdin().lock());
    let (n, k) = scan!((usize, usize), <~ scanner);
    let a = scan!([u64; n], <~ scanner);

    let mut ord = vec![false; n];
    for i in 0..k {
        ord[i] = true;
    }
    ord.sort();
    let mut ans = 0;
    loop {
        let mut s1 = 0;
        let mut s2 = 0;
        for (i, &f) in ord.iter().enumerate() {
            if f == false {
                continue;
            }
            s1 += a[i];
            s1 %= 998244353;
            s2 += a[i];
            s2 %= 998;
        }
        if s1 <= s2 {
            ans += 1;
            ans %= 998;
        }
        if ord.next_permutation() == false {
            break;
        }
    }
    println!("{}", ans);
}

// ✂ --- scanner --- ✂
#[allow(unused)]
mod scanner {
    pub use crate::__cargo_equip::prelude::*;

    use std::fmt;
    use std::io;
    use std::str;

    pub struct Scanner<R> {
        r: R,
        l: String,
        i: usize,
    }

    impl<R> Scanner<R>
    where
        R: io::BufRead,
    {
        pub fn new(reader: R) -> Self {
            Self {
                r: reader,
                l: String::new(),
                i: 0,
            }
        }

        pub fn scan<T>(&mut self) -> T
        where
            T: str::FromStr,
            T::Err: fmt::Debug,
        {
            self.skip_blanks();
            assert!(self.i < self.l.len()); // remain some character
            assert_ne!(&self.l[self.i..=self.i], " ");
            let rest = &self.l[self.i..];
            let len = rest
                .find(|ch| char::is_ascii_whitespace(&ch))
                .unwrap_or_else(|| rest.len());
            // parse self.l[self.i..(self.i + len)]
            let val = rest[..len]
                .parse()
                .unwrap_or_else(|e| panic!("{:?}, attempt to read `{}`", e, rest));
            self.i += len;
            val
        }

        pub fn scan_vec<T>(&mut self, n: usize) -> Vec<T>
        where
            T: str::FromStr,
            T::Err: fmt::Debug,
        {
            (0..n).map(|_| self.scan()).collect::<Vec<_>>()
        }

        fn skip_blanks(&mut self) {
            loop {
                match self.l[self.i..].find(|ch| !char::is_ascii_whitespace(&ch)) {
                    Some(j) => {
                        self.i += j;
                        break;
                    }
                    None => {
                        self.l.clear(); // clear buffer
                        let num_bytes = self
                            .r
                            .read_line(&mut self.l)
                            .unwrap_or_else(|_| panic!("invalid UTF-8"));
                        assert!(num_bytes > 0, "reached EOF :(");
                        self.i = 0;
                    }
                }
            }
        }
    }

    impl<'a> From<&'a str> for Scanner<&'a [u8]> {
        fn from(s: &'a str) -> Self {
            Self::new(s.as_bytes())
        }
    }

    impl<'a> From<io::StdinLock<'a>> for Scanner<io::BufReader<io::StdinLock<'a>>> {
        fn from(stdin: io::StdinLock<'a>) -> Self {
            Self::new(io::BufReader::new(stdin))
        }
    }

    #[macro_export]
    macro_rules! scan {
        (( $($t: ty),+ ), <~ $scanner: expr) => {
            ( $(scan!($t, <~ $scanner)),+ )
        };
        ([ $t: tt; $n: expr ], <~ $scanner: expr) => {
            (0..$n).map(|_| scan!($t, <~ $scanner)).collect::<Vec<_>>()
        };
        ($t: ty, <~ $scanner: expr) => {
            $scanner.scan::<$t>()
        };
    }
}
// ✂ --- scanner --- ✂

// The following code was expanded by `cargo-equip`.

///  # Bundled libraries
///
///  - `next_permutation 0.1.0 (git+https://github.com/ia7ck/rust-competitive-programming#f49de25336b2de6602bce284a44ec4b9d163e9f4)` licensed under `CC0-1.0` as `crate::__cargo_equip::crates::next_permutation`
#[allow(unused)]
mod __cargo_equip {
    pub(crate) mod crates {
        pub mod next_permutation {
            pub trait NextPermutation {
                fn next_permutation(&mut self) -> bool;
            }

            impl<T: Ord> NextPermutation for [T] {
                fn next_permutation(&mut self) -> bool {
                    if self.len() <= 1 {
                        return false;
                    }
                    let mut i = self.len() - 1;
                    while i > 0 && self[i - 1] >= self[i] {
                        i -= 1;
                    }
                    if i == 0 {
                        return false;
                    }
                    let mut j = self.len() - 1;
                    while self[i - 1] >= self[j] {
                        j -= 1;
                    }
                    self.swap(i - 1, j);
                    self[i..].reverse();
                    true
                }
            }
        }
    }

    pub(crate) mod macros {
        pub mod next_permutation {}
    }

    pub(crate) mod prelude {
        pub use crate::__cargo_equip::crates::*;
    }

    mod preludes {
        pub mod next_permutation {}
    }
}
0