For problem statement at 0-999/600-699/680-689/685/problemC.txt this is a correct solution, but verifier at 0-999/600-699/680-689/685/verifierC.go ends with wrong answer on test 16
input:1
3
1 -2 -1
3 3 -3
2 3 1
expected:1 2 -2
output:1 2 -1 can you fix the verifier? package main
import (
"io"
"os"
"strconv"
)
const (
HI int64 = 6000000000000000000
BIG int64 = 9000000000000000000
MaxI int64 = 1<<63 - 1
MinI int64 = -1 << 63
)
type Scanner struct {
data []byte
idx int
}
func (s *Scanner) Int64() int64 {
n := len(s.data)
for s.idx < n && s.data[s.idx] <= ' ' {
s.idx++
}
sign := int64(1)
if s.data[s.idx] == '-' {
sign = -1
s.idx++
}
var v int64
for s.idx < n {
c := s.data[s.idx]
if c < '0' || c > '9' {
break
}
v = v*10 + int64(c-'0')
s.idx++
}
return v * sign
}
type Pt struct {
a, b, c, d int64
}
func max64(a, b int64) int64 {
if a > b {
return a
}
return b
}
func min64(a, b int64) int64 {
if a < b {
return a
}
return b
}
func nextParity(v, p int64) int64 {
if (v & 1) != p {
return v + 1
}
return v
}
func prevParity(v, p int64) int64 {
if (v & 1) != p {
return v - 1
}
return v
}
func satAdd(a, b int64) int64 {
if b > 0 && a > MaxI-b {
return MaxI
}
if b < 0 && a < MinI-b {
return MinI
}
return a + b
}
func satSub(a, b int64) int64 {
if b > 0 && a < MinI+b {
return MinI
}
if b < 0 && a > MaxI+b {
return MaxI
}
return a - b
}
func trySolve(pts []Pt, r int64, build bool) (bool, int64, int64, int64) {
la, lb, lc, ld := int64(-BIG), int64(-BIG), int64(-BIG), int64(-BIG)
ua, ub, uc, ud := int64(BIG), int64(BIG), int64(BIG), int64(BIG)
for _, p := range pts {
x := p.a - r
if x > la {
la = x
}
x = p.a + r
if x < ua {
ua = x
}
x = p.b - r
if x > lb {
lb = x
}
x = p.b + r
if x < ub {
ub = x
}
x = p.c - r
if x > lc {
lc = x
}
x = p.c + r
if x < uc {
uc = x
}
x = p.d - r
if x > ld {
ld = x
}
x = p.d + r
if x < ud {
ud = x
}
}
if la > ua || lb > ub || lc > uc || ld > ud {
return false, 0, 0, 0
}
for parity := 0; parity < 2; parity++ {
pp := int64(parity)
aoL := nextParity(la, pp)
aoU := prevParity(ua, pp)
if aoL > aoU {
continue
}
boL := nextParity(lb, pp)
boU := prevParity(ub, pp)
if boL > boU {
continue
}
coL := nextParity(lc, pp)
coU := prevParity(uc, pp)
if coL > coU {
continue
}
doL := nextParity(ld, pp)
doU := prevParity(ud, pp)
if doL > doU {
continue
}
tL := (aoL - 3*pp) / 2
tU := (aoU - 3*pp) / 2
bL := (boL - pp) / 2
bU := (boU - pp) / 2
cL := (coL - pp) / 2
cU := (coU - pp) / 2
dL := (doL - pp) / 2
dU := (doU - pp) / 2
sumL := satAdd(satAdd(bL, cL), dL)
sumU := satAdd(satAdd(bU, cU), dU)
low := max64(tL, sumL)
high := min64(tU, sumU)
if low > high {
continue
}
if !build {
return true, 0, 0, 0
}
target := low
bLow := max64(bL, satSub(target, satAdd(cU, dU)))
bHigh := min64(bU, satSub(target, satAdd(cL, dL)))
if bLow > bHigh {
continue
}
bv := bLow
rem := satSub(target, bv)
cLow := max64(cL, satSub(rem, dU))
cHigh := min64(cU, satSub(rem, dL))
if cLow > cHigh {
continue
}
cv := cLow
dv := satSub(rem, cv)
if dv < dL || dv > dU {
continue
}
x := satAdd(satAdd(bv, cv), pp)
y := satAdd(satAdd(bv, dv), pp)
z := satAdd(satAdd(cv, dv), pp)
return true, x, y, z
}
return false, 0, 0, 0
}
func main() {
data, _ := io.ReadAll(os.Stdin)
in := Scanner{data: data}
t := int(in.Int64())
out := make([]byte, 0, t*70)
for ; t > 0; t-- {
n := int(in.Int64())
pts := make([]Pt, n)
for i := 0; i < n; i++ {
x := in.Int64()
y := in.Int64()
z := in.Int64()
pts[i] = Pt{
a: x + y + z,
b: x + y - z,
c: x - y + z,
d: -x + y + z,
}
}
lo, hi := int64(-1), HI
for hi-lo > 1 {
mid := lo + (hi-lo)/2
ok, _, _, _ := trySolve(pts, mid, false)
if ok {
hi = mid
} else {
lo = mid
}
}
_, x, y, z := trySolve(pts, hi, true)
out = strconv.AppendInt(out, x, 10)
out = append(out, ' ')
out = strconv.AppendInt(out, y, 10)
out = append(out, ' ')
out = strconv.AppendInt(out, z, 10)
out = append(out, '\n')
}
_, _ = os.Stdout.Write(out)
}