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, mut writer: impl Write) {
5    let s = read_all_unchecked(reader);
6    let mut scanner = Scanner::new(&s);
7    scan!(scanner, n, xyxy: [(usize, usize, usize, usize)]);
8    let mut acc = vec![vec![0; 1001]; 1001];
9    for (x1, y1, x2, y2) in xyxy.take(n) {
10        acc[x1][y1] += 1;
11        acc[x2][y1] -= 1;
12        acc[x1][y2] -= 1;
13        acc[x2][y2] += 1;
14    }
15    for a in acc.iter_mut() {
16        for j in 0..1000 {
17            a[j + 1] += a[j];
18        }
19    }
20    for i in 0..1000 {
21        let [a, b] = acc.get_disjoint_mut([i + 1, i]).unwrap();
22        for (a, b) in a.iter_mut().zip(b) {
23            *a += *b;
24        }
25    }
26    writeln!(
27        writer,
28        "{}",
29        acc.into_iter()
30            .map(|acc| acc.into_iter().max().unwrap_or_default())
31            .max()
32            .unwrap_or_default()
33    )
34    .ok();
35}