結果
問題 | No.1330 Multiply or Divide |
ユーザー | Strorkis |
提出日時 | 2021-01-09 11:18:15 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 3,780 bytes |
コンパイル時間 | 21,554 ms |
コンパイル使用メモリ | 378,248 KB |
実行使用メモリ | 9,536 KB |
最終ジャッジ日時 | 2024-11-17 13:29:10 |
合計ジャッジ時間 | 19,088 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 17 ms
9,148 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 9 ms
5,248 KB |
testcase_07 | AC | 63 ms
9,152 KB |
testcase_08 | AC | 49 ms
9,344 KB |
testcase_09 | AC | 51 ms
9,536 KB |
testcase_10 | AC | 47 ms
9,524 KB |
testcase_11 | AC | 47 ms
9,408 KB |
testcase_12 | AC | 48 ms
9,408 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 1 ms
5,248 KB |
testcase_15 | AC | 1 ms
5,248 KB |
testcase_16 | AC | 1 ms
5,248 KB |
testcase_17 | AC | 1 ms
5,248 KB |
testcase_18 | AC | 9 ms
5,248 KB |
testcase_19 | AC | 10 ms
5,248 KB |
testcase_20 | AC | 10 ms
5,248 KB |
testcase_21 | AC | 10 ms
5,248 KB |
testcase_22 | AC | 9 ms
5,248 KB |
testcase_23 | AC | 18 ms
9,152 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 1 ms
5,248 KB |
testcase_26 | AC | 1 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 1 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 8 ms
5,248 KB |
testcase_35 | AC | 3 ms
5,248 KB |
testcase_36 | AC | 7 ms
5,248 KB |
testcase_37 | AC | 5 ms
5,248 KB |
testcase_38 | AC | 4 ms
5,248 KB |
testcase_39 | AC | 3 ms
5,248 KB |
testcase_40 | AC | 4 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 KB |
testcase_42 | AC | 6 ms
5,248 KB |
testcase_43 | AC | 6 ms
5,248 KB |
testcase_44 | AC | 49 ms
9,156 KB |
testcase_45 | AC | 75 ms
9,152 KB |
コンパイルメッセージ
warning: unused return value of `std::cmp::Ord::max` that must be used --> src/main.rs:100:9 | 100 | max_a.max(a); | ^^^^^^^^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 100 | let _ = max_a.max(a); | +++++++
ソースコード
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 max_a = 0; for (c, a) in b { if a <= max_a { continue; } v.push((c, a)); max_a.max(a); } use std::cmp::Reverse; let mut ans = std::usize::MAX; let mut map = std::collections::BTreeMap::new(); let mut heap = std::collections::BinaryHeap::new(); map.insert(0, 1); heap.push(Reverse(0)); while let Some(Reverse(cost)) = heap.pop() { let x = map[&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 { if let Some(value) = map.get_mut(&next_cost) { *value = std::cmp::max(*value, next_x); } else { map.insert(next_cost, next_x); heap.push(Reverse(next_cost)); } } } } println!("{}", ans as isize); }