← Home
For problem statement at 0-999/200-299/250-259/258/problemD.txt this is a correct solution, but verifier at 0-999/200-299/250-259/258/verifierD.go ends with wrong answer on test 1
input: 2 1
1 2
1 2
expected: 0.500000
got: 0.500000000

exit status 1 can you fix the verifier? ```go
package main

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

func main() {
	// Use buffered reader for faster input processing
	in := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscan(in, &n, &m)

	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &p[i])
	}

	// dp represents a flattened 2D array where dp[i*n + j] stores the probability that p[i] > p[j].
	// Size is n*n.
	dp := make([]float64, n*n)

	// Initialize probabilities based on the initial permutation
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if p[i] > p[j] {
				dp[i*n+j] = 1.0
			} else {
				dp[i*n+j] = 0.0
			}
		}
	}

	// Process each move
	for k := 0; k < m; k++ {
		var u, v int
		fmt.Fscan(in, &u, &v)
		u-- // Convert to 0-based index
		v--

		// After the move, the elements at u and v are swapped with probability 0.5.
		// The relationship between positions u and v becomes random (0.5).
		dp[u*n+v] = 0.5
		dp[v*n+u] = 0.5

		// Update probabilities for all other elements relative to u and v
		for i := 0; i < n; i++ {
			if i != u && i != v {
				// Update rows u and v: P(p[u] > p[i]) and P(p[v] > p[i])
				// New P(p[u] > p[i]) = 0.5 * Old P(p[u] > p[i]) + 0.5 * Old P(p[v] > p[i])
				idxUI := u*n + i
				idxVI := v*n + i
				valRow := (dp[idxUI] + dp[idxVI]) * 0.5
				dp[idxUI] = valRow
				dp[idxVI] = valRow

				// Update columns u and v: P(p[i] > p[u]) and P(p[i] > p[v])
				// New P(p[i] > p[u]) = 0.5 * Old P(p[i] > p[u]) + 0.5 * Old P(p[i] > p[v])
				idxIU := i*n + u
				idxIV := i*n + v
				valCol := (dp[idxIU] + dp[idxIV]) * 0.5
				dp[idxIU] = valCol
				dp[idxIV] = valCol
			}
		}
	}

	// Calculate the expected number of inversions
	// Expected value is the sum of probabilities P(p[i] > p[j]) for all pairs i < j
	ans := 0.0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			ans += dp[i*n+j]
		}
	}

	fmt.Printf("%.9f\n", ans)
}
```