結果
問題 | No.1330 Multiply or Divide |
ユーザー |
|
提出日時 | 2021-01-15 15:50:40 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,941 bytes |
コンパイル時間 | 13,352 ms |
コンパイル使用メモリ | 378,468 KB |
実行使用メモリ | 5,632 KB |
最終ジャッジ日時 | 2024-11-26 03:10:21 |
合計ジャッジ時間 | 15,644 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 WA * 1 |
ソースコード
use std::cmp::*;#[allow(dead_code)]mod scanner {use std;use std::io::Read;use std::str::FromStr;use std::str::SplitWhitespace;pub struct Scanner<'a> {it: SplitWhitespace<'a>,}impl<'a> Scanner<'a> {pub fn new(s: &'a String) -> Scanner<'a> {Scanner {it: s.split_whitespace(),}}pub fn next<T: FromStr>(&mut self) -> T {match self.it.next().unwrap().parse::<T>() {Ok(v) => v,_ => panic!("Scanner error"),}}pub fn next_chars(&mut self) -> Vec<char> { self.next::<String>().chars().collect() }pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {(0..len).map(|_| self.next()).collect()}}pub fn read_string() -> String {let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s}}fn main() {let sc = scanner::read_string();let mut sc = scanner::Scanner::new(&sc);let n: usize = sc.next();let m: usize = sc.next();let p: usize = sc.next();let mut a = sc.next_vec::<usize>(n);let mut am = 1;let mut map = std::collections::BTreeMap::<usize, usize>::new();for i in 0..n {am = max(am, a[i]);let mut x = 1;while a[i] % p == 0 {a[i] /= p;x += 1;}if a[i] != 1 {let y = map.entry(x).or_insert(1);*y = max(*y, a[i]);}}if map.is_empty() {println!("-1");return;}let mut dp = vec![0usize; 100000];dp[0] = 1;for i in 1.. {if dp[i - 1] * am > m {println!("{}", i);return;}for (&k, &v) in map.iter() {if k <= i {dp[i] = max(dp[i], dp[i - k] * v);}}}}