Submission #68381296


Source Code Expand

#![allow(unused)]

use std::collections::HashMap;

use proconio::input;

fn main() {
    input! {
        n: usize,
        xy: [(i64, i64); n],
    }

    let mut groups = HashMap::new();
    for i in 0..n {
        for j in (i + 1)..n {
            let dx = (xy[j].0 - xy[i].0);
            let dy = (xy[j].1 - xy[i].1);
            let d2 = dx * dx + dy * dy;

            let g = gcd(dx.abs(), dy.abs());
            let (dx, dy) = (dx / g, dy / g);

            // normalize (dx, dy) in regard to (-dx, -dy)
            let pos = (dx, dy);
            let neg = (-dx, -dy);
            let (dx, dy) = if pos < neg { pos } else { neg };

            groups.entry((dx, dy)).or_insert(vec![]).push(d2);
        }
    }

    // Trapezoid (opposite side has different length) will be counted twice.

    // Parallelogram will be counted four times.
    // parallelogram <-> length of opposite side is the same.

    let mut abcd = 0; // opposite side has different length
    let mut abab = 0; // opposite side has same length <-> parallelogram
    for (&k, v) in &groups {
        if v.len() >= 2 {
            let mut cnt = HashMap::new();
            for &l in v {
                *cnt.entry(l).or_insert(0) += 1;
            }

            for &l in v {
                abcd += v.len() as i64 - cnt[&l];
                abab += cnt[&l] - 1;
            }
        }
    }

    let ans = abcd / 2 + abab / 4;
    println!("{ans}");
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn join<T: ToString>(arr: &[T], sep: &str) -> String {
    arr.iter()
        .map(|x| x.to_string())
        .collect::<Vec<String>>()
        .join(sep)
}

Submission Info

Submission Time
Task E - Trapezium
User amoshuangyc
Language Rust (rustc 1.70.0)
Score 475
Code Size 1766 Byte
Status AC
Exec Time 754 ms
Memory 340052 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 28
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 2040 KiB
00-sample-02.txt AC 1 ms 2012 KiB
01-01.txt AC 0 ms 1820 KiB
01-02.txt AC 19 ms 12320 KiB
01-03.txt AC 479 ms 170888 KiB
01-04.txt AC 237 ms 86328 KiB
01-05.txt AC 701 ms 339896 KiB
01-06.txt AC 688 ms 339904 KiB
01-07.txt AC 236 ms 26068 KiB
01-08.txt AC 230 ms 25936 KiB
01-09.txt AC 225 ms 25544 KiB
01-10.txt AC 173 ms 20880 KiB
01-11.txt AC 157 ms 19068 KiB
01-12.txt AC 572 ms 172316 KiB
01-13.txt AC 554 ms 172136 KiB
01-14.txt AC 742 ms 170860 KiB
01-15.txt AC 754 ms 170884 KiB
01-16.txt AC 701 ms 340000 KiB
01-17.txt AC 689 ms 340020 KiB
01-18.txt AC 658 ms 170836 KiB
01-19.txt AC 676 ms 170852 KiB
01-20.txt AC 670 ms 170748 KiB
01-21.txt AC 683 ms 170880 KiB
01-22.txt AC 695 ms 339928 KiB
01-23.txt AC 640 ms 170892 KiB
01-24.txt AC 685 ms 340052 KiB
01-25.txt AC 614 ms 171700 KiB
01-26.txt AC 694 ms 339892 KiB