結果

問題 No.1330 Multiply or Divide
ユーザー Moss_LocalMoss_Local
提出日時 2021-01-08 22:08:02
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 6,355 bytes
コンパイル時間 14,980 ms
コンパイル使用メモリ 379,436 KB
実行使用メモリ 11,164 KB
最終ジャッジ日時 2024-11-16 12:23:45
合計ジャッジ時間 17,867 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 17 ms
9,120 KB
testcase_02 WA -
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,248 KB
testcase_06 AC 11 ms
8,604 KB
testcase_07 WA -
testcase_08 AC 61 ms
11,040 KB
testcase_09 AC 64 ms
11,128 KB
testcase_10 AC 60 ms
11,164 KB
testcase_11 AC 60 ms
11,036 KB
testcase_12 AC 62 ms
11,156 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 59 ms
11,128 KB
testcase_19 AC 59 ms
11,036 KB
testcase_20 AC 58 ms
11,040 KB
testcase_21 AC 59 ms
11,156 KB
testcase_22 AC 59 ms
11,048 KB
testcase_23 WA -
testcase_24 AC 1 ms
5,248 KB
testcase_25 AC 1 ms
5,248 KB
testcase_26 WA -
testcase_27 AC 1 ms
5,248 KB
testcase_28 AC 1 ms
5,248 KB
testcase_29 AC 1 ms
5,248 KB
testcase_30 AC 1 ms
5,248 KB
testcase_31 AC 1 ms
5,248 KB
testcase_32 AC 1 ms
5,248 KB
testcase_33 AC 1 ms
5,248 KB
testcase_34 AC 42 ms
8,084 KB
testcase_35 AC 11 ms
5,248 KB
testcase_36 AC 37 ms
7,176 KB
testcase_37 AC 33 ms
6,688 KB
testcase_38 AC 20 ms
5,248 KB
testcase_39 AC 14 ms
5,248 KB
testcase_40 AC 17 ms
5,248 KB
testcase_41 AC 9 ms
5,248 KB
testcase_42 AC 31 ms
6,164 KB
testcase_43 AC 36 ms
6,884 KB
testcase_44 AC 11 ms
8,588 KB
testcase_45 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around type
  --> src/main.rs:42:15
   |
42 | fn readi() -> (i64) {
   |               ^   ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
42 - fn readi() -> (i64) {
42 + fn readi() -> i64 {
   |

warning: variable does not need to be mutable
   --> src/main.rs:195:13
    |
195 |         let mut r = F64Total(data[i].2 as f64 / data[i].1 as f64);
    |             ----^
    |             |
    |             help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: variable does not need to be mutable
   --> src/main.rs:201:13
    |
201 |         let mut x = *data.last().unwrap();
    |             ----^
    |             |
    |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/main.rs:228:9
    |
228 |     let mut p = data[0].1.pow(rres as u32);
    |         ----^
    |         |
    |         help: remove this `mut`

ソースコード

diff #

// -*- coding:utf-8-unix -*-

#![allow(dead_code)]
#![allow(unused_imports)]
use std::cmp::Ordering::*;
use std::collections::*;
use std::convert::*;
use std::convert::{From, Into};
use std::fmt::Debug;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::marker::Copy;
use std::mem::*;
use std::ops::Bound::*;
use std::ops::{Add, Mul, Neg, Sub};
use std::str;
use std::vec;
use std::{cmp, process::Output};
use std::{cmp::Ordering, env::consts::DLL_PREFIX};

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: i64 = 1000000007;
// const MOD: i64 = 998244353;
use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;

use btree_map::{Keys, Values};
// use str::Chars;
#[allow(dead_code)]
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()
}

#[allow(dead_code)]
fn readi() -> (i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    iter.next().unwrap().parse::<i64>().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}

fn readff() -> (f64, f64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<f64>().unwrap(),
        iter.next().unwrap().parse::<f64>().unwrap(),
    )
}

#[allow(dead_code)]
fn readiii() -> (i64, i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

fn readcc() -> (char, char) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<char>().unwrap(),
        iter.next().unwrap().parse::<char>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuu() -> (usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuuu() -> (usize, usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

fn readiiii() -> (i64, i64, i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}

#[derive(PartialEq, PartialOrd, Clone, Copy, Debug)]
struct F64Total(f64);

impl Eq for F64Total {}
impl Ord for F64Total {
    fn cmp(&self, other: &F64Total) -> Ordering {
        let F64Total(f1) = *self;
        let F64Total(f2) = *other;
        if f1.is_nan() {
            Less
        } else if f2.is_nan() {
            Greater
        } else {
            if (f1 - f2).is_sign_positive() {
                Greater
            } else {
                Less
            }
        }
    }
}
fn readin() -> (usize, char) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<char>().unwrap(),
    )
}

fn solve() {
    let (n, m, p) = readuuu();
    let vec: Vec<usize> = read_vec();
    let mut data = vec![(F64Total(0.0), 0, 0); n];
    for i in 0..n {
        let mut cnt = 1 as usize;
        let mut x = vec[i];
        while x % p == 0 {
            cnt += 1;
            x /= p;
        }
        data[i].2 = x;
        data[i].1 = cnt;
        let mut r = F64Total(data[i].2 as f64 / data[i].1 as f64);
        data[i].0 = r;
    }
    data.sort();
    data.reverse();
    while !data.is_empty() {
        let mut x = *data.last().unwrap();
        let x = x.2;
        if x == 1 {
            data.pop();
        } else {
            break;
        }
    }
    if data.is_empty() {
        println!("{:?}", -1);
        return;
    }
    // data.reverse();
    // println!("{:?}", data);
    for i in 0..data.len() {
        let x = data[i].1;
        data[i].1 = data[i].2;
        data[i].2 = x;
    }
    let mut rres = 0;
    let mut mm = m;
    while mm > 0 {
        mm /= data[0].1;
        rres += data[0].2;
    }
    rres -= 1;
    let mut res = INF as usize;
    let mut p = data[0].1.pow(rres as u32);
    // println!("{:?}", p);
    if p < m {
        for &x in data.iter() {
            if p * x.1 >= m {
                res = min(res, rres + x.2);
            }
        }
    } else {
        res = rres;
    }
    println!("{:?}", res);

    return;
}

fn main() {
    solve()
}
0