- Decide the key that represents the information needed later.
- Update its count or stored state while scanning the input.
- Use constant-time expected lookups to detect matches or assemble the result.
Code notes
- 66 lines of Python from the credited upstream file abc248_e.py.
- The implementation visibly relies on sequence storage, hash lookup, ordered lookup.
- No explicit loop blocks detected.
Complexity
Expected hash operations are constant time, but the surrounding scan and the number of stored keys determine total work and memory.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def calc_line_passing_through(point1, point2):5 '''6 See:7 https:atcoder.jp/contests/abc248/submissions/310186088 https:blog.hamayanhamayan.com/entry/2022/04/16/2322379 '''10 11 from math import gcd12 13 a = point2[1] - point1[1]14 b = point1[0] - point2[0]15 c = -(point1[0] * a + point1[1] * b)16 17 if a < 0:18 a, b, c = -a, -b, -c19 20 if a == 0 and b < 0:21 b, c = -b, -c22 23 g = gcd(gcd(a, b), c)24 a = g25 b = g26 c = g27 28 return (a, b, c)29 30 31def main():32 from collections import defaultdict33 import sys34 35 input = sys.stdin.readline36 37 n, k = map(int, input().split())38 xy = list()39 40 if k == 1:41 print("Infinity")42 exit()43 44 for i in range(n):45 xi, yi = map(int, input().split())46 xy.append((xi, yi))47 48 d = defaultdict(int)49 50 for i in range(n):51 for j in range(i + 1, n):52 p, q, r = calc_line_passing_through(xy[i], xy[j])53 d[(p, q, r)] += 154 55 ans = 056 57 for value in d.values():58 if value >= k * (k - 1) 2:59 ans += 160 61 print(ans)62 63 64if __name__ == "__main__":65 main()66