結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 14:00:13 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 915 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
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);
}