Explanation
Add one to the line passing through each pair of points.
Implementation
Time Complexity:
import mathfrom collections import defaultdictfrom typing import Tupledef 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!