For problem statement at 1000-1999/1400-1499/1450-1459/1455/problemD.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1450-1459/1455/verifierD.go ends with test 1 failed
input:
1
1 382
400
expected: 0
got:
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"os"
)
const MAX = 500
const INF = 1001
var dp [MAX + 1][MAX + 1]int
var vis [MAX + 1][MAX + 1]int
func min(a, b int) int {
if a < b {
return a
}
return b
}
func main() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
var t int
fmt.Fscan(in, &t)
version := 0
for test := 0; test < t; test++ {
var n, x int
fmt.Fscan(in, &n, &x)
a := make([]int, n+1)
for i := 1; i <= n; i++ {
fmt.Fscan(in, &a[i])
}
version += n + 2
currVersion := version
// For i=1
// not swap
newLast := a[1]
dp[newLast][x] = 0
vis[newLast][x] = currVersion
// swap
if a[1] > x {
newLast = x
newCur := a[1]
dp[newLast][newCur] = 1
vis[newLast][newCur] = currVersion
}
for i := 1; i < n; i++ {
prevVersion := currVersion
currVersion = version + 1
version++
for l := 0; l <= MAX; l++ {
for c := 0; c <= MAX; c++ {
if vis[l][c] != prevVersion {
continue
}
ops := dp[l][c]
// not swap
newLast = a[i+1]
if l <= newLast {
if vis[newLast][c] == currVersion {
dp[newLast][c] = min(dp[newLast][c], ops)
} else {
dp[newLast][c] = ops
vis[newLast][c] = currVersion
}
}
// swap
if a[i+1] > c {
newLast = c
if l <= newLast {
newCur := a[i+1]
if vis[newLast][newCur] == currVersion {
dp[newLast][newCur] = min(dp[newLast][newCur], ops+1)
} else {
dp[newLast][newCur] = ops + 1
vis[newLast][newCur] = currVersion
}
}
}
}
}
}
minn := INF
for l := 0; l <= MAX; l++ {
for c := 0; c <= MAX; c++ {
if vis[l][c] == currVersion {
minn = min(minn, dp[l][c])
}
}
}
if minn == INF {
fmt.Fprintln(out, -1)
} else {
fmt.Fprintln(out, minn)
}
}
}
```