結果

問題 No.1330 Multiply or Divide
ユーザー ikdikd
提出日時 2021-01-08 21:54:25
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,218 bytes
コンパイル時間 13,113 ms
コンパイル使用メモリ 378,476 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-04-28 02:46:38
合計ジャッジ時間 15,291 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 10 ms
5,248 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 7 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 13 ms
5,888 KB
testcase_09 AC 13 ms
6,016 KB
testcase_10 AC 13 ms
5,888 KB
testcase_11 AC 12 ms
6,016 KB
testcase_12 AC 13 ms
5,888 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 0 ms
5,376 KB
testcase_17 WA -
testcase_18 AC 11 ms
6,016 KB
testcase_19 AC 11 ms
5,888 KB
testcase_20 AC 10 ms
5,888 KB
testcase_21 AC 11 ms
6,016 KB
testcase_22 AC 10 ms
5,888 KB
testcase_23 WA -
testcase_24 AC 0 ms
5,376 KB
testcase_25 AC 0 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 0 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 0 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 9 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 8 ms
5,376 KB
testcase_37 AC 8 ms
5,376 KB
testcase_38 AC 5 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 4 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 7 ms
5,376 KB
testcase_43 AC 8 ms
5,376 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let n: usize = rd.get();
    let m: u64 = rd.get();
    let p: u64 = rd.get();
    let a: Vec<u64> = rd.get_vec(n);

    if a.iter().any(|&x| x > m) {
        println!("1");
        return;
    }
    let a: Vec<u64> = a.into_iter().filter(|&x| x != 1 && x % p != 0).collect();
    if a.is_empty() {
        println!("-1");
        return;
    }
    let max = *a.iter().max().unwrap();
    let mut x = 1;
    let mut ans = 0;
    while x < m {
        x *= max;
        ans += 1;
    }
    println!("{}", ans);
}

pub struct ProconReader<R> {
    r: R,
    line: String,
    i: usize,
}

impl<R: std::io::BufRead> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self {
            r: reader,
            line: String::new(),
            i: 0,
        }
    }
    pub fn get<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        self.skip_blanks();
        assert!(self.i < self.line.len());
        assert_ne!(&self.line[self.i..=self.i], " ");
        let line = &self.line[self.i..];
        let end = line.find(' ').unwrap_or_else(|| line.len());
        let s = &line[..end];
        self.i += end;
        s.parse()
            .unwrap_or_else(|_| panic!("parse error `{}`", self.line))
    }
    fn skip_blanks(&mut self) {
        loop {
            let start = self.line[self.i..].find(|ch| ch != ' ');
            match start {
                Some(j) => {
                    self.i += j;
                    break;
                }
                None => {
                    self.line.clear();
                    self.i = 0;
                    let num_bytes = self.r.read_line(&mut self.line).unwrap();
                    assert!(num_bytes > 0, "reached EOF :(");
                    self.line = self.line.trim_end_matches(&['\r', '\n'][..]).to_string();
                }
            }
        }
    }
    pub fn get_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.get()).collect()
    }
}
0