結果

問題 No.2808 Concentration
ユーザー 37kt37kt
提出日時 2024-11-29 10:24:08
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 8,259 bytes
コンパイル時間 12,664 ms
コンパイル使用メモリ 377,608 KB
実行使用メモリ 28,984 KB
最終ジャッジ日時 2024-11-29 10:24:35
合計ジャッジ時間 18,264 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
17,408 KB
testcase_01 AC 64 ms
17,888 KB
testcase_02 AC 56 ms
17,124 KB
testcase_03 AC 54 ms
17,872 KB
testcase_04 AC 1 ms
6,820 KB
testcase_05 AC 1 ms
6,820 KB
testcase_06 AC 1 ms
5,248 KB
testcase_07 AC 24 ms
9,296 KB
testcase_08 AC 11 ms
5,480 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 35 ms
18,688 KB
testcase_11 AC 37 ms
15,252 KB
testcase_12 AC 16 ms
6,272 KB
testcase_13 AC 51 ms
22,144 KB
testcase_14 AC 9 ms
5,632 KB
testcase_15 AC 47 ms
20,920 KB
testcase_16 AC 47 ms
20,432 KB
testcase_17 AC 53 ms
16,860 KB
testcase_18 AC 55 ms
25,228 KB
testcase_19 AC 29 ms
11,888 KB
testcase_20 AC 51 ms
23,364 KB
testcase_21 AC 44 ms
18,352 KB
testcase_22 AC 35 ms
13,672 KB
testcase_23 AC 30 ms
15,232 KB
testcase_24 AC 48 ms
18,484 KB
testcase_25 AC 28 ms
12,940 KB
testcase_26 AC 50 ms
16,540 KB
testcase_27 AC 54 ms
19,776 KB
testcase_28 AC 56 ms
25,572 KB
testcase_29 AC 55 ms
25,984 KB
testcase_30 AC 57 ms
28,984 KB
testcase_31 AC 53 ms
24,208 KB
testcase_32 AC 52 ms
24,548 KB
testcase_33 AC 55 ms
25,088 KB
testcase_34 AC 54 ms
24,860 KB
testcase_35 AC 55 ms
20,160 KB
testcase_36 AC 54 ms
24,368 KB
testcase_37 AC 53 ms
19,468 KB
testcase_38 AC 55 ms
23,308 KB
testcase_39 AC 54 ms
17,996 KB
testcase_40 AC 54 ms
20,092 KB
testcase_41 AC 55 ms
25,404 KB
testcase_42 AC 55 ms
20,432 KB
testcase_43 AC 59 ms
23,052 KB
testcase_44 AC 54 ms
17,376 KB
testcase_45 AC 54 ms
21,076 KB
testcase_46 AC 53 ms
20,444 KB
testcase_47 AC 1 ms
5,248 KB
testcase_48 AC 1 ms
5,248 KB
testcase_49 AC 1 ms
5,248 KB
testcase_50 AC 1 ms
5,248 KB
testcase_51 AC 1 ms
5,248 KB
testcase_52 AC 1 ms
5,248 KB
testcase_53 AC 1 ms
5,248 KB
testcase_54 AC 1 ms
5,248 KB
testcase_55 AC 1 ms
5,248 KB
testcase_56 AC 1 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub use __cargo_equip::prelude::*;

use algebraic::{algebra, monoid};
use chminmax::chmax;
#[allow(unused_imports)]
use proconio::{
    input,
    marker::{Bytes, Chars, Usize1},
};
use sliding_window_aggregation::SlidingWindowAggregation;

algebra!(M, i64);
monoid!(M, -(1 << 60), |&a: &i64, &b: &i64| a.max(b));

