You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is a property of a color that cannot be the first painted?
17
21
18
-
<Spoilertitle="Solution">
22
+
</Spoiler>
23
+
24
+
## Explanation
25
+
26
+
First, notice that if two colors are overlapping, we know at least one of them cannot be the original rectangle.
27
+
28
+
For each color $c_1$, we can determine the limits of that color and consider its bounding rectangle. Any other color $c_2$ that appears inside this rectangle in the final grid must have been painted after $c_1$, and we can rule out $c_2$ as the first color painted.
29
+
30
+
We must notice that we always choose the smallest bounding rectangle as possible for each color $c_1$. This is because a larger rectangle creates more intersection between colors, which could elminate valid starting colors.
19
31
20
32
## Implementation
21
33
@@ -163,7 +175,7 @@ for c in range(1, MAX_COLOR + 1):
163
175
left[c],up[c]=float("inf"),float("inf")
164
176
right[c],down[c]=-1,-1
165
177
166
-
valid_start=[False]*MAX_COLOR
178
+
valid_start=[False]*(MAX_COLOR+1)
167
179
withopen("art.in")asread:
168
180
n=int(read.readline().strip())
169
181
art=[None]*n
@@ -179,18 +191,18 @@ with open("art.in") as read:
0 commit comments