Submission #33019116


Source Code Expand

use std::collections::HashSet;

use proconio::input;

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

fn main() {
    input! {
        n: usize,
        xy: [(i64, i64); n],
    };
    let mut set1 = HashSet::new();
    let mut set = HashSet::new();
    for (i, (x_i, y_i)) in xy.iter().copied().enumerate() {
        for (j, (x_j, y_j)) in xy.iter().copied().enumerate() {
            if i == j {
                continue;
            }
            if x_i == x_j {
                set1.insert(if y_j - y_i > 0 { 1 } else { -1 });
            } else {
                let dy = y_j - y_i;
                let dx = x_j - x_i;
                let g = gcd(dx, dy);
                set.insert((dy / g, dx / g));
            }
        }
    }
    let ans = set.len() * 2 + set1.len();
    println!("{}", ans);
}

Submission Info

Submission Time
Task D - Teleportation
User bouzuya
Language Rust (1.42.0)
Score 400
Code Size 860 Byte
Status AC
Exec Time 85 ms
Memory 8612 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 12
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_xy_small_00.txt, 02_xy_small_random_00.txt, 02_xy_small_random_01.txt, 02_xy_small_random_02.txt, 02_xy_small_random_03.txt, 03_random_00.txt, 03_random_01.txt, 04_line_00.txt, 04_line_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 7 ms 2020 KiB
00_sample_01.txt AC 2 ms 2028 KiB
00_sample_02.txt AC 2 ms 1952 KiB
01_xy_small_00.txt AC 27 ms 2120 KiB
02_xy_small_random_00.txt AC 29 ms 2168 KiB
02_xy_small_random_01.txt AC 31 ms 2560 KiB
02_xy_small_random_02.txt AC 41 ms 3824 KiB
02_xy_small_random_03.txt AC 40 ms 5360 KiB
03_random_00.txt AC 85 ms 8612 KiB
03_random_01.txt AC 83 ms 8608 KiB
04_line_00.txt AC 24 ms 2036 KiB
04_line_01.txt AC 33 ms 2000 KiB