結果

問題 No.1330 Multiply or Divide
ユーザー phsplsphspls
提出日時 2023-01-08 20:26:20
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,403 bytes
コンパイル時間 6,383 ms
コンパイル使用メモリ 141,220 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-22 05:32:24
合計ジャッジ時間 5,418 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 14 ms
8,276 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 7 ms
4,380 KB
testcase_07 AC 47 ms
8,160 KB
testcase_08 AC 18 ms
8,664 KB
testcase_09 AC 21 ms
8,752 KB
testcase_10 AC 18 ms
8,688 KB
testcase_11 AC 16 ms
8,736 KB
testcase_12 AC 17 ms
8,760 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 11 ms
5,588 KB
testcase_19 AC 11 ms
5,572 KB
testcase_20 AC 12 ms
5,588 KB
testcase_21 AC 11 ms
5,620 KB
testcase_22 AC 12 ms
5,520 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,384 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,380 KB
testcase_33 AC 1 ms
4,388 KB
testcase_34 AC 9 ms
4,608 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 8 ms
4,432 KB
testcase_37 AC 7 ms
4,376 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 7 ms
4,380 KB
testcase_43 AC 8 ms
4,380 KB
testcase_44 AC 11 ms
7,216 KB
testcase_45 AC 10 ms
7,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> Main.rs:16:9
   |
16 |     let n = nmp[0];
   |         ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn costmap(val: usize, p: usize) -> (usize, usize) {
    let mut cnt = 1usize;
    let mut val = val;
    while val % p == 0 {
        cnt += 1;
        val /= p;
    }
    (val, cnt)
}

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();

    let maxval = *a.iter().max().unwrap();
    if maxval >= m {
        println!("1");
        return;
    }
    let paths = a.iter().map(|&v| costmap(v, p)).filter(|&v| v.0 > 1).collect::<Vec<_>>();
    if paths.is_empty() {
        println!("-1");
        return;
    }
    let mut cnt2max = vec![0usize; 31];
    for &(val, cnt) in paths.iter() {
        cnt2max[cnt] = cnt2max[cnt].max(val);
    }
    let mut dp = vec![vec![0usize; 1000]; 31];
    dp[0][1] = maxval;
    for cnt in 1..31 {
        for j in 0..1000 {
            dp[cnt][j] = dp[cnt][j].max(dp[cnt-1][j]);
            if j+cnt < 1000 {
                dp[cnt][j+cnt] = dp[cnt][j+cnt].max(dp[cnt][j] * cnt2max[cnt]).min(m);
            }
        }
    }
    println!("{}", (0..1000).filter(|&i| dp[30][i] == m).nth(0).unwrap());
}
0