-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.go
57 lines (55 loc) · 1.24 KB
/
5.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strconv"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
re := regexp.MustCompile("\\d+")
size := int64(0)
cap := 1000
board := make([]int, cap*cap)
board2 := make([]int, cap*cap)
for scanner.Scan() {
match := re.FindAllString(scanner.Text(), -1)
x1, _ := strconv.ParseInt(match[0], 0, 0)
y1, _ := strconv.ParseInt(match[1], 0, 0)
x2, _ := strconv.ParseInt(match[2], 0, 0)
y2, _ := strconv.ParseInt(match[3], 0, 0)
size = max(size, x1, x2, y1, y2)
if x1 == x2 || y1 == y2 {
for x := min(x1, x2); x <= max(x1, x2); x++ {
for y := min(y1, y2); y <= max(y1, y2); y++ {
board[y*int64(cap)+x]++
board2[y*int64(cap)+x]++
}
}
}
if x1-x2 == y1-y2 {
for x := min(x1, x2); x <= max(x1, x2); x++ {
board2[(x-min(x1, x2)+min(y1, y2))*int64(cap)+x]++
}
}
if x1-x2 == y2-y1 {
for x := min(x1, x2); x <= max(x1, x2); x++ {
board2[(max(y1, y2)-(x-min(x1, x2)))*int64(cap)+x]++
}
}
}
result, result2 := 0, 0
for x := int64(0); x <= size; x++ {
for y := int64(0); y <= size; y++ {
if board[y*int64(cap)+x] > 1 {
result++
}
if board2[y*int64(cap)+x] > 1 {
result2++
}
}
}
fmt.Println(result)
fmt.Println(result2)
}