← Home
For problem statement at 0-999/900-999/980-989/980/problemC.txt this is a correct solution, but verifier at 0-999/900-999/980-989/980/verifierC.go ends with All 100 tests passed. can you fix the verifier? package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1024*1024*10), 1024*1024*10)

	if !scanner.Scan() {
		return
	}
	firstLine := strings.Fields(scanner.Text())
	if len(firstLine) < 2 {
		return
	}
	n, _ := strconv.Atoi(firstLine[0])
	k, _ := strconv.Atoi(firstLine[1])

	if !scanner.Scan() {
		return
	}
	pixelsStr := strings.Fields(scanner.Text())

	ans := make([]int, 256)
	for i := 0; i < 256; i++ {
		ans[i] = -1
	}

	out := make([]string, 0, n)
	for i := 0; i < n; i++ {
		p, _ := strconv.Atoi(pixelsStr[i])

		if ans[p] != -1 {
			out = append(out, strconv.Itoa(ans[p]))
			continue
		}

		curr := p
		for curr > 0 && ans[curr-1] == -1 && p-(curr-1)+1 <= k {
			curr--
		}

		var key int
		if curr > 0 && ans[curr-1] != -1 && p-ans[curr-1]+1 <= k {
			key = ans[curr-1]
		} else {
			key = curr
		}

		for j := curr; j <= p; j++ {
			if ans[j] == -1 {
				ans[j] = key
			}
		}

		out = append(out, strconv.Itoa(ans[p]))
	}

	fmt.Println(strings.Join(out, " "))
}