結果

問題 No.1330 Multiply or Divide
ユーザー phsplsphspls
提出日時 2022-11-19 01:00:24
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,542 bytes
コンパイル時間 2,497 ms
コンパイル使用メモリ 197,504 KB
実行使用メモリ 8,864 KB
最終ジャッジ日時 2023-10-20 09:42:49
合計ジャッジ時間 4,702 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
8,408 KB
testcase_02 WA -
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 45 ms
8,860 KB
testcase_09 AC 47 ms
8,860 KB
testcase_10 AC 45 ms
8,860 KB
testcase_11 AC 44 ms
8,864 KB
testcase_12 AC 48 ms
8,860 KB
testcase_13 AC 0 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 12 ms
5,584 KB
testcase_19 AC 12 ms
5,580 KB
testcase_20 AC 12 ms
5,580 KB
testcase_21 AC 12 ms
5,584 KB
testcase_22 AC 12 ms
5,584 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 0 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 0 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 9 ms
4,564 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 8 ms
4,400 KB
testcase_37 AC 7 ms
4,348 KB
testcase_38 AC 5 ms
4,348 KB
testcase_39 AC 4 ms
4,348 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 7 ms
4,348 KB
testcase_43 AC 8 ms
4,348 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `HashMap`
 --> Main.rs:1:24
  |
1 | use std::collections::{HashMap, HashSet};
  |                        ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `n`
  --> Main.rs:14:9
   |
14 |     let n = nmp[0];
   |         ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: constant `INF` is never used
 --> Main.rs:3:7
  |
3 | const INF: usize = 1usize << 60;
  |       ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function `gcd` is never used
 --> Main.rs:5:4
  |
5 | fn gcd(a: usize, b: usize) -> usize {
  |    ^^^

warning: 4 warnings emitted

ソースコード

diff #

use std::collections::{HashMap, HashSet};

const INF: usize = 1usize << 60;

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 { return a; }
    gcd(b, a%b)
}

fn main() {
    let mut nmp = String::new();
    std::io::stdin().read_line(&mut nmp).ok();
    let nmp: Vec<usize> = nmp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nmp[0];
    let m = nmp[1];
    let p = nmp[2];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    if m == 1 {
        println!("0");
        return;
    }
    let maxval = *a.iter().max().unwrap();
    if maxval >= m {
        println!("1");
        return;
    }
    let mut a = a.into_iter()
        .map(|v| {
            let mut ret = v;
            while ret % p == 0 {
                ret /= p;
            }
            ret
        })
        .filter(|&v| v > 1)
        .collect::<HashSet<_>>()
        .into_iter()
        .collect::<Vec<usize>>();
    if p == 1 || a.is_empty() {
        println!("-1");
        return;
    }
    a.sort();
    a.reverse();
    let mut start_val = 1usize;
    let mut cnt = 0usize;
    for &v in a.iter() {
        for _ in 1.. {
            if start_val * v * maxval >= m {
                println!("{}", cnt+2);
                return;
            }
            if start_val * v % p == 0 {
                break;
            }
            start_val *= v;
            cnt += 1;
        }
    }
    println!("-1");
}
0