Submission #56338171
Source Code Expand
use proconio::input; fn main() { input! { n: usize, m: u64, a: [u64; n], } let oo = 10_u64.pow(15); let res = (0_u64..oo) .bisect(|&x| a.iter().map(|&ai| ai.min(x)).sum::<u64>() <= m); if res < oo { println!("{}", res - 1); } else { println!("infinite"); } } trait Bisect { type Item; fn bisect(&self, f: impl FnMut(&Self::Item) -> bool) -> Self::Item; } impl Bisect for std::ops::Range<u64> { type Item = u64; fn bisect(&self, mut pred: impl FnMut(&Self::Item) -> bool) -> Self::Item { let std::ops::Range { start, end } = *self; assert!(start <= end, "range must be valid."); if !pred(&start) { return start; } let mut ok = start; let mut bad = end; while let Some(mid) = ok.checked_midpoint(&bad) { *(if pred(&mid) { &mut ok } else { &mut bad }) = mid; } bad } } trait BisectTy: Sized { fn checked_midpoint(&self, other: &Self) -> Option<Self>; } macro_rules! impl_uint { ( $($ty:ty)* ) => { $( impl BisectTy for $ty { fn checked_midpoint(&self, &other: &Self) -> Option<Self> { (other - self > 1).then(|| self + (other - self) / 2) } } )* }; } impl_uint! { u8 u16 u32 u64 u128 usize }
Submission Info
Submission Time | |
---|---|
Task | C - Transportation Expenses |
User | rsk0315 |
Language | Rust (rustc 1.70.0) |
Score | 300 |
Code Size | 1414 Byte |
Status | AC |
Exec Time | 16 ms |
Memory | 5440 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 1 ms | 2068 KB |
00_sample_02.txt | AC | 1 ms | 1900 KB |
00_sample_03.txt | AC | 0 ms | 1792 KB |
01_test_01.txt | AC | 14 ms | 5236 KB |
01_test_02.txt | AC | 15 ms | 5240 KB |
01_test_03.txt | AC | 16 ms | 5236 KB |
01_test_04.txt | AC | 14 ms | 5304 KB |
01_test_05.txt | AC | 14 ms | 5296 KB |
01_test_06.txt | AC | 14 ms | 5160 KB |
01_test_07.txt | AC | 14 ms | 5128 KB |
01_test_08.txt | AC | 14 ms | 5300 KB |
01_test_09.txt | AC | 3 ms | 2700 KB |
01_test_10.txt | AC | 5 ms | 2924 KB |
01_test_11.txt | AC | 14 ms | 5188 KB |
01_test_12.txt | AC | 16 ms | 5164 KB |
01_test_13.txt | AC | 14 ms | 5300 KB |
01_test_14.txt | AC | 14 ms | 5300 KB |
01_test_15.txt | AC | 14 ms | 5184 KB |
01_test_16.txt | AC | 15 ms | 5144 KB |
01_test_17.txt | AC | 14 ms | 5216 KB |
01_test_18.txt | AC | 15 ms | 5412 KB |
01_test_19.txt | AC | 14 ms | 5440 KB |
01_test_20.txt | AC | 1 ms | 2000 KB |
01_test_21.txt | AC | 14 ms | 5224 KB |
01_test_22.txt | AC | 14 ms | 5248 KB |
01_test_23.txt | AC | 14 ms | 5176 KB |
01_test_24.txt | AC | 14 ms | 5148 KB |
01_test_25.txt | AC | 14 ms | 5236 KB |