For problem statement at 0-999/300-399/330-339/335/problemC.txt this is a correct solution, but verifier at 0-999/300-399/330-339/335/verifierC.go ends with mismatch on test 12 (random_8)
input:
41 26
23 2
20 1
41 2
21 1
8 2
12 2
18 1
12 1
32 2
14 1
35 1
2 2
41 1
25 1
33 2
38 1
10 2
30 1
5 2
38 2
18 2
30 2
6 2
9 2
28 1
36 1
expected:
WIN
got:
LOSE
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strings"
)
var memo map[string]int
func main() {
reader := bufio.NewReader(os.Stdin)
var r, n int
fmt.Fscan(reader, &r, &n)
limit := 2 * r
valid := make([]bool, limit+1)
for i := 1; i <= limit; i++ {
valid[i] = true
}
for i := 0; i < n; i++ {
var rr, cc int
fmt.Fscan(reader, &rr, &cc)
idx := 2*(rr-1) + cc
toInvalidate := []int{idx}
if idx-1 >= 1 { toInvalidate = append(toInvalidate, idx-1) }
if idx+1 <= limit { toInvalidate = append(toInvalidate, idx+1) }
if idx-3 >= 1 { toInvalidate = append(toInvalidate, idx-3) }
if idx+3 <= limit { toInvalidate = append(toInvalidate, idx+3) }
for _, v := range toInvalidate {
valid[v] = false
}
}
var indices []int
for i := 1; i <= limit; i++ {
if valid[i] {
indices = append(indices, i)
}
}
memo = make(map[string]int)
comps := getComponents(indices)
xorSum := 0
for _, comp := range comps {
xorSum ^= solve(comp)
}
if xorSum != 0 {
fmt.Println("WIN")
} else {
fmt.Println("LOSE")
}
}
func solve(indices []int) int {
if len(indices) == 0 {
return 0
}
minVal := indices[0]
maxVal := indices[len(indices)-1]
length := maxVal - minVal + 1
var sb strings.Builder
sb.Grow(length)
idxPtr := 0
for i := 0; i < length; i++ {
currentVal := minVal + i
if idxPtr < len(indices) && indices[idxPtr] == currentVal {
sb.WriteByte('1')
idxPtr++
} else {
sb.WriteByte('0')
}
}
key := sb.String()
if val, ok := memo[key]; ok {
return val
}
keyComps := getComponentsFromKey(key)
if len(keyComps) > 1 {
res := 0
for _, comp := range keyComps {
res ^= solve(comp)
}
memo[key] = res
return res
}
seen := make(map[int]bool)
for i, c := range key {
if c == '1' {
var nextIndices []int
for j, kChar := range key {
if kChar == '1' {
diff := j - i
if diff < 0 { diff = -diff }
if diff != 0 && diff != 1 && diff != 3 {
nextIndices = append(nextIndices, j)
}
}
}
seen[solve(nextIndices)] = true
}
}
res := 0
for seen[res] {
res++
}
memo[key] = res
return res
}
func getComponents(indices []int) [][]int {
if len(indices) == 0 {
return nil
}
var comps [][]int
visited := make(map[int]bool)
validSet := make(map[int]bool)
for _, v := range indices {
validSet[v] = true
}
for _, start := range indices {
if visited[start] {
continue
}
var comp []int
q := []int{start}
visited[start] = true
for len(q) > 0 {
u := q[0]
q = q[1:]
comp = append(comp, u)
candidates := []int{u-1, u+1, u-3, u+3}
for _, v := range candidates {
if validSet[v] && !visited[v] {
visited[v] = true
q = append(q, v)
}
}
}
sort.Ints(comp)
comps = append(comps, comp)
}
return comps
}
func getComponentsFromKey(key string) [][]int {
var indices []int
for i, c := range key {
if c == '1' {
indices = append(indices, i)
}
}
return getComponents(indices)
}
```