heh
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs index 9e94395..a37b4f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,26 +38,30 @@ extern crate test; pub mod util; use atools::prelude::*; pub use util::prelude::*; -fn area([l, w, h]: [u32; 3]) -> u32 { - 2 * l * w + 2 * w * h + 2 * h * l -} #[no_mangle] pub unsafe fn p1(i: &str) -> impl Display { - for n in 0.. { - let x = md5::compute(format!("iwrupvqb{n}")); - if x.0.take::<3>() == [0x00; 3] { - return n; + let mut m = [[0u32; 1000]; 1000]; + for l in i.行() { + let (d, a, b) = if l.starts_with(b"toggle") { + let [_, a, _, b] = l.str().split(' ').carr::<4>(); + (2, a, b) + } else { + let [_, x, a, _, b] = l.str().split(' ').carr::<5>(); + ((x == "on") as u32, a, b) + }; + let [a, b] = [a, b].map(|x| x.μ(',').mb(|x| x.λ::<u32>())); + for x in a.0..=b.0 { + for y in a.1..=b.1 { + let e = &mut m[x as usize][y as usize]; + match d { + 0 => *e = e.saturating_sub(1), + 1 => *e += 1, + _ => *e += 2, + } + } } } - 0 -} - -#[no_mangle] -pub unsafe fn p2(i: &str) -> impl Display { - i.行() - .map(|x| x.str().split('x').map(|x| x.λ::<u32>()).carr::<3>()) - .map(|x| x.sort().take::<2>().sum() * 2 + x.product()) - .sum::<u32>() + m.as_flattened().into_iter().sum::<u32>() } fn main() { @@ -69,9 +73,3 @@ fn benc(b: &mut test::Bencher) { let i = boxd(include_str!("inp.txt")); b.iter(|| unsafe { p1(i) }); } - -#[bench] -fn benc_sort(b: &mut test::Bencher) { - let i = boxd(include_str!("inp.txt")); - b.iter(|| unsafe { p2(i) }); -} |