← Home
For problem statement at 1000-1999/1800-1899/1890-1899/1896/problemF.txt this is a correct solution, but verifier at 1000-1999/1800-1899/1890-1899/1896/verifierF.go ends with mismatch on line 2: expected "(())" got "()()"

exit status 1 can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func buildPair(d string) (string, string) {
	m := len(d)
	a := make([]byte, m)
	b := make([]byte, m)

	zeros := make([]int, 0, m)
	ones := make([]int, 0, m)

	for i := 0; i < m; i++ {
		if d[i] == '0' {
			zeros = append(zeros, i)
		} else {
			ones = append(ones, i)
		}
	}

	half := len(zeros) / 2
	for i, pos := range zeros {
		ch := byte('(')
		if i >= half {
			ch = ')'
		}
		a[pos] = ch
		b[pos] = ch
	}

	for i, pos := range ones {
		if i%2 == 0 {
			a[pos] = '('
			b[pos] = ')'
		} else {
			a[pos] = ')'
			b[pos] = '('
		}
	}

	return string(a), string(b)
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for ; T > 0; T-- {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		ones := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '1' {
				ones++
			}
		}

		if s[0] != s[len(s)-1] || ones%2 == 1 {
			fmt.Fprintln(out, -1)
			continue
		}

		if s[0] == '0' {
			a, b := buildPair(s)
			fmt.Fprintln(out, 2)
			fmt.Fprintln(out, a)
			fmt.Fprintln(out, b)
		} else {
			d := make([]byte, len(s))
			for i := 0; i < len(s); i++ {
				if s[i] == '0' {
					d[i] = '1'
				} else {
					d[i] = '0'
				}
			}
			a, b := buildPair(string(d))
			fmt.Fprintln(out, 3)
			fmt.Fprintln(out, strings.Repeat("()", n))
			fmt.Fprintln(out, a)
			fmt.Fprintln(out, b)
		}
	}
}