Submission #1572961


Source Code Expand

#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

const MOD: i64 = 998244353;

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32
}

struct Vector {
    dx: i32,
    dy: i32
}

impl Vector {
    fn new(p0: &Point, p1: &Point) -> Vector {
        Vector { dx: p1.x - p0.x, dy: p1.y - p0.y }
    }
}

fn cross(v1: &Vector, v2: &Vector) -> i32 {
    v1.dx * v2.dy - v1.dy * v2.dx
}

fn lined(p0: &Point, p1: &Point, p2: &Point) -> bool {
    let v1 = Vector::new(p0, p1);
    let v2 = Vector::new(p0, p2);
    cross(&v1, &v2) == 0
}


fn powmod(a: i64, p: i64, m: i64) -> i64 {
    let mut ret = 1i64;
    let mut aa = a;
    let mut pp = p;
    while pp >= 1 {
        if pp & 1 == 1 {
            ret *= aa;
            ret %= m;
        }
        aa = aa * aa % m;
        pp >>= 1;
    }
    ret
}

fn inv(a: i64, m: i64) -> i64 {
    powmod(a, m-2, m)
}

struct Combination {
    fact: Vec<i64>,
    invfact: Vec<i64>,
    modulo: i64
}

impl Combination {
    fn new(n: usize, modulo: i64) -> Self {
        let mut fact: Vec<i64> = vec![0; n];
        let mut invfact: Vec<i64> = vec![0; n];
        fact[0] = 1;
        for i in 1..n {
            fact[i] = fact[i-1] * i as i64 % modulo;
        }
        invfact[n-1] = inv(fact[n-1], modulo);
        for i in (0..n-1).rev() {
            invfact[i] = (invfact[i+1] * (i+1) as i64) % modulo;
        }

        Combination { fact: fact, invfact: invfact, modulo: modulo }
    }

    fn combination(&self, n: usize, k: usize) -> i64 {
        if n < k {
            return 0;
        }
        self.fact[n] * self.invfact[n-k] % self.modulo * self.invfact[k] % self.modulo
    }
}

fn main() {
    let n: usize = read();
    let points: Vec<(i32, i32)> = readn(n);
    let points: Vec<Point> = points.into_iter().map(|(a, b)| Point {x: a, y: b }).collect();
    let mut ans: i64 = 0;

    let comb = Combination::new(n+10, MOD);
    for i in 3..n+1 {
        ans += comb.combination(n, i);
        ans %= MOD;
    }

    let mut done: Vec<Vec<bool>> = vec![vec![false; n]; n];
    for i in 0..n {
        for j in i+1..n {
            let ref a = points[i];
            let ref b = points[j];
            if done[i][j] {
                continue;
            }

            let mut online: Vec<usize> = vec![];
            for k in 0..n {
                if lined(&a, &b, &points[k]) {
                    online.push(k);
                }
            }
            let same = online.len();
            for nk in 3..same+1 {
                ans += MOD;
                ans -= comb.combination(same, nk);
                ans %= MOD;
            }
            for &x in &online {
                for &y in &online {
                    done[x][y] = true;
                }
            }
        }
    }

    println!("{}", ans);
}

Submission Info

Submission Time
Task E - ConvexScore
User hamadu
Language Rust (1.15.1)
Score 700
Code Size 4178 Byte
Status AC
Exec Time 10 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt
Case Name Status Exec Time Memory
0_000.txt AC 2 ms 4352 KB
0_001.txt AC 2 ms 4352 KB
0_002.txt AC 2 ms 4352 KB
1_003.txt AC 2 ms 4352 KB
1_004.txt AC 2 ms 4352 KB
1_005.txt AC 4 ms 4352 KB
1_006.txt AC 2 ms 4352 KB
1_007.txt AC 4 ms 4352 KB
1_008.txt AC 3 ms 4352 KB
1_009.txt AC 4 ms 4352 KB
1_010.txt AC 2 ms 4352 KB
1_011.txt AC 5 ms 4352 KB
1_012.txt AC 5 ms 4352 KB
1_013.txt AC 4 ms 4352 KB
1_014.txt AC 2 ms 4352 KB
1_015.txt AC 2 ms 4352 KB
1_016.txt AC 2 ms 4352 KB
1_017.txt AC 10 ms 4352 KB
1_018.txt AC 10 ms 4352 KB
1_019.txt AC 6 ms 4352 KB
1_020.txt AC 6 ms 4352 KB
1_021.txt AC 6 ms 4352 KB
1_022.txt AC 8 ms 4352 KB
1_023.txt AC 9 ms 4352 KB
1_024.txt AC 9 ms 4352 KB
1_025.txt AC 8 ms 4352 KB
1_026.txt AC 8 ms 4352 KB
1_027.txt AC 2 ms 4352 KB
1_028.txt AC 2 ms 4352 KB
1_029.txt AC 8 ms 4352 KB
1_030.txt AC 10 ms 4352 KB
1_031.txt AC 10 ms 4352 KB
1_032.txt AC 9 ms 4352 KB
1_033.txt AC 10 ms 4352 KB
1_034.txt AC 10 ms 4352 KB
1_035.txt AC 6 ms 4352 KB