fn main() {
    input! {
        n: usize,
        s: i64,
        h: i64,
    }
    let mut a = vec![-2_000_000_000];
    let mut b = vec![0];
    for _ in 0..n {
        input! {
            x: i64,
            y: i64,
            z: i64,
        }
        if y - x > s {
            continue;
        }
        a.push(x);
        a.push(y);
        b.push(0);
        b.push(z);
    }
    for i in 1..b.len() {
        b[i] += b[i - 1];
    }
    let mut dp1 = vec![0; a.len()]; // dp1[i]: 最後に寝始めたのがiのときの最大値

    // let mut dp2 = vec![0; a.len()]; // dp2[i]: 最後に起き上がったのがiのときの最大値
    let mut dq = SlidingWindowAggregation::<M>::new();
    let mut l1 = 0;
    let mut l2 = 0;
    let mut mx = -(1 << 60);
    for i in 0..a.len() {
        while l1 < a.len() && a[l1] + h <= a[i] {
            chmax!(mx, dp1[l1]);
            l1 += 1;
        }
        while l2 < a.len() && a[l2] + s < a[i] {
            dq.pop_front();
            l2 += 1;
        }
        chmax!(dp1[i], dq.prod() + b[i]);
        dq.push_back(mx - b[i]);
    }
    println!("{}", dp1.iter().max().unwrap());
}

// The following code was expanded by `cargo-equip`.

