結果

問題 No.3502 GCD Knapsack
コンテスト
ユーザー ガルム
提出日時 2026-04-18 14:00:13
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 915 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 830 ms
コンパイル使用メモリ 198,476 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2026-04-18 14:00:23
合計ジャッジ時間 5,570 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let mut it = input.split_whitespace();

    let n: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();

    let mut x = vec![0_usize; n];
    let mut max_x = 0_usize;
    for v in &mut x {
        *v = it.next().unwrap().parse().unwrap();
        max_x = max_x.max(*v);
    }

    let mut value_sum = vec![0_u64; max_x + 1];
    for &weight in &x {
        let y: u64 = it.next().unwrap().parse().unwrap();
        value_sum[weight] += y;
    }

    let mut ans = 0_u64;
    for d in w..=max_x {
        let mut total = 0_u64;
        let mut multiple = d;
        while multiple <= max_x {
            total += value_sum[multiple];
            multiple += d;
        }
        ans = ans.max(total);
    }

    println!("{}", ans);
}
0