結果
問題 | No.1330 Multiply or Divide |
ユーザー | Strorkis |
提出日時 | 2021-01-09 11:23:17 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,642 bytes |
コンパイル時間 | 10,625 ms |
コンパイル使用メモリ | 401,060 KB |
実行使用メモリ | 9,152 KB |
最終ジャッジ日時 | 2024-11-17 13:35:00 |
合計ジャッジ時間 | 12,568 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 14 ms
9,152 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 0 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 0 ms
6,816 KB |
testcase_06 | AC | 7 ms
6,820 KB |
testcase_07 | AC | 39 ms
6,816 KB |
testcase_08 | AC | 42 ms
8,380 KB |
testcase_09 | AC | 43 ms
7,868 KB |
testcase_10 | AC | 40 ms
8,256 KB |
testcase_11 | AC | 38 ms
8,636 KB |
testcase_12 | AC | 41 ms
8,256 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 9 ms
6,816 KB |
testcase_19 | AC | 8 ms
6,820 KB |
testcase_20 | AC | 8 ms
6,820 KB |
testcase_21 | AC | 9 ms
6,816 KB |
testcase_22 | AC | 8 ms
6,820 KB |
testcase_23 | AC | 12 ms
6,816 KB |
testcase_24 | AC | 1 ms
6,816 KB |
testcase_25 | AC | 1 ms
6,820 KB |
testcase_26 | AC | 1 ms
6,820 KB |
testcase_27 | AC | 1 ms
6,816 KB |
testcase_28 | AC | 1 ms
6,820 KB |
testcase_29 | AC | 1 ms
6,820 KB |
testcase_30 | AC | 1 ms
6,824 KB |
testcase_31 | AC | 1 ms
6,816 KB |
testcase_32 | AC | 1 ms
6,816 KB |
testcase_33 | AC | 1 ms
6,820 KB |
testcase_34 | AC | 7 ms
6,816 KB |
testcase_35 | AC | 2 ms
6,820 KB |
testcase_36 | AC | 6 ms
6,816 KB |
testcase_37 | AC | 5 ms
6,820 KB |
testcase_38 | AC | 4 ms
6,816 KB |
testcase_39 | AC | 3 ms
6,816 KB |
testcase_40 | AC | 3 ms
6,820 KB |
testcase_41 | AC | 2 ms
6,820 KB |
testcase_42 | AC | 5 ms
6,816 KB |
testcase_43 | AC | 6 ms
6,816 KB |
testcase_44 | AC | 9 ms
6,816 KB |
testcase_45 | AC | 8 ms
6,816 KB |
ソースコード
struct Scanner<R> { r: R, buf: Vec<u8> } impl<R: std::io::BufRead> Scanner<R> { fn new(r: R) -> Scanner<R> { Scanner { r, buf: Vec::with_capacity(8000) } } fn next(&mut self) -> &str { self.buf.clear(); loop { let (done, used) = { let available = self.r.fill_buf().unwrap(); match available.iter().position(|b| !b.is_ascii_whitespace()) { Some(i) => (true, i), None => (false, available.len()), } }; self.r.consume(used); if done || used == 0 { break; } } loop { let (done, used) = { let available = self.r.fill_buf().unwrap(); match available.iter().position(|b| b.is_ascii_whitespace()) { Some(i) => { self.buf.extend_from_slice(&available[..i]); (true, i) } None => { self.buf.extend_from_slice(&available); (false, available.len()) } } }; self.r.consume(used); if done || used == 0 { unsafe { return std::str::from_utf8_unchecked(&self.buf); } } } } } macro_rules! parse { ($s:expr, Chars) => ($s.chars().collect::<Vec<_>>()); ($s:expr, Bytes) => ($s.bytes().collect::<Vec<_>>()); ($s:expr, Usize1) => (parse!($s, usize) - 1); ($s:expr, $t:ty) => ($s.parse::<$t>().unwrap()); } macro_rules! read { ($sc:expr, [$t:tt; $n:expr]) => ( (0..$n).map(|_| read!($sc, $t)).collect::<Vec<_>>() ); ($sc:expr, ($($t:tt),*)) => (($(read!($sc, $t)),*)); ($sc:expr, $t:ident) => (parse!($sc.next(), $t)); ($sc:expr, $($t:tt),*) => (($(read!($sc, $t)),*)); } fn main() { use std::io::Write; let (stdin, stdout) = (std::io::stdin(), std::io::stdout()); let mut sc = Scanner::new(stdin.lock()); let mut wr = std::io::BufWriter::new(stdout.lock()); macro_rules! scan { ($($t:tt)*) => (read!(sc, $($t)*)); } macro_rules! println { ($($arg:tt)*) => (writeln!(wr, $($arg)*).ok()); } let (n, m, p) = scan!(usize, usize, usize); let a = scan!([usize; n]); let max_a = a.iter().max().unwrap(); if m < *max_a { println!("1"); return; } let m = m / max_a; let mut b = Vec::with_capacity(n); for mut a in a { let mut c: usize = 1; while a % p == 0 { a /= p; c += 1; } if a == 1 { continue; } b.push((c, a)); } b.sort_by_key(|key| (std::cmp::Reverse(key.0), key.1)); let mut v = Vec::new(); let mut max_a = 0; for (c, a) in b { if a <= max_a { continue; } v.push((c, a)); max_a = max_a.max(a); } let mut ans = std::usize::MAX; let mut map = std::collections::BTreeMap::new(); map.insert(0, 1); for cost in 0.. { if let Some(&x) = map.get(&cost) { for (c, a) in &v { let next_cost = cost + c; let next_x = x * a; if next_x > m { ans = ans.min(next_cost + 1); } else { let value = map.entry(next_cost).or_default(); *value = std::cmp::max(*value, next_x); } } map.remove(&cost); if map.is_empty() { break; } } } println!("{}", ans as isize); }