- 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
- 73 lines of Go from the credited upstream file 1365G.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 "math/bits"7 "os"8)9 10type (11 input1365 struct{ n int }12 guess1365 struct{ ans []int64 }13 req1365 struct{ q []int }14 resp1365 struct{ or int64 }15)16 1718func run1365(in input1365, Q func(req1365) resp1365) (gs guess1365) {19 n := in.n20 mask6 := make([]uint, n)21 qs := [13][]int{}22 x := uint(0)23 for i := range mask6 {24 for x++; bits.OnesCount(x) != 6; x++ {25 }26 mask6[i] = x27 for j := range qs {28 if x>>j&1 == 0 {29 qs[j] = append(qs[j], i+1)30 }31 }32 }33 or := [13]int64{}34 for i, q := range qs {35 if len(q) > 0 {36 or[i] = Q(req1365{q}).or37 }38 }39 a := make([]int64, n)40 for i, v := range mask6 {41 for j, o := range or {42 if v>>j&1 > 0 {43 a[i] |= o44 }45 }46 }47 gs.ans = a48 return49}50 51func ioq1365() {52 in := bufio.NewReader(os.Stdin)53 Q := func(req req1365) (resp resp1365) {54 Print("? ", len(req.q))55 for _, v := range req.q {56 Print(" ", v)57 }58 Println()59 Fscan(in, &resp.or)60 return61 }62 d := input1365{}63 Fscan(in, &d.n)64 gs := run1365(d, Q)65 Print("!")66 for _, v := range gs.ans {67 Print(" ", v)68 }69 Println()70}71 7273