結果
問題 | No.2232 Miser's Gift |
ユーザー | otamay6 |
提出日時 | 2023-03-03 21:46:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,617 bytes |
コンパイル時間 | 12,555 ms |
コンパイル使用メモリ | 401,820 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-17 22:40:27 |
合計ジャッジ時間 | 16,960 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
コンパイルメッセージ
warning: unused imports: `BufReader`, `Write` --> src/main.rs:1:15 | 1 | use std::io::{BufReader, Write}; | ^^^^^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: variable does not need to be mutable --> src/main.rs:8:13 | 8 | let mut s = { | ----^ | | | help: remove this `mut` ... 80 | / input!{ 81 | | n: usize, 82 | | w: usize, 83 | | p: [(usize, u64); n], 84 | | } | |_____- in this macro invocation | = note: `#[warn(unused_mut)]` on by default = note: this warning originates in the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)
ソースコード
use std::io::{BufReader, Write}; macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let mut s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } /// https://maguro.dev/debug-macro/ #[allow(unused_macros)] macro_rules! debug { ($($a:expr),* $(,)*) => { #[cfg(debug_assertions)] eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*); #[cfg(debug_assertions)] std::io::stderr().flush().unwrap(); }; } #[allow(dead_code)] fn concat_newline(chg: &mut String, additional: &str){ chg.push_str(additional); chg.push_str("\n"); } #[allow(dead_code)] fn concat_whitespace(chg: &mut String, additional: &str){ chg.push_str(additional); chg.push_str(" "); } fn main(){ println!("{}", solve()); } fn solve()->String{ let mut ans= String::new(); input!{ n: usize, w: usize, p: [(usize, u64); n], } // maxを更新できる価値を与える let mut from: Vec<u64> = Vec::new(); let mut to: Vec<u64> = Vec::new(); from.resize(w+1,0); to.resize(w+1, 0); for i in 0..n { let (weight, value) = p[i]; for j in 0..=w { if j > 0 { to[j] = to[j-1].max(from[j]); } if j >= weight { to[j] = std::cmp::max(to[j], from[j-weight] + value); } } std::mem::swap(&mut from, &mut to); } let dp = from; for x in 1..=w { concat_newline(&mut ans, (dp[w] - dp[w-x] + 1).to_string().as_str()); } return ans; }