For problem statement at 1000-1999/1200-1299/1270-1279/1270/problemG.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1270-1279/1270/verifierG.go ends with Accepted (7 tests) 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, err := fs.r.ReadByte()
for (c < '0' || c > '9') && c != '-' {
c, err = fs.r.ReadByte()
if err != nil {
return 0
}
}
if c == '-' {
sign = -1
c, _ = fs.r.ReadByte()
}
for c >= '0' && c <= '9' {
val = val*10 + int(c-'0')
c, err = fs.r.ReadByte()
if err != nil {
break
}
}
if err == nil {
_ = fs.r.UnreadByte()
}
return sign * val
}
func main() {
in := NewFastScanner()
out := bufio.NewWriterSize(os.Stdout, 1<<20)
defer out.Flush()
t := in.NextInt()
for ; t > 0; t-- {
n := in.NextInt()
next := make([]int, n+1)
for i := 1; i <= n; i++ {
a := in.NextInt()
next[i] = i - a
}
pos := make([]int, n+1)
path := make([]int, 0, n)
cur := 1
step := 1
for pos[cur] == 0 {
pos[cur] = step
path = append(path, cur)
step++
cur = next[cur]
}
start := pos[cur] - 1
cycle := path[start:]
fmt.Fprintln(out, len(cycle))
for i, v := range cycle {
if i > 0 {
out.WriteByte(' ')
}
fmt.Fprint(out, v)
}
out.WriteByte('\n')
}
}