結果

問題 No.1330 Multiply or Divide
ユーザー phsplsphspls
提出日時 2023-01-09 21:18:06
言語 Rust
(1.77.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,294 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 144,456 KB
実行使用メモリ 5,884 KB
最終ジャッジ日時 2023-08-22 21:00:23
合計ジャッジ時間 6,127 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 11 ms
5,180 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 47 ms
4,984 KB
testcase_08 AC 17 ms
5,584 KB
testcase_09 AC 21 ms
5,604 KB
testcase_10 AC 17 ms
5,664 KB
testcase_11 AC 15 ms
5,640 KB
testcase_12 AC 17 ms
5,616 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 13 ms
5,652 KB
testcase_19 AC 13 ms
5,632 KB
testcase_20 AC 13 ms
5,652 KB
testcase_21 AC 13 ms
5,620 KB
testcase_22 AC 13 ms
5,656 KB
testcase_23 AC 14 ms
5,884 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 10 ms
4,744 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 9 ms
4,460 KB
testcase_37 AC 8 ms
4,376 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 5 ms
4,376 KB
testcase_41 AC 4 ms
4,380 KB
testcase_42 AC 8 ms
4,380 KB
testcase_43 AC 9 ms
4,396 KB
testcase_44 AC 9 ms
4,380 KB
testcase_45 AC 9 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> Main.rs:6:9
  |
6 |     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 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();
    let mut cnt2val = vec![0usize; 31];
    for &v in a.iter() {
        let mut cnt = 1usize;
        let mut target = v;
        while target % p == 0 {
            target /= p;
            cnt += 1;
        }
        cnt2val[cnt] = cnt2val[cnt].max(target);
    }
    let mut dp = vec![vec![0usize; 1000]; 32];
    dp[0][1] = maxval;
    for i in 1..=31 {
        for j in 0..1000 {
            dp[i][j] = dp[i][j].max(dp[i-1][j]).min(m+1);
            for acnt in 0..=30 {
                if cnt2val[acnt] <= 1 { continue; }
                if j >= acnt {
                    dp[i][j] = dp[i][j].max(dp[i][j-acnt] * cnt2val[acnt]).min(m+1);
                }
            }
        }
    }
    if let Some(idx) = (0..1000).filter(|&i| dp[31][i] > m).nth(0) {
        println!("{}", idx);
    } else {
        println!("-1");
    }
}
0