結果
問題 | No.527 ナップサック容量問題 |
ユーザー | sntea |
提出日時 | 2017-09-15 12:31:28 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 2,501 bytes |
コンパイル時間 | 14,586 ms |
コンパイル使用メモリ | 379,932 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 22:50:09 |
合計ジャッジ時間 | 16,343 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 3 ms
5,248 KB |
testcase_06 | AC | 13 ms
5,248 KB |
testcase_07 | AC | 8 ms
5,248 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 12 ms
5,248 KB |
testcase_11 | AC | 6 ms
5,248 KB |
testcase_12 | AC | 4 ms
5,248 KB |
testcase_13 | AC | 14 ms
5,248 KB |
testcase_14 | AC | 3 ms
5,248 KB |
testcase_15 | AC | 5 ms
5,248 KB |
testcase_16 | AC | 1 ms
5,248 KB |
testcase_17 | AC | 3 ms
5,248 KB |
testcase_18 | AC | 4 ms
5,248 KB |
testcase_19 | AC | 1 ms
5,248 KB |
testcase_20 | AC | 3 ms
5,248 KB |
testcase_21 | AC | 15 ms
5,248 KB |
testcase_22 | AC | 9 ms
5,248 KB |
testcase_23 | AC | 13 ms
5,248 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 7 ms
5,248 KB |
testcase_26 | AC | 6 ms
5,248 KB |
testcase_27 | AC | 7 ms
5,248 KB |
testcase_28 | AC | 5 ms
5,248 KB |
testcase_29 | AC | 15 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 1 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 1 ms
5,248 KB |
testcase_35 | AC | 6 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 3 ms
5,248 KB |
testcase_38 | AC | 5 ms
5,248 KB |
testcase_39 | AC | 5 ms
5,248 KB |
コンパイルメッセージ
warning: unused imports: `Ordering`, `min` --> src/main.rs:2:16 | 2 | use std::cmp::{Ordering, min, max}; | ^^^^^^^^ ^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused macro definition: `parse` --> src/main.rs:19:14 | 19 | macro_rules! parse { | ^^^^^ | = note: `#[warn(unused_macros)]` on by default warning: unused macro definition: `rvec` --> src/main.rs:44:14 | 44 | macro_rules! rvec { | ^^^^ warning: unused macro definition: `readlvec` --> src/main.rs:50:14 | 50 | macro_rules! readlvec { | ^^^^^^^^ warning: unused macro definition: `debug` --> src/main.rs:60:14 | 60 | macro_rules! debug { | ^^^^^ warning: function `printvec` is never used --> src/main.rs:66:4 | 66 | fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display { | ^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: variable `V` should have a snake case name --> src/main.rs:84:9 | 84 | let V = readl!(i32); | ^ help: convert the identifier to snake case (notice the capitalization): `v` | = note: `#[warn(non_snake_case)]` on by default
ソースコード
// use std::ops::{Index, IndexMut}; use std::cmp::{Ordering, min, max}; // use std::collections::{BinaryHeap, BTreeMap}; // use std::collections::btree_map::Entry::{Occupied, Vacant}; // use std::clone::Clone; fn getline() -> String{ let mut res = String::new(); std::io::stdin().read_line(&mut res).ok(); res } macro_rules! split { ($x: expr) => { ($x).trim().split(' ').collect() } } macro_rules! parse { ($x: expr) => { ($x).parse().unwrap() } } macro_rules! readl { ($t: ty) => { { let s = getline(); let iv: Vec<_> = split!(s); let mut iter = iv.into_iter(); iter.next().unwrap().parse::<$t>().unwrap() } }; ($( $t: ty),+ ) => { { let s = getline(); let iv: Vec<_> = split!(s); let mut iter = iv.into_iter(); ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) } }; } macro_rules! rvec { ($x: expr) => { ($x).into_iter().map(|x| parse!(x)).collect() } } macro_rules! readlvec { ($t: ty) => { { let s = getline(); let iv: Vec<_> = split!(s); iv.into_iter().map(|x| x.parse().unwrap()).collect::<Vec<$t>>() } } } macro_rules! debug { ($x: expr) => { println!("{}: {}", stringify!($x), $x) } } fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display { for (i,e) in v.into_iter().enumerate() { if i != 0 { print!(" "); } print!("{}", e); } println!(""); } fn main() { let n = readl!(usize); let mut v = Vec::with_capacity(n); let mut w = Vec::with_capacity(n); for _ in 0..n { let (x, y) = readl!(i32, i32); v.push(x); w.push(y); } let V = readl!(i32); let wsum: i32 = w.iter().sum(); const INF: i32 = 1e9 as i32; let mut dp = vec![-INF; (wsum+1) as usize]; dp[0] = 0; for i in 0..n { for j in (w[i] as usize..(wsum+1) as usize).rev() { dp[j] = max(dp[j], dp[j-w[i] as usize] + v[i]); } } let mut l = -1; let mut r = -1; let mut ma = 0; for j in 1..(wsum+1) as usize { ma = max(ma, dp[j]); if ma == V { if l == -1 { l = j as i32; } r = j as i32; } } println!("{} ", l); if r == wsum { println!("inf"); } else { println!("{}", r); } }