-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildSquare.kt
117 lines (98 loc) · 2.9 KB
/
BuildSquare.kt
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package setsandmaps
import java.io.File
data class BuildSquarePoint(
val x: Int,
val y: Int
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as BuildSquarePoint
if (x != other.x) return false
if (y != other.y) return false
return true
}
override fun hashCode(): Int {
var result = x
result = 31 * result + y
return result
}
override fun toString(): String {
return "$x $y"
}
companion object {
fun fromLine(line: String): BuildSquarePoint {
line.split(' ').map { it.toInt() }.let {
return BuildSquarePoint(it[0], it[1])
}
}
fun getAllCandidates(point1: BuildSquarePoint, point2: BuildSquarePoint): List<List<BuildSquarePoint>> {
val dx = point1.x - point2.x
val dy = point1.y - point2.y
return listOf(
listOf(
BuildSquarePoint(point1.x - dy, point1.y + dx),
BuildSquarePoint(point2.x - dy, point2.y + dx)
),
listOf(
BuildSquarePoint(point1.x + dy, point1.y - dx),
BuildSquarePoint(point2.x + dy, point2.y - dx)
)
)
}
}
}
fun main() {
val input = File("input.txt").bufferedReader()
val n = input.readLine().toInt()
val points = List(n) {
BuildSquarePoint.fromLine(input.readLine())
}
val pointsSet = points.toSet()
if (points.size == 1) {
val point = points.first()
println(3)
println("${point.x} 0")
println("0 ${point.y}")
println("0 0")
return
}
var ans = 4
var ansPoints = listOf(
BuildSquarePoint(0, 0),
BuildSquarePoint(1, 0),
BuildSquarePoint(0, 1),
BuildSquarePoint(1, 1)
)
for (i in 0..n - 2) {
for (j in i + 1..<n) {
val point1 = points[i]
val point2 = points[j]
val candidates = BuildSquarePoint.getAllCandidates(point1, point2)
candidates.forEach { line ->
val isCandidate1 = pointsSet.contains(line[0])
val isCandidate2 = pointsSet.contains(line[1])
if (isCandidate1 && isCandidate2) {
println(0)
return
}
if (isCandidate1) {
ans = 1
ansPoints = listOf(line[1])
}
if (isCandidate2) {
ans = 1
ansPoints = listOf(line[0])
}
if (ans > 2) {
ans = 2
ansPoints = line
}
}
}
}
println(ans)
ansPoints.forEach {
println(it)
}
}