結果
問題 | No.2232 Miser's Gift |
ユーザー | Moss_Local |
提出日時 | 2023-03-03 21:37:51 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 233 ms / 2,000 ms |
コード長 | 8,467 bytes |
コンパイル時間 | 23,813 ms |
コンパイル使用メモリ | 377,296 KB |
実行使用メモリ | 83,584 KB |
最終ジャッジ日時 | 2024-09-17 22:32:07 |
合計ジャッジ時間 | 24,845 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
6,656 KB |
testcase_01 | AC | 9 ms
6,656 KB |
testcase_02 | AC | 10 ms
7,424 KB |
testcase_03 | AC | 212 ms
83,328 KB |
testcase_04 | AC | 232 ms
83,456 KB |
testcase_05 | AC | 104 ms
83,456 KB |
testcase_06 | AC | 8 ms
5,376 KB |
testcase_07 | AC | 140 ms
5,376 KB |
testcase_08 | AC | 220 ms
83,456 KB |
testcase_09 | AC | 214 ms
83,456 KB |
testcase_10 | AC | 219 ms
83,328 KB |
testcase_11 | AC | 219 ms
83,456 KB |
testcase_12 | AC | 220 ms
83,456 KB |
testcase_13 | AC | 216 ms
83,456 KB |
testcase_14 | AC | 220 ms
83,456 KB |
testcase_15 | AC | 212 ms
83,456 KB |
testcase_16 | AC | 216 ms
83,328 KB |
testcase_17 | AC | 218 ms
83,456 KB |
testcase_18 | AC | 216 ms
83,456 KB |
testcase_19 | AC | 212 ms
83,584 KB |
testcase_20 | AC | 216 ms
83,456 KB |
testcase_21 | AC | 225 ms
83,328 KB |
testcase_22 | AC | 214 ms
83,456 KB |
testcase_23 | AC | 227 ms
83,456 KB |
testcase_24 | AC | 228 ms
83,328 KB |
testcase_25 | AC | 219 ms
83,456 KB |
testcase_26 | AC | 225 ms
83,456 KB |
testcase_27 | AC | 228 ms
83,456 KB |
testcase_28 | AC | 229 ms
83,456 KB |
testcase_29 | AC | 233 ms
83,456 KB |
testcase_30 | AC | 231 ms
83,456 KB |
testcase_31 | AC | 225 ms
83,328 KB |
testcase_32 | AC | 231 ms
83,456 KB |
testcase_33 | AC | 220 ms
83,328 KB |
testcase_34 | AC | 221 ms
83,456 KB |
testcase_35 | AC | 221 ms
83,456 KB |
testcase_36 | AC | 223 ms
83,456 KB |
testcase_37 | AC | 219 ms
83,456 KB |
testcase_38 | AC | 89 ms
83,456 KB |
testcase_39 | AC | 89 ms
83,456 KB |
testcase_40 | AC | 90 ms
83,456 KB |
testcase_41 | AC | 90 ms
83,456 KB |
testcase_42 | AC | 91 ms
83,456 KB |
testcase_43 | AC | 91 ms
83,456 KB |
testcase_44 | AC | 92 ms
83,456 KB |
testcase_45 | AC | 92 ms
83,328 KB |
testcase_46 | AC | 91 ms
83,328 KB |
testcase_47 | AC | 91 ms
83,328 KB |
testcase_48 | AC | 89 ms
83,456 KB |
testcase_49 | AC | 89 ms
83,456 KB |
testcase_50 | AC | 89 ms
83,456 KB |
testcase_51 | AC | 89 ms
83,456 KB |
testcase_52 | AC | 87 ms
83,456 KB |
testcase_53 | AC | 88 ms
83,456 KB |
testcase_54 | AC | 90 ms
83,456 KB |
testcase_55 | AC | 89 ms
83,456 KB |
testcase_56 | AC | 90 ms
83,328 KB |
testcase_57 | AC | 90 ms
83,456 KB |
コンパイルメッセージ
warning: unnecessary parentheses around type --> src/main.rs:64:15 | 64 | fn readi() -> (i64) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 64 - fn readi() -> (i64) { 64 + fn readi() -> i64 { | warning: unnecessary parentheses around match arm expression --> src/main.rs:226:46 | 226 | std::ops::Bound::Included(&x) => (x + 1), | ^ ^ | help: remove these parentheses | 226 - std::ops::Bound::Included(&x) => (x + 1), 226 + std::ops::Bound::Included(&x) => x + 1, |
ソースコード
// -*- coding:utf-8-unix -*- // #![feature(map_first_last)] #![allow(dead_code)] #![allow(unused_imports)] #![allow(unused_macros)] use core::num; use std::cmp::*; use std::fmt::*; use std::hash::*; use std::*; use std::{cmp, collections, fmt, io, iter, ops, str}; const INF: i64 = 1223372036854775807; const UINF: usize = INF as usize; const LINF: i64 = 2147483647; const INF128: i128 = 1223372036854775807000000000000; // const MOD: i64 = 1000000007; const MOD: i64 = 998244353; const UMOD: usize = MOD as usize; const M_PI: f64 = 3.14159265358979323846; // const MOD: i64 = INF; use cmp::Ordering::*; use std::collections::*; use std::io::stdin; use std::io::stdout; use std::io::Write; macro_rules! p { ($x:expr) => { println!("{}", $x); }; } macro_rules! d { ($x:expr) => { println!("{:?}", $x); }; } #[allow(unused_macros)] pub mod macros { macro_rules! min { ($x: expr) => { $x }; ($x: expr, $($xs: expr),+) => {{ let y = macros::min!($($xs),+); std::cmp::min($x, y) } }} macro_rules! max { ($x: expr) => { $x }; ($x: expr, $($xs: expr),+) => {{ let y = macros::max!($($xs),+); std::cmp::max($x, y) } }} macro_rules! chmin { ($x: expr, $($xs: expr),+) => {{ let y = macros::min!($($xs),+); if $x > y { $x = y; true } else { false } }}} macro_rules! chmax { ($x: expr, $($xs: expr),+) => {{ let y = macros::max!($($xs),+); if $x < y { $x = y; true } else { false } }}} macro_rules! multi_vec { ($element: expr; ($len: expr, $($lens: expr),*)) => ( vec![macros::multi_vec![$element; ($($lens),*)]; $len] ); ($element: expr; ($len: expr)) => ( vec![$element; $len] ); } macro_rules! multi_box_array { ($element: expr; ($len: expr, $($lens: expr),*)) => ( vec![macros::multi_box_array![$element; ($($lens),*)]; $len].into_boxed_slice() ); ($element: expr; ($len: expr)) => ( vec![$element; $len].into_boxed_slice() ); } #[allow(unused_imports)] pub(super) use {chmax, chmin, max, min, multi_box_array, multi_vec}; } use macros::*; fn main() { solve(); } // use str::Chars; #[allow(dead_code)] fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } #[allow(dead_code)] fn readi() -> (i64) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); iter.next().unwrap().parse::<i64>().unwrap() } #[allow(dead_code)] fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } #[allow(dead_code)] fn read_mat<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> { (0..n).map(|_| read_vec()).collect() } #[allow(dead_code)] fn readii() -> (i64, i64) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<i64>().unwrap(), iter.next().unwrap().parse::<i64>().unwrap(), ) } #[allow(dead_code)] fn readiii() -> (i64, i64, i64) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<i64>().unwrap(), iter.next().unwrap().parse::<i64>().unwrap(), iter.next().unwrap().parse::<i64>().unwrap(), ) } #[allow(dead_code)] fn readuu() -> (usize, usize) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<usize>().unwrap(), iter.next().unwrap().parse::<usize>().unwrap(), ) } #[allow(dead_code)] fn readff() -> (f64, f64) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<f64>().unwrap(), iter.next().unwrap().parse::<f64>().unwrap(), ) } fn readcc() -> (char, char) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<char>().unwrap(), iter.next().unwrap().parse::<char>().unwrap(), ) } fn readuuu() -> (usize, usize, usize) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<usize>().unwrap(), iter.next().unwrap().parse::<usize>().unwrap(), iter.next().unwrap().parse::<usize>().unwrap(), ) } #[allow(dead_code)] fn readiiii() -> (i64, i64, i64, i64) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<i64>().unwrap(), iter.next().unwrap().parse::<i64>().unwrap(), iter.next().unwrap().parse::<i64>().unwrap(), iter.next().unwrap().parse::<i64>().unwrap(), ) } #[allow(dead_code)] fn readuuuu() -> (usize, usize, usize, usize) { let mut str = String::new(); let _ = stdin().read_line(&mut str).unwrap(); let mut iter = str.split_whitespace(); ( iter.next().unwrap().parse::<usize>().unwrap(), iter.next().unwrap().parse::<usize>().unwrap(), iter.next().unwrap().parse::<usize>().unwrap(), iter.next().unwrap().parse::<usize>().unwrap(), ) } pub struct SEG<M: Monoid> { n: usize, buf: Vec<M::T>, } impl<M: Monoid> SEG<M> { #[allow(dead_code)] pub fn new(n: usize) -> SEG<M> { SEG { n, buf: vec![M::id(); 2 * n], } } #[allow(dead_code)] pub fn update(&mut self, k: usize, a: M::T) { let mut k = k + self.n; self.buf[k] = a; while k > 0 { k >>= 1; self.buf[k] = M::op(&self.buf[k << 1], &self.buf[(k << 1) | 1]); } } #[allow(dead_code)] pub fn add(&mut self, k: usize, a: &M::T) { let mut k = k + self.n; self.buf[k] = M::op(&self.buf[k], a); while k > 0 { k >>= 1; self.buf[k] = M::op(&self.buf[k << 1], &self.buf[(k << 1) | 1]); } } #[allow(dead_code)] pub fn get(&self, i: usize) -> M::T { self.query(i, i + 1) } #[allow(dead_code)] pub fn query_range<R: std::ops::RangeBounds<usize>>(&self, range: R) -> M::T { let l = match range.start_bound() { std::ops::Bound::Excluded(&x) => { assert!(x > 0); x - 1 } std::ops::Bound::Included(&x) => x, std::ops::Bound::Unbounded => 0, }; let r = match range.end_bound() { std::ops::Bound::Excluded(&x) => x, std::ops::Bound::Included(&x) => (x + 1), std::ops::Bound::Unbounded => self.n, }; self.query(l, r) } #[allow(dead_code)] pub fn query(&self, l: usize, r: usize) -> M::T { let mut vl = M::id(); let mut vr = M::id(); let mut l = l + self.n; let mut r = r + self.n; while l < r { if l & 1 == 1 { vl = M::op(&vl, &self.buf[l]); l += 1; } if r & 1 == 1 { r -= 1; vr = M::op(&self.buf[r], &vr); } l >>= 1; r >>= 1; } M::op(&vl, &vr) } } pub trait Monoid { type T: Clone; fn id() -> Self::T; fn op(a: &Self::T, b: &Self::T) -> Self::T; } pub enum MON {} impl Monoid for MON { type T = usize; fn id() -> Self::T { 0 } fn op(a: &Self::T, b: &Self::T) -> Self::T { max(*a, *b) } } fn solve() { let (n, w) = readuu(); let mut dp = vec![vec![0 as usize; (101010) as usize]; (n + 1) as usize]; for i in 0..n { let (w, v) = readuu(); for j in 0..(101010) { if j < w { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v); } } } let mut seg: SEG<MON> = SEG::new(101010); for i in 0..101010 { seg.update(i, dp[n][i]); } for i in 1..=w { let x = seg.query_range(0..=w) - seg.query_range(0..=(w - i)); println!("{}", x + 1); // dbg!(dp[n][i]); } return; }