結果

問題 No.1330 Multiply or Divide
ユーザー fukafukatani
提出日時 2021-01-08 21:37:43
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,321 bytes
コンパイル時間 13,572 ms
コンパイル使用メモリ 379,348 KB
実行使用メモリ 6,532 KB
最終ジャッジ日時 2024-11-16 10:37:52
合計ジャッジ時間 14,460 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> src/main.rs:20:10
   |
20 |     let (n, m, p) = (v[0], v[1], v[2]);
   |          ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, m, p) = (v[0], v[1], v[2]);
    let a = read_vec::<i64>();
    let amax = *a.iter().max().unwrap();
    let mut aa = vec![];
    for mut num in a {
        while num % p == 0 {
            num /= p;
        }
        aa.push(num);
    }
    // debug!(aa);
    let aa_max = *aa.iter().max().unwrap();
    if aa_max == 1 && amax <= m {
        println!("-1");
        return;
    }
    if m == 1 {
        println!("0");
        return;
    }

    let mut x = 1;
    let mut ans = 1;
    while x * amax <= m {
        x *= aa_max;
        ans += 1;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0