For problem statement at 0-999/100-199/120-129/126/problemE.txt this is a correct solution, but verifier at 0-999/100-199/120-129/126/verifierE.go ends with case 1 failed
input:
BYRRWRRY
RBBRYYYB
RWWBRWYY
BWBYWRBB
WYRWWBBB
YRYRYYYR
RBYBYWRB
18 24 19 10 14 19 6 22 15 21
expected:
56
B.Y.R.R.W.R.R.Y
...............
R.B.B.R.Y.Y.Y.B
...............
R.W.W.B.R.W.Y.Y
...............
B.W.B.Y.W.R.B.B
...............
W.Y.R.W.W.B.B.B
...............
Y.R.Y.R.Y.Y.Y.R
...............
R.B.Y.B.Y.W.R.B
got:
56
B-Y.R-R.W-R.R-Y
...............
R-B.B-R.Y-Y.Y-B
...............
R-W.W-B.R-W.Y-Y
...............
B-W.B-Y.W-R.B-B
...............
W-Y.R-W.W-B.B-B
...............
Y-R.Y-R.Y-Y.Y-R
...............
R-B.Y-B.Y-W.R-B
exit status 1 can you fix the verifier? ```go
package main
import (
"fmt"
"math"
"math/rand"
"time"
)
const (
UP = iota
RIGHT
DOWN
LEFT
)
var typeColors = [10][2]int{
{0, 3}, {0, 2}, {0, 1}, {0, 0},
{1, 3}, {1, 2}, {1, 1},
{2, 3}, {2, 2},
{3, 3},
}
var typeMatrix = [4][4]int{
{3, 2, 1, 0},
{2, 6, 5, 4},
{1, 5, 8, 7},
{0, 4, 7, 9},
}
var scoreMatrix [10][10]int
var cost [22][22]int
var capNet [22][22]int
var flow [22][22]int
func init() {
for t := 0; t < 10; t++ {
for p := 0; p < 10; p++ {
tc1, tc2 := typeColors[t][0], typeColors[t][1]
pc1, pc2 := typeColors[p][0], typeColors[p][1]
s1 := 0
if tc1 == pc1 { s1++ }
if tc2 == pc2 { s1++ }
s2 := 0
if tc1 == pc2 { s2++ }
if tc2 == pc1 { s2++ }
if s1 > s2 {
scoreMatrix[t][p] = s1
} else {
scoreMatrix[t][p] = s2
}
}
}
for i := 1; i <= 10; i++ {
for j := 11; j <= 20; j++ {
cost[i][j] = 2 - scoreMatrix[i-1][j-11]
cost[j][i] = -cost[i][j]
}
}
}
func getType(c1, c2 int) int {
return typeMatrix[c1][c2]
}
func packReq(req *[10]int) uint64 {
var res uint64
for i := 0; i < 10; i++ {
res = (res << 5) | uint64(req[i])
}
return res
}
func getMaxScore(req *[10]int, inv *[10]int) int {
for i := 0; i < 22; i++ {
for j := 0; j < 22; j++ {
capNet[i][j] = 0
flow[i][j] = 0
}
}
for i := 1; i <= 10; i++ {
capNet[0][i] = req[i-1]
}
for j := 11; j <= 20; j++ {
capNet[j][21] = inv[j-11]
}
for i := 1; i <= 10; i++ {
for j := 11; j <= 20; j++ {
capNet[i][j] = 28
}
}
totalCost := 0
totalFlow := 0
var dist [22]int
var parent [22]int
var inQ [22]bool
var q [1024]int
for totalFlow < 28 {
for i := 0; i < 22; i++ {
dist[i] = 1e9
parent[i] = -1
inQ[i] = false
}
dist[0] = 0
head, tail := 0, 0
q[tail] = 0
tail++
inQ[0] = true
for head != tail {
u := q[head]
head = (head + 1) & 1023
inQ[u] = false
for v := 0; v < 22; v++ {
if capNet[u][v] - flow[u][v] > 0 && dist[v] > dist[u] + cost[u][v] {
dist[v] = dist[u] + cost[u][v]
parent[v] = u
if !inQ[v] {
inQ[v] = true
q[tail] = v
tail = (tail + 1) & 1023
}
}
}
}
if dist[21] == 1e9 {
break
}
push := 28 - totalFlow
curr := 21
for curr != 0 {
p := parent[curr]
avail := capNet[p][curr] - flow[p][curr]
if avail < push {
push = avail
}
curr = p
}
totalFlow += push
totalCost += push * dist[21]
curr = 21
for curr != 0 {
p := parent[curr]
flow[p][curr] += push
flow[curr][p] -= push
curr = p
}
}
return 56 - totalCost
}
func main() {
var targetColors [7][8]int
for r := 0; r < 7; r++ {
var s string
fmt.Scan(&s)
for c := 0; c < 8; c++ {
switch s[c] {
case 'B': targetColors[r][c] = 0
case 'R': targetColors[r][c] = 1
case 'W': targetColors[r][c] = 2
case 'Y': targetColors[r][c] = 3
}
}
}
var inv [10]int
for i := 0; i < 10; i++ {
fmt.Scan(&inv[i])
}
var dir [7][8]int
for r := 0; r < 7; r++ {
for c := 0; c < 8; c += 2 {
dir[r][c] = RIGHT
dir[r][c+1] = LEFT
}
}
var req [10]int
for r := 0; r < 7; r++ {
for c := 0; c < 8; c += 2 {
t := getType(targetColors[r][c], targetColors[r][c+1])
req[t]++
}
}
bestScore := getMaxScore(&req, &inv)
currentScore := bestScore
bestDir := dir
memo := make(map[uint64]int)
memo[packReq(&req)] = bestScore
rand.Seed(time.Now().UnixNano())
startTime := time.Now()
timeLimit := 1900 * time.Millisecond
T := 5.0
if bestScore < 56 {
for iters := 0; ; iters++ {
if iters&1023 == 0 {
elapsed := time.Since(startTime)
if elapsed > timeLimit {
break
}
progress := float64(elapsed) / float64(timeLimit)
T = 5.0 * math.Exp(-5.0*progress)
}
r := rand.Intn(6)
c := rand.Intn(7)
canFlip := false
isHoriz := false
if dir[r][c] == RIGHT && dir[r+1][c] == RIGHT {
canFlip = true
isHoriz = true
} else if dir[r][c] == DOWN && dir[r][c+1] == DOWN {
canFlip = true
isHoriz = false
}
if !canFlip {
continue
}
var t1, t2, t3, t4 int
if isHoriz {
t1 = getType(targetColors[r][c], targetColors[r][c+1])
t2 = getType(targetColors[r+1][c], targetColors[r+1][c+1])
t3 = getType(targetColors[r][c], targetColors[r+1][c])
t4 = getType(targetColors[r][c+1], targetColors[r+1][c+1])
} else {
t1 = getType(targetColors[r][c], targetColors[r+1][c])
t2 = getType(targetColors[r][c+1], targetColors[r+1][c+1])
t3 = getType(targetColors[r][c], targetColors[r][c+1])
t4 = getType(targetColors[r+1][c], targetColors[r+1][c+1])
}
req[t1]--
req[t2]--
req[t3]++
req[t4]++
hash := packReq(&req)
newScore, exists := memo[hash]
if !exists {
newScore = getMaxScore(&req, &inv)
memo[hash] = newScore
}
delta := newScore - currentScore
accept := false
if delta >= 0 {
accept = true
} else {
prob := math.Exp(float64(delta) / T)
if rand.Float64() < prob {
accept = true
}
}
if accept {
currentScore = newScore
if isHoriz {
dir[r][c] = DOWN; dir[r+1][c] = UP
dir[r][c+1] = DOWN; dir[r+1][c+1] = UP
} else {
dir[r][c] = RIGHT; dir[r][c+1] = LEFT
dir[r+1][c] = RIGHT; dir[r+1][c+1] = LEFT
}
if currentScore > bestScore {
bestScore = currentScore
bestDir = dir
if bestScore == 56 {
break
}
}
} else {
req[t1]++
req[t2]++
req[t3]--
req[t4]--
}
}
}
var bestReq [10]int
for r := 0; r < 7; r++ {
for c := 0; c < 8; c++ {
if bestDir[r][c] == RIGHT {
t := getType(targetColors[r][c], targetColors[r][c+1])
bestReq[t]++
} else if bestDir[r][c] == DOWN {
t := getType(targetColors[r][c], targetColors[r+1][c])
bestReq[t]++
}
}
}
getMaxScore(&bestReq, &inv)
assignedPills := make([][]int, 10)
for i := 1; i <= 10; i++ {
for j := 11; j <= 20; j++ {
for k := 0; k < flow[i][j]; k++ {
assignedPills[i-1] = append(assignedPills[i-1], j-11)
}
}
}
fmt.Println(bestScore)
var out [13][15]byte
for r := 0; r < 13; r++ {
for c := 0; c < 15; c++ {
out[r][c] = '.'
}
}
colorChars := []byte{'B', 'R', 'W', 'Y'}
for r := 0; r < 7; r++ {
for c := 0; c < 8; c++ {
if bestDir[r][c] == RIGHT {
tc1 := targetColors[r][c]
tc2 := targetColors[r][c+1]
t := getType(tc1, tc2)
p := assignedPills[t][0]
assignedPills[t] = assignedPills[t][1:]
pc1 := typeColors[p][0]
pc2 := typeColors[p][1]
s1 := 0
if tc1 == pc1 { s1++ }
if tc2 == pc2 { s1++ }
s2 := 0
if tc1 == pc2 { s2++ }
if tc2 == pc1 { s2++ }
if s1 >= s2 {
out[2*r][2*c] = colorChars[pc1]
out[2*r][2*c+2] = colorChars[pc2]
} else {
out[2*r][2*c] = colorChars[pc2]
out[2*r][2*c+2] = colorChars[pc1]
}
out[2*r][2*c+1] = '-'
} else if bestDir[r][c] == DOWN {
tc1 := targetColors[r][c]
tc2 := targetColors[r+1][c]
t := getType(tc1, tc2)
p := assignedPills[t][0]
assignedPills[t] = assignedPills[t][1:]
pc1 := typeColors[p][0]
pc2 := typeColors[p][1]
s1 := 0
if tc1 == pc1 { s1++ }
if tc2 == pc2 { s1++ }
s2 := 0
if tc1 == pc2 { s2++ }
if tc2 == pc1 { s2++ }
if s1 >= s2 {
out[2*r][2*c] = colorChars[pc1]
out[2*r+2][2*c] = colorChars[pc2]
} else {
out[2*r][2*c] = colorChars[pc2]
out[2*r+2][2*c] = colorChars[pc1]
}
out[2*r+1][2*c] = '|'
}
}
}
for r := 0; r < 13; r++ {
fmt.Println(string(out[r][:]))
}
}
```