///  # Bundled libraries
/// 
///  - `path+file:///home/junji/code/cprs/crates/algebraic/algebraic#0.1.0`                       published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::algebraic`
///  - `path+file:///home/junji/code/cprs/crates/data-structure/sliding-window-aggregation#0.1.0` published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::sliding_window_aggregation`
///  - `path+file:///home/junji/code/cprs/crates/macros/chminmax#0.1.0`                           published in **missing** licensed under `CC0-1.0` as `crate::__cargo_equip::crates::chminmax`
#[cfg_attr(any(), rustfmt::skip)]
#[allow(unused)]
mod __cargo_equip {
    pub(crate) mod crates {
        pub mod algebraic {pub use crate::__cargo_equip::macros::algebraic::*;pub trait Algebra{type S;}pub trait Act:Algebra{type X;fn act(f:&Self::S,x:&Self::X)->Self::X;}pub trait Monoid:Algebra{fn e()->Self::S;fn op(x:&Self::S,y:&Self::S)->Self::S;}pub trait Group:Monoid{fn inv(x:&Self::S)->Self::S;}pub trait Zero{fn zero()->Self;fn is_zero(&self)->bool;}pub trait One{fn one()->Self;fn is_one(&self)->bool;}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_algebra{($ident:ident,$ty:ty)=>{#[derive(Clone)]enum$ident{}impl$crate::__cargo_equip::crates::algebraic::Algebra for$ident{type S=$ty;}};}macro_rules!algebra{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_algebra!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_act{($ident:ident,$tar:ty,$act:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Act for$ident{type X=$tar;#[inline]fn act(f:&Self::S,x:&Self::X)->Self::X{$act(f,x)}}};}macro_rules!act{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_act!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_monoid{($ident:ident,$e:expr,$op:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Monoid for$ident{#[inline]fn e()->Self::S{$e}#[inline]fn op(x:&Self::S,y:&Self::S)->Self::S{$op(x,y)}}};}macro_rules!monoid{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_monoid!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_algebraic_group{($ident:ident,$e:expr,$op:expr,$inv:expr)=>{impl$crate::__cargo_equip::crates::algebraic::Monoid for$ident{#[inline]fn e()->Self::S{$e}#[inline]fn op(x:&Self::S,y:&Self::S)->Self::S{$op(x,y)}}impl$crate::__cargo_equip::crates::algebraic::Group for$ident{#[inline]fn inv(x:&Self::S)->Self::S{$inv(x)}}};}macro_rules!group{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_algebraic_group!{$($tt)*})}macro_rules!impl_zero_one{($($t:ty)*)=>{$(impl$crate::__cargo_equip::crates::algebraic::Zero for$t{fn zero()->Self{0}fn is_zero(&self)->bool{*self==0}}impl$crate::__cargo_equip::crates::algebraic::One for$t{fn one()->Self{1}fn is_one(&self)->bool{*self==1}})*};}impl_zero_one!(usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128);}
        pub mod sliding_window_aggregation {use crate::__cargo_equip::preludes::sliding_window_aggregation::*;use algebraic::Monoid;pub struct SlidingWindowAggregation<M>where M:Monoid,M::S:Clone,{fv:Vec<M::S>,bv:Vec<M::S>,fs:Vec<M::S>,bs:Vec<M::S>,}impl<M>SlidingWindowAggregation<M>where M:Monoid,M::S:Clone,{pub fn new()->Self{Self{fv:vec![],bv:vec![],fs:vec![M::e()],bs:vec![M::e()],}}pub fn clear(&mut self){self.fv.clear();self.bv.clear();self.fs.clear();self.fs.push(M::e());self.bs.clear();self.bs.push(M::e());}pub fn len(&self)->usize{self.fv.len()+self.bv.len()}pub fn is_empty(&self)->bool{self.len()==0}pub fn push_back(&mut self,x:M::S){self.bs.push(M::op(self.bs.last().unwrap(),&x));self.bv.push(x);}pub fn push_front(&mut self,x:M::S){self.fs.push(M::op(&x,self.fs.last().unwrap()));self.fv.push(x);}pub fn pop_back(&mut self)->Option<M::S>{if self.len()==0{None}else if self.len()==1{if self.bv.len()==1{self.bs.pop();self.bv.pop()}else{self.fs.pop();self.fv.pop()}}else{if self.bv.is_empty(){self.rebuild();}self.bs.pop();self.bv.pop()}}pub fn pop_front(&mut self)->Option<M::S>{if self.len()==0{None}else if self.len()==1{if self.bv.len()==1{self.bs.pop();self.bv.pop()}else{self.fs.pop();self.fv.pop()}}else{if self.fv.is_empty(){self.rebuild();}self.fs.pop();self.fv.pop()}}pub fn prod(&self)->M::S{M::op(self.fs.last().unwrap(),self.bs.last().unwrap())}fn rebuild(&mut self){let mut v=vec![];v.reserve(self.len());v.append(&mut self.fv);v.reverse();v.append(&mut self.bv);self.clear();for x in v[0..v.len()/2].iter().rev(){self.push_front(x.clone());}for x in&v[v.len()/2..v.len()]{self.push_back(x.clone());}}}}
        pub mod chminmax {pub use crate::__cargo_equip::macros::chminmax::*;#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_min{($a:expr$(,)*)=>{{$a}};($a:expr,$b:expr$(,)*)=>{{std::cmp::min($a,$b)}};($a:expr,$($rest:expr),+$(,)*)=>{{std::cmp::min($a,$crate::__cargo_equip::crates::chminmax::min!($($rest),+))}};}macro_rules!min{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_chminmax_min!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_max{($a:expr$(,)*)=>{{$a}};($a:expr,$b:expr$(,)*)=>{{std::cmp::max($a,$b)}};($a:expr,$($rest:expr),+$(,)*)=>{{std::cmp::max($a,$crate::__cargo_equip::crates::chminmax::max!($($rest),+))}};}macro_rules!max{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_chminmax_max!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_chmin{($base:expr,$($cmps:expr),+$(,)*)=>{{let cmp_min=$crate::__cargo_equip::crates::chminmax::min!($($cmps),+);if$base>cmp_min{$base=cmp_min;true}else{false}}};}macro_rules!chmin{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_chminmax_chmin!{$($tt)*})}#[macro_export]macro_rules!__cargo_equip_macro_def_chminmax_chmax{($base:expr,$($cmps:expr),+$(,)*)=>{{let cmp_max=$crate::__cargo_equip::crates::chminmax::max!($($cmps),+);if$base<cmp_max{$base=cmp_max;true}else{false}}};}macro_rules!chmax{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_chminmax_chmax!{$($tt)*})}}
    }

    pub(crate) mod macros {
        pub mod algebraic {pub use crate::{__cargo_equip_macro_def_algebraic_act as act,__cargo_equip_macro_def_algebraic_algebra as algebra,__cargo_equip_macro_def_algebraic_group as group,__cargo_equip_macro_def_algebraic_monoid as monoid};}
        pub mod sliding_window_aggregation {}
        pub mod chminmax {pub use crate::{__cargo_equip_macro_def_chminmax_chmax as chmax,__cargo_equip_macro_def_chminmax_chmin as chmin,__cargo_equip_macro_def_chminmax_max as max,__cargo_equip_macro_def_chminmax_min as min};}
    }

    pub(crate) mod prelude {pub use crate::__cargo_equip::crates::*;}

    mod preludes {
        pub mod algebraic {}
        pub mod sliding_window_aggregation {pub(in crate::__cargo_equip)use crate::__cargo_equip::crates::algebraic;}
        pub mod chminmax {}
    }
}
0