← Home
For problem statement at 2000-2999/2000-2099/2090-2099/2092/problemE.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2090-2099/2092/verifierE.go ends with test 1 (sample) failed
input:
2
3 3 6
1 1 0
1 2 1
1 3 0
3 1 1
3 2 0
3 3 1
3 4 12
1 1 0
1 2 1
1 3 0
1 4 1
2 1 1
2 2 0
2 3 1
2 4 0
3 1 0
3 2 1
3 3 0
3 4 1
reference:
0
1

candidate:
4
0
exit status 1 can you fix the verifier? package main

import (
	"bufio"
	"bytes"
	"io"
	"os"
	"strconv"
)

const MOD int64 = 1000000007

func pow2(e int64) int64 {
	res, base := int64(1), int64(2)
	for e > 0 {
		if e&1 == 1 {
			res = res * base % MOD
		}
		base = base * base % MOD
		e >>= 1
	}
	return res
}

func main() {
	data, _ := io.ReadAll(bufio.NewReaderSize(os.Stdin, 1<<20))
	idx := 0
	nextInt := func() int64 {
		for idx < len(data) && (data[idx] < '0' || data[idx] > '9') {
			idx++
		}
		var v int64
		for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
			v = v*10 + int64(data[idx]-'0')
			idx++
		}
		return v
	}

	t := int(nextInt())
	var out bytes.Buffer

	for ; t > 0; t-- {
		n := nextInt()
		m := nextInt()
		k := nextInt()

		totalOdd := int64(2) * (n + m - 4)
		cntOddSpecified := int64(0)
		parity := int64(0)

		for i := int64(0); i < k; i++ {
			x := nextInt()
			y := nextInt()
			c := nextInt()

			boundary := x == 1 || x == n || y == 1 || y == m
			corner := (x == 1 || x == n) && (y == 1 || y == m)
			if boundary && !corner {
				cntOddSpecified++
				parity ^= c
			}
		}

		totalCells := n * m
		free := totalCells - k

		var ans int64
		if cntOddSpecified < totalOdd {
			ans = pow2(free - 1)
		} else {
			if parity == 0 {
				ans = pow2(free)
			} else {
				ans = 0
			}
		}

		out.WriteString(strconv.FormatInt(ans, 10))
		out.WriteByte('\n')
	}

	w := bufio.NewWriterSize(os.Stdout, 1<<20)
	w.Write(out.Bytes())
	w.Flush()
}