For problem statement at 0-999/200-299/270-279/277/problemC.txt this is a correct solution, but verifier at 0-999/200-299/270-279/277/verifierC.go ends with case 1 failed
input:5 3 1
4 1 4 2
expected:FIRST
0 1 1 1
got:FIRST
1 0 1 1
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
buf := make([]byte, 1024*1024)
scanner.Buffer(buf, 10*1024*1024)
scanner.Split(bufio.ScanWords)
nextInt := func() int64 {
scanner.Scan()
s := scanner.Bytes()
var res int64
sign := int64(1)
for _, b := range s {
if b == '-' {
sign = -1
} else {
res = res*10 + int64(b-'0')
}
}
return res * sign
}
if !scanner.Scan() {
return
}
s := scanner.Bytes()
var n int64
sign := int64(1)
for _, b := range s {
if b == '-' {
sign = -1
} else {
n = n*10 + int64(b-'0')
}
}
n *= sign
m := nextInt()
k := int(nextInt())
type Interval struct{ start, end int64 }
vCuts := make(map[int64][]Interval)
hCuts := make(map[int64][]Interval)
for i := 0; i < k; i++ {
x1 := nextInt()
y1 := nextInt()
x2 := nextInt()
y2 := nextInt()
if x1 == x2 {
if y1 > y2 {
y1, y2 = y2, y1
}
vCuts[x1] = append(vCuts[x1], Interval{start: y1, end: y2})
} else {
if x1 > x2 {
x1, x2 = x2, x1
}
hCuts[y1] = append(hCuts[y1], Interval{start: x1, end: x2})
}
}
type Line struct {
id int64
S int64
uncut []Interval
}
var vLines []Line
var hLines []Line
var xor_sum int64
for x, intervals := range vCuts {
sort.Slice(intervals, func(i, j int) bool {
return intervals[i].start < intervals[j].start
})
merged := []Interval{}
for _, iv := range intervals {
if len(merged) == 0 {
merged = append(merged, iv)
} else {
last := &merged[len(merged)-1]
if iv.start <= last.end {
if iv.end > last.end {
last.end = iv.end
}
} else {
merged = append(merged, iv)
}
}
}
uncut := []Interval{}
curr := int64(0)
for _, iv := range merged {
if curr < iv.start {
uncut = append(uncut, Interval{start: curr, end: iv.start})
}
curr = iv.end
}
if curr < m {
uncut = append(uncut, Interval{start: curr, end: m})
}
S := int64(0)
for _, iv := range uncut {
S += iv.end - iv.start
}
vLines = append(vLines, Line{id: x, S: S, uncut: uncut})
xor_sum ^= S
}
for y, intervals := range hCuts {
sort.Slice(intervals, func(i, j int) bool {
return intervals[i].start < intervals[j].start
})
merged := []Interval{}
for _, iv := range intervals {
if len(merged) == 0 {
merged = append(merged, iv)
} else {
last := &merged[len(merged)-1]
if iv.start <= last.end {
if iv.end > last.end {
last.end = iv.end
}
} else {
merged = append(merged, iv)
}
}
}
uncut := []Interval{}
curr := int64(0)
for _, iv := range merged {
if curr < iv.start {
uncut = append(uncut, Interval{start: curr, end: iv.start})
}
curr = iv.end
}
if curr < n {
uncut = append(uncut, Interval{start: curr, end: n})
}
S := int64(0)
for _, iv := range uncut {
S += iv.end - iv.start
}
hLines = append(hLines, Line{id: y, S: S, uncut: uncut})
xor_sum ^= S
}
empty_v := (n - 1) - int64(len(vCuts))
if empty_v%2 == 1 {
xor_sum ^= m
}
empty_h := (m - 1) - int64(len(hCuts))
if empty_h%2 == 1 {
xor_sum ^= n
}
if xor_sum == 0 {
fmt.Println("SECOND")
return
}
fmt.Println("FIRST")
for _, line := range vLines {
target := line.S ^ xor_sum
if target < line.S {
c := line.S - target
y_start := line.uncut[0].start
y_end := int64(0)
rem := c
for _, iv := range line.uncut {
length := iv.end - iv.start
if rem <= length {
y_end = iv.start + rem
break
}
rem -= length
}
fmt.Printf("%d %d %d %d\n", line.id, y_start, line.id, y_end)
return
}
}
for _, line := range hLines {
target := line.S ^ xor_sum
if target < line.S {
c := line.S - target
x_start := line.uncut[0].start
x_end := int64(0)
rem := c
for _, iv := range line.uncut {
length := iv.end - iv.start
if rem <= length {
x_end = iv.start + rem
break
}
rem -= length
}
fmt.Printf("%d %d %d %d\n", x_start, line.id, x_end, line.id)
return
}
}
if (m^xor_sum) < m && empty_v > 0 {
c := m - (m ^ xor_sum)
for x := int64(1); x < n; x++ {
if _, exists := vCuts[x]; !exists {
fmt.Printf("%d 0 %d %d\n", x, x, c)
return
}
}
}
if (n^xor_sum) < n && empty_h > 0 {
c := n - (n ^ xor_sum)
for y := int64(1); y < m; y++ {
if _, exists := hCuts[y]; !exists {
fmt.Printf("0 %d %d %d\n", y, c, y)
return
}
}
}
}
```