Submission #2698755


Source Code Expand

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![(0, 0); n];
    for i in 0..n {
        let mut x = read::<i64>();
        let mut y = read::<i64>();
        if x > y {
            std::mem::swap(&mut x, &mut y);
        }
        seq[i] = (x, y);
    }
    let mut min_value = 1 << 32;
    let mut max_value = -(1 << 32);
    let mut que = vec![(0, 0); 3 * n];
    for i in 0..n {
        min_value = std::cmp::min(min_value, seq[i].0);
        max_value = std::cmp::max(max_value, seq[i].1);
        que[i * 3 + 0] = (-(1 << 32), seq[i].0);
        que[i * 3 + 1] = (seq[i].0, seq[i].1);
        que[i * 3 + 2] = (seq[i].1, 1 << 32);
    }
    que.sort();
    let mut ans = 1 << 61;
    let mut pos = 0;
    let mut right = -(1 << 32);
    for i in 0..3 * n {
        while pos < 3 * n && que[pos].0 < que[i].0 {
            right = std::cmp::max(right, que[pos].1);
            pos += 1;
        }
        if que[i].0 == -(1 << 32) || right == (1 << 32) {
            continue;
        }
        let lans = (max_value - min_value) * (right - que[i].0);
        assert!(lans >= 0);
        ans = std::cmp::min(ans, lans);
    }
    {
        let mut left = min_value;
        let mut right = max_value;
        for i in 0..n {
            left = std::cmp::max(left, seq[i].0);
            right = std::cmp::min(right, seq[i].1);
        }
        let lans = (left - min_value) * (max_value - right);
        assert!(lans >= 0);
        ans = std::cmp::min(ans, lans);
    }
    println!("{}", ans);
}

Submission Info

Submission Time
Task E - Ball Coloring
User cos
Language Rust (1.15.1)
Score 700
Code Size 1999 Byte
Status AC
Exec Time 233 ms
Memory 22780 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 35
Set Name Test Cases
Sample example0, example1, example2
All div20, div21, div22, div23, div24, example0, example1, example2, maxrand0, maxrand1, maxrand2, maxrand20, maxrand21, maxrand210, maxrand211, maxrand22, maxrand23, maxrand24, maxrand25, maxrand26, maxrand27, maxrand28, maxrand29, maxrand3, maxrand4, smallrand0, smallrand1, smallrand2, smallrand3, smallrand4, sparse0, sparse1, sparse2, sparse3, sparse4
Case Name Status Exec Time Memory
div20 AC 228 ms 22780 KB
div21 AC 229 ms 22780 KB
div22 AC 230 ms 22780 KB
div23 AC 228 ms 22780 KB
div24 AC 229 ms 22780 KB
example0 AC 2 ms 4352 KB
example1 AC 2 ms 4352 KB
example2 AC 2 ms 4352 KB
maxrand0 AC 226 ms 22780 KB
maxrand1 AC 226 ms 22780 KB
maxrand2 AC 226 ms 22780 KB
maxrand20 AC 211 ms 22780 KB
maxrand21 AC 223 ms 22780 KB
maxrand210 AC 218 ms 22780 KB
maxrand211 AC 223 ms 22780 KB
maxrand22 AC 225 ms 22780 KB
maxrand23 AC 233 ms 22780 KB
maxrand24 AC 229 ms 22780 KB
maxrand25 AC 220 ms 22780 KB
maxrand26 AC 221 ms 22780 KB
maxrand27 AC 226 ms 22780 KB
maxrand28 AC 228 ms 22780 KB
maxrand29 AC 229 ms 22780 KB
maxrand3 AC 226 ms 22780 KB
maxrand4 AC 226 ms 22780 KB
smallrand0 AC 2 ms 4352 KB
smallrand1 AC 2 ms 4352 KB
smallrand2 AC 2 ms 4352 KB
smallrand3 AC 2 ms 4352 KB
smallrand4 AC 2 ms 4352 KB
sparse0 AC 215 ms 22780 KB
sparse1 AC 216 ms 22780 KB
sparse2 AC 217 ms 22780 KB
sparse3 AC 217 ms 22780 KB
sparse4 AC 217 ms 22780 KB