結果

問題 No.1330 Multiply or Divide
ユーザー o2co2c
提出日時 2021-01-15 15:25:48
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 3,296 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 156,692 KB
実行使用メモリ 9,224 KB
最終ジャッジ日時 2023-08-17 07:19:41
合計ジャッジ時間 3,293 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 12 ms
7,220 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 9 ms
5,700 KB
testcase_07 RE -
testcase_08 AC 31 ms
7,512 KB
testcase_09 AC 34 ms
7,472 KB
testcase_10 AC 31 ms
7,596 KB
testcase_11 AC 30 ms
7,852 KB
testcase_12 AC 31 ms
7,552 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 1 ms
4,380 KB
testcase_17 RE -
testcase_18 AC 29 ms
7,668 KB
testcase_19 AC 29 ms
7,768 KB
testcase_20 AC 29 ms
7,744 KB
testcase_21 AC 30 ms
7,776 KB
testcase_22 AC 29 ms
7,736 KB
testcase_23 AC 17 ms
9,224 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 22 ms
6,864 KB
testcase_35 AC 6 ms
4,376 KB
testcase_36 AC 20 ms
6,436 KB
testcase_37 AC 18 ms
6,080 KB
testcase_38 AC 11 ms
4,480 KB
testcase_39 AC 8 ms
4,376 KB
testcase_40 AC 10 ms
4,380 KB
testcase_41 AC 5 ms
4,376 KB
testcase_42 AC 17 ms
5,972 KB
testcase_43 AC 19 ms
6,420 KB
testcase_44 RE -
testcase_45 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
    }
}

trait Monoid {
    fn id() -> Self;
    fn f(a: Self, b: Self) -> Self;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
enum MinInt {
    Val(i64),
    Maximal,
}
#[allow(dead_code)]
impl MinInt {
    fn unwrap(self) -> i64 {
        if let Self::Val(x) = self {
            x
        } else {
            panic!();
        }
    }
    fn map<F>(self, f: F) -> Self
    where
        F: Fn(i64) -> i64,
    {
        if let Self::Val(x) = self {
            Self::Val(f(x))
        } else {
            Self::Maximal
        }
    }
    fn map2<F>(self, b: Self, f: F) -> Self
    where
        F: Fn(i64, i64) -> i64,
    {
        match (self, b) {
            (Self::Val(x), Self::Val(y)) => Self::Val(f(x, y)),
            _ => Self::Maximal,
        }
    }
    fn get_or(self, default: i64) -> i64 {
        match self {
            Self::Val(x) => x,
            _ => default,
        }
    }
}
impl std::ops::Mul for MinInt {
    type Output = Self;
    fn mul(self, other: Self) -> Self {
        if self < other {
            self
        } else {
            other
        }
    }
}
impl Monoid for MinInt {
    fn id() -> Self { MinInt::Maximal }
    fn f(a: Self, b: Self) -> Self { a * b }
}
use MinInt::*;

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 b = vec![];
    let mut c = vec![];
    for i in 0..n {
        if a[i] % p == 0 {
            while a[i] % p == 0 {
                a[i] /= p;
            }
            b.push(a[i]);
        } else {
            c.push(a[i]);
        }
    }
    b.sort();
    c.sort();
    b.reverse();
    c.reverse();

    let mut ans = Maximal;
    if !b.is_empty() && b[0] != 1 {
        let mut x = 1;
        let mut y = 0;
        while x <= m {
            if x * c[0] > m {
                y += 1;
                break;
            }
            x *= b[0];
            y += 2;
        }
        ans = ans * Val(y);
    }

    if !c.is_empty() && c[0] != 1 {
        let mut x = 1;
        let mut y = 0;
        while x <= m {
            x *= c[0];
            y += 1;
        }
        ans = ans * Val(y);
    }

    println!("{}", ans.get_or(-1));
}
0