For problem statement at 1000-1999/1000-1099/1030-1039/1031/problemE.txt this is a correct solution, but verifier at 1000-1999/1000-1099/1030-1039/1031/verifierE.go ends with case 1 failed: expected false but got true
input:
8
1 0 0 1 1 1 0 0
exit status 1 can you fix the verifier? package main
import (
"bufio"
"fmt"
"io"
"os"
)
type Triple struct {
x int
y int
z int
}
type Sol struct {
cnt int
op [2]int
}
func precompute() ([]Triple, [64]Sol) {
templates := make([]Triple, 0)
masks := make([]int, 0)
for x := 1; x <= 6; x++ {
for d := 1; x+2*d <= 18; d++ {
y := x + d
z := x + 2*d
m := 0
if x <= 6 {
m |= 1 << (x - 1)
}
if y <= 6 {
m |= 1 << (y - 1)
}
if z <= 6 {
m |= 1 << (z - 1)
}
templates = append(templates, Triple{x, y, z})
masks = append(masks, m)
}
}
var sol [64]Sol
for i := 0; i < 64; i++ {
sol[i].cnt = 3
sol[i].op[0] = -1
sol[i].op[1] = -1
}
sol[0].cnt = 0
for i, m := range masks {
if sol[m].cnt > 1 {
sol[m].cnt = 1
sol[m].op[0] = i
}
}
for i := 0; i < len(masks); i++ {
for j := i + 1; j < len(masks); j++ {
m := masks[i] ^ masks[j]
if sol[m].cnt > 2 {
sol[m].cnt = 2
sol[m].op[0] = i
sol[m].op[1] = j
}
}
}
return templates, sol
}
func solveSegment(a []byte, l, r int) ([]Triple, bool) {
if l > r {
return nil, true
}
n := r - l + 1
ops := make([]Triple, 0, 64)
rows := make([]uint64, n)
rhs := make([]byte, n)
for i := 0; i < n; i++ {
rhs[i] = a[l+i]
}
for x := 0; x < n; x++ {
for d := 1; x+2*d < n; d++ {
y := x + d
z := x + 2*d
idx := len(ops)
bit := uint64(1) << uint(idx)
rows[x] |= bit
rows[y] |= bit
rows[z] |= bit
ops = append(ops, Triple{l + x, l + y, l + z})
}
}
m := len(ops)
where := make([]int, m)
for i := 0; i < m; i++ {
where[i] = -1
}
row := 0
for col := 0; col < m && row < n; col++ {
sel := -1
for i := row; i < n; i++ {
if ((rows[i] >> uint(col)) & 1) != 0 {
sel = i
break
}
}
if sel == -1 {
continue
}
rows[row], rows[sel] = rows[sel], rows[row]
rhs[row], rhs[sel] = rhs[sel], rhs[row]
where[col] = row
for i := 0; i < n; i++ {
if i != row && ((rows[i]>>uint(col))&1) != 0 {
rows[i] ^= rows[row]
rhs[i] ^= rhs[row]
}
}
row++
}
for i := 0; i < n; i++ {
if rows[i] == 0 && rhs[i] != 0 {
return nil, false
}
}
var selOps uint64
for col := 0; col < m; col++ {
if where[col] != -1 && rhs[where[col]] != 0 {
selOps |= uint64(1) << uint(col)
}
}
ans := make([]Triple, 0, n)
for i := 0; i < m; i++ {
if ((selOps >> uint(i)) & 1) != 0 {
ans = append(ans, ops[i])
}
}
return ans, true
}
func main() {
data, _ := io.ReadAll(os.Stdin)
idx := 0
nextInt := func() int {
for idx < len(data) && (data[idx] == ' ' || data[idx] == '\n' || data[idx] == '\r' || data[idx] == '\t') {
idx++
}
sign := 1
if idx < len(data) && data[idx] == '-' {
sign = -1
idx++
}
val := 0
for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
val = val*10 + int(data[idx]-'0')
idx++
}
return val * sign
}
n := nextInt()
a := make([]byte, n+1)
for i := 1; i <= n; i++ {
a[i] = byte(nextInt())
}
templates, sol := precompute()
ans := make([]Triple, 0, n/3+20)
start := 1
for start+17 <= n {
p := 0
for i := 0; i < 6; i++ {
if a[start+i] != 0 {
p |= 1 << uint(i)
}
}
s := sol[p]
if s.cnt > 2 {
w := bufio.NewWriter(os.Stdout)
fmt.Fprintln(w, "NO")
w.Flush()
return
}
for t := 0; t < s.cnt; t++ {
op := templates[s.op[t]]
x := start + op.x - 1
y := start + op.y - 1
z := start + op.z - 1
a[x] ^= 1
a[y] ^= 1
a[z] ^= 1
ans = append(ans, Triple{x, y, z})
}
start += 6
}
tailOps, ok := solveSegment(a, start, n)
w := bufio.NewWriter(os.Stdout)
defer w.Flush()
if !ok {
fmt.Fprintln(w, "NO")
return
}
ans = append(ans, tailOps...)
fmt.Fprintln(w, "YES")
fmt.Fprintln(w, len(ans))
for _, op := range ans {
fmt.Fprintln(w, op.x, op.y, op.z)
}
}