Skip to content

Commit ce69adb

Browse files
authored
Merge pull request #5752 from lems9520138/master
Update usaco-737.mdx
2 parents 08173a9 + 14ac56b commit ce69adb

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

solutions/bronze/usaco-737.mdx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@
22
id: usaco-737
33
source: USACO Bronze 2017 US Open
44
title: Modern Art
5-
author: Juheon Rhee, Kevin Sheng, Yifan Ma
5+
author: Juheon Rhee, Kevin Sheng, Yifan Ma, Arnav Gokhale
66
---
77

8-
<Spoiler title="Hint">
8+
[Official Analysis (C++)](http://www.usaco.org/current/data/sol_art_bronze_open17.html)
9+
10+
# Solution
11+
12+
<Spoiler title="Hint 1">
913

1014
Try solving the sample input by hand: could you apply a similar method in your code?
1115

1216
</Spoiler>
1317

14-
[Official Analysis (C++)](http://www.usaco.org/current/data/sol_art_bronze_open17.html)
18+
<Spoiler title="Hint 2">
1519

16-
# Solution
20+
What is a property of a color that cannot be the first painted?
1721

18-
<Spoiler title="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.
1931

2032
## Implementation
2133

@@ -163,7 +175,7 @@ for c in range(1, MAX_COLOR + 1):
163175
left[c], up[c] = float("inf"), float("inf")
164176
right[c], down[c] = -1, -1
165177

166-
valid_start = [False] * MAX_COLOR
178+
valid_start = [False] * (MAX_COLOR + 1)
167179
with open("art.in") as read:
168180
n = int(read.readline().strip())
169181
art = [None] * n
@@ -179,18 +191,18 @@ with open("art.in") as read:
179191
valid_start[curr] = True
180192

181193
for color in range(1, MAX_COLOR + 1):
182-
if any(p[color] == float("inf") for p in [left, right, down, up]):
194+
if left[color] == float("inf"):
183195
continue
184196

185197
for c in range(int(up[color]), int(down[color] + 1)):
186198
for k in range(int(left[color]), int(right[color] + 1)):
187199
if art[c][k] != color:
188-
valid_start[art[c][k]] = False
200+
other = art[c][k]
201+
if other != 0 and other != color:
202+
valid_start[other] = False
189203

190204
print(sum(valid_start), file=open("art.out", "w"))
191205
```
192206

193207
</PySection>
194208
</LanguageSection>
195-
196-
</Spoiler>

0 commit comments

Comments
 (0)