Skip to main content

aizu_online_judge/dsl/
dsl_5_b.rs

1use competitive::prelude::*;
2
3#[verify::aizu_online_judge("DSL_5_B")]
4pub fn dsl_5_b(reader: impl Read, writer: impl Write) {
5    prepare_io!(reader, writer);
6    sc!(n, xyxy: [(usize, usize, usize, usize); iter n]);
7    let mut acc = vec![vec![0; 1001]; 1001];
8    for (x1, y1, x2, y2) in xyxy {
9        acc[x1][y1] += 1;
10        acc[x2][y1] -= 1;
11        acc[x1][y2] -= 1;
12        acc[x2][y2] += 1;
13    }
14    for a in acc.iter_mut() {
15        for j in 0..1000 {
16            a[j + 1] += a[j];
17        }
18    }
19    for i in 0..1000 {
20        let [a, b] = acc.get_disjoint_mut([i + 1, i]).unwrap();
21        for (a, b) in a.iter_mut().zip(b) {
22            *a += *b;
23        }
24    }
25    pp!(acc
26        .into_iter()
27        .map(|acc| acc.into_iter().max().unwrap_or_default())
28        .max()
29        .unwrap_or_default());
30}