- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 56 lines of Go from the credited upstream file 85E.go.
- The implementation visibly relies on sequence storage.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1package main2 3import (4 "bufio"5 . "fmt"6 "io"7 "sort"8)9 1011type pair85 struct{ x, y int }12 13func f85(v, c, lim int, a []pair85, cs []int) bool {14 cs[v] = c15 for w, p := range a {16 if abs85(a[v].x-p.x)+abs85(a[v].y-p.y) > lim && (cs[w] == c || cs[w] == 0 && !f85(w, -c, lim, a, cs)) {17 return false18 }19 }20 return true21}22 23func CF85E(_r io.Reader, out io.Writer) {24 in := bufio.NewReader(_r)25 const mod = 1_000_000_00726 var n, ansCC int27 Fscan(in, &n)28 a := make([]pair85, n)29 for i := range a {30 Fscan(in, &a[i].x, &a[i].y)31 }32 ans := sort.Search(1e4+1, func(lim int) bool {33 cs := make([]int, n)34 cc := 0 35 for i, c := range cs {36 if c == 0 {37 cc++38 if !f85(i, 1, lim, a, cs) {39 return false40 }41 }42 }43 ansCC = cc44 return true45 })46 p2 := 147 for ; ansCC > 0; ansCC-- {48 p2 = p2 * 2 % mod49 }50 Fprintln(out, ans)51 Fprintln(out, p2)52}53 5455func abs85(x int) int { if x < 0 { return -x }; return x }56