problem_id stringlengths 12 45 | cp_id stringlengths 2 4 | name stringlengths 3 34 | description stringlengths 940 4.03k | problem_level stringclasses 4
values | problem_link stringlengths 56 58 | contest_link stringclasses 45
values | description_no_samples stringlengths 713 3.03k | samples listlengths 1 3 | num_samples int64 1 3 | solution_python3 stringlengths 106 4.14k | solution_english stringlengths 154 7.91k | tests listlengths 9 23 | num_tests int64 9 23 | runtime_limit_sec int64 2 15 | memory_limit_mb int64 256 512 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
93_gold_cow_steeplechase | 93 | Cow Steeplechase | Problem 3: Cow Steeplechase [Brian Dean]
Farmer John has a brilliant idea for the next great spectator sport: Cow
Steeplechase! As everyone knows, regular steeplechase involves a group of
horses that race around a course filled with obstacles they must jump over.
FJ figures the same contest should work with highly-tra... | gold | http://www.usaco.org/index.php?page=viewproblem2&cpid=93 | http://www.usaco.org/index.php?page=nov11results | Problem 3: Cow Steeplechase [Brian Dean]
Farmer John has a brilliant idea for the next great spectator sport: Cow
Steeplechase! As everyone knows, regular steeplechase involves a group of
horses that race around a course filled with obstacles they must jump over.
FJ figures the same contest should work with highly-tra... | [
{
"input": "3\n4 5 10 5\n6 2 6 12\n8 3 8 5",
"output": "2",
"explanation": "There are three potential obstacles. The first is a horizontal segment\nconnecting (4, 5) to (10, 5); the second and third are vertical segments\nconnecting (6, 2) to (6, 12) and (8, 3) to (8, 5).\nThe optimal solution is to cho... | 1 |
from collections import defaultdict
class BipartiteMatcher:
def __init__(self):
self.G = defaultdict(list)
def add_edge(self, u, v):
self.G[u].append(v)
def _augment(self, u, match, visited):
if u not in visited:
visited.add(u)
for v in self.G[u]:
... | Contest Results
Solution Notes: In one sentence, this problem boils down to computing the size of a maximum independent set in a bipartite graph. Nodes on the left-hand side of the graph represent horizontal segments, and nodes on the right-hand side represent vertical segments; two nodes are connected if their corres... | [
{
"input": "3\n4 5 10 5\n6 2 6 12\n8 3 8 5\n",
"output": "2\n"
},
{
"input": "4\n1 1 2 1\n2 1 2 6\n1 1 1 3\n1 3 4 3\n",
"output": "2\n"
},
{
"input": "16\n2 8 2 15\n10 1 5 1\n19 19 19 3\n14 14 2 14\n8 2 8 12\n3 16 8 16\n17 12 17 5\n14 3 13 3\n3 2 3 17\n16 19 8 19\n7 12 7 19\n1 10 16 10\n... | 10 | 2 | 256 |
88_silver_cow_beauty_pageant_(silver_level) | 88 | Cow Beauty Pageant (Silver Level) | Problem 1: Cow Beauty Pageant (Silver Level) [Brian Dean]
Hearing that the latest fashion trend was cows with three spots on their
hides, Farmer John has purchased an entire herd of three-spot cows.
Unfortunately, fashion trends tend to change quickly, and the most popular
current fashion is cows with only one spot! ... | silver | http://www.usaco.org/index.php?page=viewproblem2&cpid=88 | http://www.usaco.org/index.php?page=nov11results | Problem 1: Cow Beauty Pageant (Silver Level) [Brian Dean]
Hearing that the latest fashion trend was cows with three spots on their
hides, Farmer John has purchased an entire herd of three-spot cows.
Unfortunately, fashion trends tend to change quickly, and the most popular
current fashion is cows with only one spot! ... | [
{
"input": "6 16\n................\n..XXXX....XXX...\n...XXXX....XX...\n.XXXX......XXX..\n........XXXXX...\n..XXX....XXX....",
"output": "4",
"explanation": "The pattern in the input shows a cow hide with three distinct spots.\nFour 'X's suffice to join the three spots into one.",
"input_explanation... | 1 |
def mark_spot(a, b, num, cow, N, M, spots, counts):
if a < 0 or b < 0 or a == N or b == M or cow[a][b] != 'X':
return
cow[a][b] = 'V'
spots[num][counts[num]] = (a, b)
counts[num] += 1
mark_spot(a - 1, b, num, cow, N, M, spots, counts)
mark_spot(a + 1, b, num, cow, N, M, spots, counts)
... | Contest Results
Solution Notes: We first use a recursive "floodfill" to label the characters in the three different spots with 1s, 2s, and 3s (in the process, we may also want to make a list of the locations of the characters in each spot). Next, we need to figure out the optimal way to join the three spots together. ... | [
{
"input": "6 16\n................\n..XXXX....XXX...\n...XXXX....XX...\n.XXXX......XXX..\n........XXXXX...\n..XXX....XXX....\n",
"output": "4\n"
},
{
"input": "9 9\nXXXXXXXXX\nX.......X\nX.XXXXX.X\nX.X...X.X\nX.X.X.X.X\nX.X...X.X\nX.XXXXX.X\nX.......X\nXXXXXXXXX\n",
"output": "2\n"
},
{
... | 12 | 2 | 256 |
89_silver_cow_lineup | 89 | Cow Lineup | Problem 2: Cow Lineup [Brian Dean]
Farmer John has hired a professional photographer to take a picture of some
of his cows. Since FJ's cows represent a variety of different breeds, he
would like the photo to contain at least one cow from each distinct breed
present in his herd.
FJ's N cows are all standing at variou... | silver | http://www.usaco.org/index.php?page=viewproblem2&cpid=89 | http://www.usaco.org/index.php?page=nov11results | Problem 2: Cow Lineup [Brian Dean]
Farmer John has hired a professional photographer to take a picture of some
of his cows. Since FJ's cows represent a variety of different breeds, he
would like the photo to contain at least one cow from each distinct breed
present in his herd.
FJ's N cows are all standing at variou... | [
{
"input": "6\n25 7\n26 1\n15 1\n22 3\n20 1\n30 1",
"output": "4",
"explanation": "There are 6 cows, at positions 25,26,15,22,20,30, with respective breed IDs\n7,1,1,3,1,1.\nThe range from x=22 up through x=26 (of total size 4) contains each of the\ndistinct breed IDs 1, 3, and 7 represented in FJ's her... | 1 |
from collections import defaultdict
def read_int():
return int(input().strip())
def read_ints():
return map(int, input().strip().split())
N = read_int()
cows = []
ID_set = set()
for _ in range(N):
loc, id = read_ints()
cows.append((loc, id))
ID_set.add(id)
cows.sort()
num_IDS = len(ID_set)
br... | Contest Results
Solution Notes: This is a somewhat interesting problem since there are several nice algorithmic ways to approach its solution. The problem can be solved in O(N log N) time due to the need to sort the cows by x coordinate as a preprocessing step. One nice method (perhaps not the simplest, but worth ment... | [
{
"input": "6\n25 7\n26 1\n15 1\n22 3\n20 1\n30 1\n",
"output": "4\n"
},
{
"input": "10\n1 3\n10 3\n9 2\n6 3\n8 3\n5 3\n2 2\n7 2\n3 3\n4 1\n",
"output": "2\n"
},
{
"input": "25\n764 3\n783 2\n60 2\n369 3\n691 3\n427 5\n384 3\n422 2\n28 2\n212 1\n650 3\n568 4\n493 3\n336 2\n794 5\n927 2\n... | 12 | 2 | 256 |
90_silver_tile_exchanging | 90 | Tile Exchanging | Problem 3: Tile Exchanging [Ray Li]
Farmer John wants to remodel the floor of his barn using a collection of
square tiles he recently purchased from the local square mart store (which
of course, only sells square objects). Unfortunately, he didn't measure
the size of the barn properly before making his purchase, so n... | silver | http://www.usaco.org/index.php?page=viewproblem2&cpid=90 | http://www.usaco.org/index.php?page=nov11results | Problem 3: Tile Exchanging [Ray Li]
Farmer John wants to remodel the floor of his barn using a collection of
square tiles he recently purchased from the local square mart store (which
of course, only sells square objects). Unfortunately, he didn't measure
the size of the barn properly before making his purchase, so n... | [
{
"input": "3 6\n3\n3\n1",
"output": "5",
"explanation": "There are 3 tiles. Two are squares of side length 3, and one is a square\nwith side length 1. We would like to exchange these to make a total area of 6.\nExchange one of the side-3 squares for a side-2 square, and another side-3\nsquare for a s... | 1 |
MAX_M = 10000
MAX_N = 10
INF = 1000000000
best = [[INF] * (MAX_N + 1) for _ in range(MAX_M + 1)]
A = [0] * (MAX_M + 1)
N, M = map(int, input().split())
for i in range(1, N + 1):
A[i] = int(input())
best[0][0] = 0
for i in range(1, M + 1):
best[i][0] = INF
for j in range(1, N + 1):
for i in range(M + 1)... | Contest Results
Solution Notes: This problem is solved with dynamic programming. Let best[i][j] denote the minimum cost of building a total area of i by exchanging only tiles 1 through j (or infinity if it is impossible to do so). As a base case, we have best[0][0] = 0 and best[i>0][0] = infinity. Otherwise, we can co... | [
{
"input": "3 6\n3\n3\n1\n",
"output": "5\n"
},
{
"input": "3 9999\n5\n20\n100\n",
"output": "-1\n"
},
{
"input": "6 77\n3\n4\n6\n7\n1\n5\n",
"output": "11\n"
},
{
"input": "9 36\n4\n2\n3\n4\n4\n2\n3\n5\n2\n",
"output": "21\n"
},
{
"input": "3 70\n5\n1\n1\n",
... | 12 | 2 | 256 |
84_bronze_contest_timing | 84 | Contest Timing | Problem 1: Contest Timing [Brian Dean]
Bessie the cow is getting bored of the milk production industry, and wants
to switch to an exciting new career in computing. To improve her coding
skills, she decides to compete in the on-line USACO competitions. Since
she notes that the contest starts on November 11, 2011 (11... | bronze | http://www.usaco.org/index.php?page=viewproblem2&cpid=84 | http://www.usaco.org/index.php?page=nov11results | Problem 1: Contest Timing [Brian Dean]
Bessie the cow is getting bored of the milk production industry, and wants
to switch to an exciting new career in computing. To improve her coding
skills, she decides to compete in the on-line USACO competitions. Since
she notes that the contest starts on November 11, 2011 (11... | [
{
"input": "12 13 14",
"output": "1563",
"explanation": "Bessie ends the contest on November 12, at 13:14 (that is, at 1:14 PM).\nBessie ends the contest 1563 minutes after she starts.",
"input_explanation": "Bessie ends the contest on November 12, at 13:14 (that is, at 1:14 PM).",
"output_expla... | 1 |
def total_mins(d, h, m):
return d * 24 * 60 + h * 60 + m
d, h, m = map(int, input().split())
if total_mins(d, h, m) < total_mins(11, 11, 11):
print("-1")
else:
print(total_mins(d, h, m) - total_mins(11, 11, 11))
| Contest Results
Solution Notes: A key to making the problem easy to solve is to write a function that converts from (day, hour, minute) to a single integer that reflects an absolute count of number of minutes since some pre-determined starting point. In the sample C solution below, the function total_mins() computes t... | [
{
"input": "12 13 14\n",
"output": "1563\n"
},
{
"input": "12 22 43\n",
"output": "2132\n"
},
{
"input": "14 17 55\n",
"output": "4724\n"
},
{
"input": "12 12 46\n",
"output": "1535\n"
},
{
"input": "14 2 1\n",
"output": "3770\n"
},
{
"input": "14 19 5... | 10 | 2 | 256 |
86_bronze_moo_sick | 86 | Moo Sick | Problem 3: Moo Sick [Rob Seay]
Everyone knows that cows love to listen to all forms of music. Almost all
forms, that is -- the great cow composer Wolfgang Amadeus Moozart
once discovered that a specific chord tends to make cows rather ill. This
chord, known as the ruminant seventh chord, is therefore typically avoid... | bronze | http://www.usaco.org/index.php?page=viewproblem2&cpid=86 | http://www.usaco.org/index.php?page=nov11results | Problem 3: Moo Sick [Rob Seay]
Everyone knows that cows love to listen to all forms of music. Almost all
forms, that is -- the great cow composer Wolfgang Amadeus Moozart
once discovered that a specific chord tends to make cows rather ill. This
chord, known as the ruminant seventh chord, is therefore typically avoid... | [
{
"input": "6\n1\n8\n5\n7\n9\n10\n3\n4\n6\n7",
"output": "2\n2\n4",
"explanation": "FJ's song is 1,8,5,7,9,10. A ruminant seventh chord is some\ntransposition/re-ordering of 4,6,7.\nTwo ruminant seventh chords appear in FJ's song (and these occurrences\nactually overlap by one note). The first is 8,5,... | 1 |
def translate_so_min_is_zero(X):
min_val = min(X)
for i in range(len(X)):
X[i] -= min_val
def sort(X):
X.sort()
def match(A, B, idx, C):
P = A[idx:idx+C]
Q = B[:]
translate_so_min_is_zero(P)
translate_so_min_is_zero(Q)
sort(P)
sort(Q)
return P == Q
N = int(input())
A ... | Contest Results
Solution Notes: At a high level, all we need to do to solve this problem is to test every window of length C within our larger piece of music to see if it "matches" our chord pattern. The is done in the match() function below, where P[] is a length-C array containing a window from the larger piece of m... | [
{
"input": "6\n1\n8\n5\n7\n9\n10\n3\n4\n6\n7\n",
"output": "2\n2\n4\n"
},
{
"input": "32\n26\n63\n36\n44\n68\n42\n33\n47\n31\n55\n34\n29\n51\n41\n27\n62\n38\n64\n55\n31\n34\n63\n39\n42\n28\n37\n28\n39\n37\n63\n42\n19\n5\n42\n28\n39\n37\n63\n",
"output": "3\n4\n22\n27\n"
},
{
"input": "24... | 10 | 2 | 256 |
87_bronze_cow_beauty_pageant_(bronze_level) | 87 | Cow Beauty Pageant (Bronze Level) | Problem 4: Cow Beauty Pageant (Bronze Level) [Brian Dean]
Hearing that the latest fashion trend was cows with two spots on their
hides, Farmer John has purchased an entire herd of two-spot cows.
Unfortunately, fashion trends tend to change quickly, and the most popular
current fashion is cows with only one spot!
F... | bronze | http://www.usaco.org/index.php?page=viewproblem2&cpid=87 | http://www.usaco.org/index.php?page=nov11results | Problem 4: Cow Beauty Pageant (Bronze Level) [Brian Dean]
Hearing that the latest fashion trend was cows with two spots on their
hides, Farmer John has purchased an entire herd of two-spot cows.
Unfortunately, fashion trends tend to change quickly, and the most popular
current fashion is cows with only one spot!
F... | [
{
"input": "6 16\n................\n..XXXX....XXX...\n...XXXX....XX...\n.XXXX......XXX..\n........XXXXX...\n.........XXX....",
"output": "3",
"explanation": "The pattern in the input shows a cow hide with two distinct spots, labeled\n1 and 2 below:\n\n................\n..1111....222...\n...1111....22...... | 1 |
def label(r, c, ch):
if r < 0 or r >= N or c < 0 or c >= M or G[r][c] != 'X':
return
G[r][c] = ch
label(r-1, c, ch)
label(r+1, c, ch)
label(r, c-1, ch)
label(r, c+1, ch)
def mindist():
min_dist = N + M
for r1 in range(N):
for c1 in range(M):
if G[r1][c1] == ... | Contest Results
Solution Notes: This was by far the most challenging problem on the bronze contest. To solve it, we first label each of the two spots by using the recursive "flood fill" function label() that spreads out and sets every character in the spot to 1 (for the first spot) or 2 (for the second spot). This rec... | [
{
"input": "6 16\n................\n..XXXX....XXX...\n...XXXX....XX...\n.XXXX......XXX..\n........XXXXX...\n.........XXX....\n",
"output": "3\n"
},
{
"input": "10 16\n...XXXXXXXXXX...\n...X........X...\n...X........X...\n...X........X...\n...X...XXX..X...\n...X..XXXX..X...\n...X........X...\n...X...... | 10 | 2 | 256 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.