- 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
- 62 lines of Go from the credited upstream file 1288D.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 1011func CF1288D(_r io.Reader, _w io.Writer) {12 in := bufio.NewScanner(_r)13 in.Split(bufio.ScanWords)14 out := bufio.NewWriter(_w)15 defer out.Flush()16 read := func() (x int) {17 in.Scan()18 for _, b := range in.Bytes() {19 x = x*10 + int(b-'0')20 }21 return22 }23 24 n, m := read(), uint(read())25 mat := make([][]int, n)26 for i := range mat {27 mat[i] = make([]int, m)28 for j := range mat[i] {29 mat[i][j] = read()30 }31 }32 var ansI, ansJ int33 sort.Search(1e9+1, func(min int) bool {34 id := make([]int, 1<<m)35 for i, mi := range mat {36 v := 037 for j, a := range mi {38 if a >= min {39 v |= 1 << uint(j)40 }41 }42 id[v] = i + 143 }44 for i := range id {45 if id[i] > 0 {46 for j := i; j < 1<<m; j++ {47 if i|j == 1<<m-1 && id[j] > 0 {48 ansI, ansJ = id[i], id[j]49 return false50 }51 }52 }53 }54 return true55 })56 Fprint(out, ansI, ansJ)57}58 59606162