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        for j in 0..=1000 {
22            acc[i + 1][j] += acc[i][j];
23        }
24    }
25    writeln!(
26        writer,
27        "{}",
28        acc.into_iter()
29            .map(|acc| acc.into_iter().max().unwrap_or_default())
30            .max()
31            .unwrap_or_default()
32    )
33    .ok();
34}