結果
問題 | No.1463 Hungry Kanten |
ユーザー | Strorkis |
提出日時 | 2021-04-03 09:57:19 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,142 bytes |
コンパイル時間 | 12,171 ms |
コンパイル使用メモリ | 377,360 KB |
実行使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2024-06-06 19:21:10 |
合計ジャッジ時間 | 13,435 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 4 ms
5,248 KB |
testcase_03 | AC | 27 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 80 ms
6,144 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 0 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 4 ms
5,376 KB |
testcase_17 | AC | 9 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 1 ms
5,376 KB |
ソースコード
#[allow(dead_code)] mod mod_int { use std::{fmt, ops}; #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] pub struct ModInt(u64); impl ModInt { const MOD: u64 = 998_244_353; pub fn new(mut x: u64) -> Self { if x >= Self::MOD { x %= Self::MOD; } Self(x) } pub fn zero() -> Self { Self(0) } pub fn one() -> Self { Self(1) } } impl From<usize> for ModInt { fn from(x: usize) -> Self { Self::new(x as u64) } } impl From<i64> for ModInt { fn from(mut x: i64) -> Self { let m = Self::MOD as i64; if x.abs() >= m { x %= m; } if x < 0 { x += m } Self::new(x as u64) } } impl ops::Add for ModInt { type Output = Self; fn add(self, other: Self) -> Self { let mut x = self.0 + other.0; if x >= Self::MOD { x -= Self::MOD; } Self(x) } } impl ops::AddAssign for ModInt { fn add_assign(&mut self, other: Self) { *self = *self + other; } } impl ops::Sub for ModInt { type Output = Self; fn sub(mut self, other: Self) -> Self { if self.0 < other.0 { self.0 += Self::MOD; } Self(self.0 - other.0) } } impl ops::SubAssign for ModInt { fn sub_assign(&mut self, other: Self) { *self = *self - other; } } impl ops::Mul for ModInt { type Output = Self; fn mul(self, other: Self) -> Self { Self::new(self.0 * other.0) } } impl ops::MulAssign for ModInt { fn mul_assign(&mut self, other: Self) { *self = *self * other; } } impl fmt::Display for ModInt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) } } impl ModInt { pub fn pow(mut self, mut n: u64) -> Self { let mut res = Self::one(); while n > 0 { if n & 1 == 1 { res *= self; } self *= self; n >>= 1; } res } pub fn inv(self) -> Self { self.pow(Self::MOD - 2) } } } use mod_int::ModInt; fn run<'a, I, W>(mut scanner: I, mut writer: W) where I: Iterator<Item = &'a str>, W: std::io::Write, { macro_rules! scan { ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>()); (($($t:tt),*)) => (($(scan!($t)),*)); (Usize1) => (scan!(usize) - 1); (Bytes) => (scan!(String).into_bytes()); ($t:ty) => (scanner.next().unwrap().parse::<$t>().unwrap()); } macro_rules! input { ($($($v:ident)* : $t:tt),* $(,)?) => ($(let $($v)* = scan!($t);)*); } macro_rules! println { ($($arg:tt)*) => (writeln!(writer, $($arg)*).ok()); } input! { n: usize, k: u32, a: [u64; n], } let mut set = std::collections::BTreeSet::new(); for bit in 0u32..1 << n { if bit.count_ones() < k { continue; } let mut sum = ModInt::zero(); let mut product = ModInt::one(); for (i, &a) in a.iter().enumerate() { if bit >> i & 1 == 1 { let a = ModInt::new(a); sum += a; product *= a; } } set.insert(sum); set.insert(product); } let ans = set.len(); println!("{}", ans); } fn main() { let ref mut buf = Vec::new(); std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok(); let scanner = unsafe { std::str::from_utf8_unchecked(buf).split_ascii_whitespace() }; let stdout = std::io::stdout(); let writer = std::io::BufWriter::new(stdout.lock()); run(scanner, writer); }