結果

問題 No.1330 Multiply or Divide
ユーザー StrorkisStrorkis
提出日時 2021-01-09 09:43:55
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,776 bytes
コンパイル時間 12,374 ms
コンパイル使用メモリ 386,692 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 16:59:50
合計ジャッジ時間 15,672 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

struct Scanner<R> { r: R, buf: Vec<u8> }

impl<R: std::io::BufRead> Scanner<R> {
    fn new(r: R) -> Scanner<R> {
        Scanner { r, buf: Vec::with_capacity(8000) }
    }

    fn next(&mut self) -> &str {
        self.buf.clear();
        loop {
            let (done, used) = {
                let available = self.r.fill_buf().unwrap();
                match available.iter().position(|b| !b.is_ascii_whitespace()) {
                    Some(i) => (true, i),
                    None => (false, available.len()),
                }
            };
            self.r.consume(used);
            if done || used == 0 { break; }
        }
        loop {
            let (done, used) = {
                let available = self.r.fill_buf().unwrap();
                match available.iter().position(|b| b.is_ascii_whitespace()) {
                    Some(i) => {
                        self.buf.extend_from_slice(&available[..i]);
                        (true, i)
                    }
                    None => {
                        self.buf.extend_from_slice(&available);
                        (false, available.len())
                    }
                }
            };
            self.r.consume(used);
            if done || used == 0 {
                unsafe {
                    return std::str::from_utf8_unchecked(&self.buf);
                }
            }
        }
    }
}

macro_rules! parse {
    ($s:expr, Chars) => ($s.chars().collect::<Vec<_>>());
    ($s:expr, Bytes) => ($s.bytes().collect::<Vec<_>>());
    ($s:expr, Usize1) => (parse!($s, usize) - 1);
    ($s:expr, $t:ty) => ($s.parse::<$t>().unwrap());
}

macro_rules! read {
    ($sc:expr, [$t:tt; $n:expr]) => (
        (0..$n).map(|_| read!($sc, $t)).collect::<Vec<_>>()
    );
    ($sc:expr, ($($t:tt),*)) => (($(read!($sc, $t)),*));
    ($sc:expr, $t:ident) => (parse!($sc.next(), $t));
    ($sc:expr, $($t:tt),*) => (($(read!($sc, $t)),*));
}

fn main() {
    use std::io::Write;
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut wr = std::io::BufWriter::new(stdout.lock());
    macro_rules! scan {
        ($($t:tt)*) => (read!(sc, $($t)*));
    }
    macro_rules! println {
        ($($arg:tt)*) => (writeln!(wr, $($arg)*).ok());
    }

    let (n, m, p) = scan!(usize, i64, i64);
    let a = scan!([i64; n]);

    let mut ans = std::u64::MAX;
    for a in a {
        let mut b = a;
        let mut x = 0;
        while b % p == 0 {
            b /= p;
            x += 1;
        }
        if b == 1 { continue; }
        let mut b = a;
        let mut y = 0;
        while b <= m {
            b *= a;
            y += 1;
        }
        ans = ans.min((1 + x) * y + 1);
    }
    println!("{}", ans as i64);
}
0