← Home
For problem statement at 1000-1999/1000-1099/1090-1099/1092/problemD1.txt this is a correct solution, but verifier at 1000-1999/1000-1099/1090-1099/1092/verifierD1.go ends with All 100 tests passed can you fix the verifier? 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) NextInt() int {
	sign, val := 1, 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 + int(c-'0')
		c, _ = fs.r.ReadByte()
	}
	fs.r.UnreadByte()
	return sign * val
}

func main() {
	in := NewFastScanner()
	n := in.NextInt()
	stack := make([]int, 0, n)
	for i := 0; i < n; i++ {
		p := in.NextInt() & 1
		if len(stack) > 0 && stack[len(stack)-1] == p {
			stack = stack[:len(stack)-1]
		} else {
			stack = append(stack, p)
		}
	}
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	if len(stack) <= 1 {
		fmt.Fprint(out, "YES")
	} else {
		fmt.Fprint(out, "NO")
	}
	out.Flush()
}