Table of Contents

ExplanationImplementation

Explanation

Add one to the line passing through each pair of points.

Implementation

Time Complexity: O(N2logN)\mathcal{O}(N^2\log N)

import math
from collections import defaultdict
from typing import Tuple
def get_line(a: Tuple[int, int], b: Tuple[int, int]) -> Tuple[Tuple[int, int], int]:
z = (b[0] - a[0], b[1] - a[1])
z = (-z[1], z[0])
g = math.gcd(z[0], z[1])

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!