← Home
For problem statement at 0-999/700-799/740-749/746/problemE.txt this is a correct solution, but verifier at 0-999/700-799/740-749/746/verifierE.go ends with case 1 failed: expected 1
13 60 1 100 18 101 98 43 got 1
13 1 14 100 18 101 98 43
input:
8 115
13 60 14 100 18 101 98 43
exit status 1 can you fix the verifier? ```go
package main

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

type FastScanner struct {
	r *bufio.Reader
}

func NewFastScanner() *FastScanner {
	return &FastScanner{r: bufio.NewReaderSize(os.Stdin, 1<<20)}
}

func (fs *FastScanner) NextInt64() int64 {
	sign := int64(1)
	val := int64(0)
	c, _ := fs.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, _ = fs.r.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, _ = fs.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int64(c-'0')
		c, _ = fs.r.ReadByte()
	}
	return val * sign
}

func getNext(parity int, nextVal *int64, used map[int64]bool, m int64) int64 {
	for *nextVal <= m && used[*nextVal] {
		*nextVal += 2
	}
	if *nextVal > m {
		return -1
	}
	v := *nextVal
	used[v] = true
	*nextVal += 2
	return v
}

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

	n := int(in.NextInt64())
	m := in.NextInt64()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = in.NextInt64()
	}

	used := make(map[int64]bool, n*2)
	change := make([]bool, n)
	res := make([]int64, n)
	copy(res, a)

	evKeep := 0
	dup := 0

	for i := 0; i < n; i++ {
		if !used[a[i]] {
			used[a[i]] = true
			if a[i]%2 == 0 {
				evKeep++
			}
		} else {
			change[i] = true
			dup++
		}
	}

	targetEven := n / 2

	if evKeep > targetEven {
		need := evKeep - targetEven
		for i := 0; i < n && need > 0; i++ {
			if !change[i] && a[i]%2 == 0 {
				change[i] = true
				used[a[i]] = false
				dup++
				need--
			}
		}
		if need > 0 {
			fmt.Fprintln(out, -1)
			return
		}
	} else if evKeep+dup < targetEven {
		need := targetEven - (evKeep + dup)
		for i := 0; i < n && need > 0; i++ {
			if !change[i] && a[i]%2 != 0 {
				change[i] = true
				used[a[i]] = false
				dup++
				need--
			}
		}
		if need > 0 {
			fmt.Fprintln(out, -1)
			return
		}
	}

	evCurrent := 0
	for i := 0; i < n; i++ {
		if !change[i] && a[i]%2 == 0 {
			evCurrent++
		}
	}

	nextEven := int64(2)
	nextOdd := int64(1)

	for i := 0; i < n; i++ {
		if change[i] {
			if evCurrent < targetEven {
				// need even
				v := getNext(0, &nextEven, used, m)
				if v == -1 {
					fmt.Fprintln(out, -1)
					return
				}
				res[i] = v
				evCurrent++
			} else {
				// need odd
				v := getNext(1, &nextOdd, used, m)
				if v == -1 {
					fmt.Fprintln(out, -1)
					return
				}
				res[i] = v
			}
		}
	}

	cnt := 0
	for i := 0; i < n; i++ {
		if change[i] {
			cnt++
		}
	}

	fmt.Fprintln(out, cnt)
	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Fprint(out, " ")
		}
		if change[i] {
			fmt.Fprint(out, res[i])
		} else {
			fmt.Fprint(out, a[i])
		}
	}
	fmt.Fprintln(out)
}
```