結果
| 問題 |
No.2232 Miser's Gift
|
| コンテスト | |
| ユーザー |
otamay6
|
| 提出日時 | 2023-03-03 21:41:42 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,370 bytes |
| コンパイル時間 | 12,693 ms |
| コンパイル使用メモリ | 406,628 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-17 22:35:22 |
| 合計ジャッジ時間 | 17,375 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 55 |
ソースコード
use std::io::{BufReader, Write};
pub use proconio::input;
/// 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(" ");
}
#[proconio::fastout]
fn main(){
let stdin = std::io::stdin();
let mut source = proconio::source::auto::AutoSource::new(BufReader::new(stdin.lock()));
println!("{}", solve(&mut source));
std::io::stdout().flush().unwrap();
}
#[cfg(test)]
mod tests{
use super::*;
#[test]
fn handcase(){
let problem: &str = test_info::HANDCASE_INPUT;
if problem == String::new() {
return;
}
let output: String = naive_ans(&mut proconio::source::auto::AutoSource::from(problem));
if output == String::new() {
return;
}
assert_eq!(
output,
solve(&mut proconio::source::auto::AutoSource::from(problem))
)
}
#[test]
fn sample_1(){
let problem = test_info::SAMPLE_INPUT_1;
let output = test_info::SAMPLE_OUTPUT_1;
if problem == String::new() {
return;
}
assert_eq!(
output.to_string(),
solve(&mut proconio::source::auto::AutoSource::from(problem))
)
}
#[test]
fn sample_2(){
let problem = test_info::SAMPLE_INPUT_2;
let output = test_info::SAMPLE_OUTPUT_2;
if problem == String::new() {
return;
}
assert_eq!(
output.to_string(),
solve(&mut proconio::source::auto::AutoSource::from(problem))
)
}
#[test]
fn sample_3(){
let problem = test_info::SAMPLE_INPUT_3;
let output = test_info::SAMPLE_OUTPUT_3;
if problem == String::new() {
return;
}
assert_eq!(
output.to_string(),
solve(&mut proconio::source::auto::AutoSource::from(problem))
)
}
#[test]
fn naive_test_sample_1(){
let problem = test_info::SAMPLE_INPUT_1;
if problem == String::new() {
return;
}
let output: String = naive_ans(&mut proconio::source::auto::AutoSource::from(problem));
if output == String::new() {
return;
}
assert_eq!(
output.to_string(),
solve(&mut proconio::source::auto::AutoSource::from(problem))
)
}
#[test]
fn naive_test_sample_2(){
let problem = test_info::SAMPLE_INPUT_2;
if problem == String::new() {
return;
}
let output: String = naive_ans(&mut proconio::source::auto::AutoSource::from(problem));
if output == String::new() {
return;
}
assert_eq!(
output.to_string(),
solve(&mut proconio::source::auto::AutoSource::from(problem))
)
}
#[test]
fn naive_test_sample_3(){
let problem = test_info::SAMPLE_INPUT_3;
if problem == String::new() {
return;
}
let output: String = naive_ans(&mut proconio::source::auto::AutoSource::from(problem));
if output == String::new() {
return;
}
assert_eq!(
output.to_string(),
solve(&mut proconio::source::auto::AutoSource::from(problem))
)
}
fn naive_ans<T: std::io::Read>(mut source: &mut proconio::source::auto::AutoSource<BufReader<T>>)->String{
input!{
from &mut source,
}
return "".to_string();
}
}
/// コピー情報をそのまま貼り付けてテストできる
#[cfg(test)]
mod test_info{
pub const HANDCASE_INPUT: &str = "";
pub const SAMPLE_INPUT_1: &str = "3 5
1 2
2 3
3 5
";
pub const SAMPLE_OUTPUT_1: &str = "2
4
6
7
9
";
pub const SAMPLE_INPUT_2: &str = "3 5
10 10
10 100
100 100
";
pub const SAMPLE_OUTPUT_2: &str = "1
1
1
1
1
";
pub const SAMPLE_INPUT_3: &str = "4 10
1 1
2 3
4 5
8 9
";
pub const SAMPLE_OUTPUT_3: &str = "3
4
4
5
7
8
9
10
12
13
";
}
fn solve<T: std::io::Read>(mut source: &mut proconio::source::auto::AutoSource<BufReader<T>>)->String{
let mut ans= String::new();
input!{
from &mut source,
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;
debug!(dp);
for x in 1..=w {
concat_newline(&mut ans, (dp[w] - dp[w-x] + 1).to_string().as_str());
}
return ans;
}
otamay6