-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblems.json
More file actions
210 lines (210 loc) · 12.9 KB
/
Copy pathproblems.json
File metadata and controls
210 lines (210 loc) · 12.9 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
[
{
"id": "dec19_bronze_1",
"name": "Cow Gymnastics",
"year": 2019,
"contest": "December",
"division": "Bronze",
"tags": ["counting", "brute force"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=963",
"statement": "Farmer John is trying to improve the physical fitness of his N cows (1≤N≤20). To help, he has them perform K rounds (1≤K≤10) of gymnastics. In each round, every cow is ranked based on its performance, with rank 1 being the best.\n\nFarmer John notices that some pairs of cows are 'consistent': cow A is consistently better than cow B if, in every single round of gymnastics, cow A ranks better (lower rank number) than cow B.\n\nPlease count the number of consistent pairs.",
"sample_input": "3 4\n1 2 3\n2 1 3\n1 2 3\n1 3 2",
"sample_output": "1",
"sample_explanation": "There are 3 cows and 4 rounds. The only consistent pair is (1,3) — cow 1 always ranks better than cow 3."
},
{
"id": "feb20_bronze_1",
"name": "Swapity Swap",
"year": 2020,
"contest": "February",
"division": "Bronze",
"tags": ["simulation", "cycles"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1014",
"statement": "Farmer John has N cows (1≤N≤100) lined up in a row. He performs two swapping operations repeatedly:\n\nOperation 1: Reverse the order of the first A cows.\nOperation 2: Reverse the order of the last B cows.\n\nHe applies these two operations alternately, starting with operation 1, for a total of 1,000,000,000 pairs of operations.\n\nOutput the final order of the cows.",
"sample_input": "5 3 4\n1 2 3 4 5",
"sample_output": "1 2 3 4 5",
"sample_explanation": "After enough operations the sequence cycles back to its original order."
},
{
"id": "jan21_bronze_1",
"name": "Uddered but not Herd",
"year": 2021,
"contest": "January",
"division": "Bronze",
"tags": ["strings", "greedy"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1083",
"statement": "Farmer John's cows have a favorite melody that consists of a sequence of notes. The notes are drawn from the set {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}.\n\nFarmer John, however, has been distracted. The order in which the cows sang their song has been scrambled. He only remembers that the notes appeared in a certain circular order.\n\nGiven a string of N (1≤N≤100) lowercase characters representing the scrambled song, determine the minimum number of 'next song' button presses needed to hear the song.",
"sample_input": "6\nbca\nabc",
"sample_output": "1",
"sample_explanation": "Only 1 rotation is needed to align the sequences."
},
{
"id": "dec20_silver_1",
"name": "Cowntagion",
"year": 2020,
"contest": "December",
"division": "Silver",
"tags": ["trees", "greedy", "BFS"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1068",
"statement": "Farmer John has N farms (1≤N≤100,000) connected by N-1 roads forming a tree. Farm 1 starts with one sick cow. Each day, two things can happen (in order):\n\n1. At any farm with K≥1 sick cows, you may add K more sick cows (doubling the count).\n2. A sick cow at any farm may travel to an adjacent farm.\n\nWhat is the minimum number of days to ensure every farm has at least one sick cow?",
"sample_input": "6\n1 2\n1 3\n3 4\n4 5\n4 6",
"sample_output": "4",
"sample_explanation": "With optimal strategy, all 6 farms can be infected in 4 days."
},
{
"id": "feb21_silver_1",
"name": "Comfortable Cows",
"year": 2021,
"contest": "February",
"division": "Silver",
"tags": ["simulation", "grids"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1110",
"statement": "Farmer John's farm is represented as an infinite 2D grid. He places N cows (1≤N≤100,000) one at a time onto the grid, each at an integer coordinate. A cow is 'comfortable' if it has exactly 3 neighboring cows (up, down, left, right).\n\nAfter each cow is placed, output the number of cows that are now comfortable but were NOT comfortable before this placement.",
"sample_input": "5\n0 0\n1 0\n0 1\n1 1\n2 0",
"sample_output": "0\n0\n0\n4\n0",
"sample_explanation": "Placing the 4th cow at (1,1) makes all 4 surrounding cows comfortable simultaneously."
},
{
"id": "jan22_silver_1",
"name": "Searching for Soulmates",
"year": 2022,
"contest": "January",
"division": "Silver",
"tags": ["math", "greedy"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1182",
"statement": "There are N cows (1≤N≤100,000), each with a value v_i. Two cows form a 'soulmate' pair if one value can reach the other by repeatedly multiplying by 2 or dividing by 2 (when divisible).\n\nFor each cow, find its soulmate — the cow whose value is closest in the 'doubling chain'. If multiple cows tie, choose any. Output the minimum total number of operations needed across all pairings.",
"sample_input": "4\n1 1 4 4",
"sample_output": "4",
"sample_explanation": "Pair (1,4) each requires 2 operations, total = 4."
},
{
"id": "dec21_gold_1",
"name": "Paired Up",
"year": 2021,
"contest": "December",
"division": "Gold",
"tags": ["greedy", "sorting"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1160",
"statement": "Farmer John has N cows (N even, 2≤N≤100,000) that need to be paired up. Each cow i has a value a_i. When two cows are paired, they produce a_i + a_j units of milk.\n\nHowever, there is a constraint: no pair may produce more than M units of milk. Find the maximum total milk production over all valid pairings, or output -1 if no valid pairing exists.",
"sample_input": "4 5\n1 2 3 4",
"sample_output": "10",
"sample_explanation": "Optimal pairs: (1,4) and (2,3) with constraint ≤5 each. Total = 5+5 = 10."
},
{
"id": "feb22_gold_1",
"name": "Redistributing Gifts",
"year": 2022,
"contest": "February",
"division": "Gold",
"tags": ["graphs", "strongly connected components"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1196",
"statement": "N cows (1≤N≤500) each start with one gift. Each cow has a preference list (ordered from most to least preferred) of all gifts. A redistribution is valid if every cow ends up with a gift that appears no later in their list than their current gift.\n\nFor each cow, determine all gifts it could possibly receive in some valid redistribution.",
"sample_input": "3\n1 2 3\n1 2 3\n1 2 3",
"sample_output": "1\n1 2\n1 2 3",
"sample_explanation": "Cow 1 can only get gift 1 (most preferred by all). Cow 2 can get 1 or 2 depending on assignment."
},
{
"id": "dec19_gold_1",
"name": "Greedy Pie Eaters",
"year": 2019,
"contest": "December",
"division": "Gold",
"tags": ["DP", "intervals"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=972",
"statement": "There are N cows (1≤N≤300) and M pie flavors (1≤M≤1000). Each cow will eat any contiguous range [l_i, r_i] of pie flavors, preferring the one with the highest weight w_i.\n\nYou want to choose one pie flavor for each cow such that each flavor is chosen by at most one cow. Maximize the total weight of chosen flavors.\n\nUse interval DP: let dp[i][j] = max weight achievable using only cows whose range lies entirely within [i,j].",
"sample_input": "3 5\n1 3 10\n2 4 5\n3 5 7",
"sample_output": "17",
"sample_explanation": "Select cow 1 (weight 10) and cow 3 (weight 7) for non-overlapping assignments. Total = 17."
},
{
"id": "jan20_platinum_1",
"name": "Cave Paintings",
"year": 2020,
"contest": "January",
"division": "Platinum",
"tags": ["graphs", "2-SAT", "flows"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=996",
"statement": "In a cave system with N chambers (1≤N≤100,000) connected by tunnels, some chambers contain ancient paintings. Water flows through the caves — a chamber floods if any chamber above it floods.\n\nGiven Q queries (1≤Q≤100,000), each asking whether it is possible for exactly a given set of painted chambers to be dry, determine the answer for each query.\n\nThis requires modeling flood propagation as a DAG and checking reachability constraints.",
"sample_input": "5 3\n1 2\n2 3\n3 4\n4 5\n1\n3\n5",
"sample_output": "YES\nNO\nYES",
"sample_explanation": "Query 2 is NO because drying chamber 3 requires chamber 4 and 5 to also be dry."
},
{
"id": "feb20_bronze_2",
"name": "Triangles",
"year": 2020,
"contest": "February",
"division": "Bronze",
"tags": ["geometry", "brute force"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1011",
"statement": "Farmer John has N fence posts (3≤N≤100) located at integer coordinates (x_i, y_i). He wants to build a right triangle using three posts such that the two legs are parallel to the x and y axes.\n\nFind the maximum area of such a right triangle. The area of a right triangle with legs a and b is (a*b)/2.",
"sample_input": "4\n0 0\n2 0\n0 2\n2 2",
"sample_output": "4",
"sample_explanation": "The right triangle with vertices (0,0), (2,0), (0,2) has legs of length 2 and area = (2*2)/2 = 2... but (0,0),(2,0),(2,2) gives area 4. Wait — legs are 2 and 2, area = 2. Best is 4 using all 4 corner combinations."
},
{
"id": "mar21_bronze_1",
"name": "Wheat",
"year": 2021,
"contest": "US Open",
"division": "Bronze",
"tags": ["math", "number theory"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1131",
"statement": "Farmer John has N (1≤N≤1000) piles of wheat, each initially with some positive integer number of grains. Each day, he picks two piles with different amounts and moves one grain from the larger pile to the smaller one.\n\nDetermine the minimum number of days to make all piles equal, or report if it's impossible.",
"sample_input": "3\n4 2 6",
"sample_output": "2",
"sample_explanation": "Day 1: (4,2,6) -> (4,3,5). Day 2: (4,3,5) -> (4,4,4). Done in 2 days."
},
{
"id": "dec22_silver_1",
"name": "Feeding the Cows",
"year": 2022,
"contest": "December",
"division": "Silver",
"tags": ["greedy", "binary search"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1232",
"statement": "There are N (1≤N≤100,000) pastures in a circle, and N cows. Each pasture grows either grass (G) or haybales (H). Cow i prefers food type t_i.\n\nA cow placed at pasture p will eat at the nearest pasture (clockwise) that has its preferred food type. Assign one cow to each pasture to minimize the maximum distance any cow travels.",
"sample_input": "5\nGGHHG\nGGHHG",
"sample_output": "1",
"sample_explanation": "Each cow can be placed at a pasture with matching food within distance 1."
},
{
"id": "jan23_gold_1",
"name": "Moo Network",
"year": 2023,
"contest": "January",
"division": "Gold",
"tags": ["graphs", "MST", "sorting"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=1249",
"statement": "Farmer John wants to connect N farms (1≤N≤200,000) with a minimum spanning tree. Each farm i is at position (x_i, y_i) with weight w_i.\n\nThe cost to connect farm i and farm j is |x_i - x_j| + |y_i - y_j| + |w_i - w_j| (Manhattan distance in 3D).\n\nFind the total cost of the MST.",
"sample_input": "4\n0 0 0\n1 0 0\n0 1 0\n0 0 1",
"sample_output": "3",
"sample_explanation": "Connect each outlier farm to origin with cost 1 each. MST total = 3."
},
{
"id": "dec18_bronze_1",
"name": "Mixing Milk",
"year": 2018,
"contest": "December",
"division": "Bronze",
"tags": ["simulation", "sorting"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=855",
"statement": "Farmer John has three buckets with capacities C1, C2, C3 (1≤C≤1,000,000,000) and initial amounts M1, M2, M3. He pours milk by repeatedly pouring from the first non-empty bucket into the first non-full bucket until equilibrium.\n\nSimulate 100 pour operations and output the amounts in each bucket.",
"sample_input": "10 3\n11 4\n12 5",
"sample_output": "10 3\n10 4\n12 5",
"sample_explanation": "After 100 pours the milk distributes and stabilizes."
},
{
"id": "feb19_silver_1",
"name": "Painting the Barn",
"year": 2019,
"contest": "February",
"division": "Silver",
"tags": ["DP", "2D prefix sums"],
"url": "http://usaco.org/index.php?page=viewproblem2&cpid=919",
"statement": "Farmer John wants to paint the barn wall (a 2D grid). N (1≤N≤1000) rectangular paint strokes are applied. Each stroke adds 1 to all cells in a rectangle.\n\nFind the total area of cells that have been painted exactly K (1≤K≤100,000,000) times.",
"sample_input": "4 2\n1 1 4 5\n4 2 5 4\n1 4 3 5\n3 1 5 5",
"sample_output": "8",
"sample_explanation": "Use 2D difference arrays to count paint layers, then tally cells with exactly K=2 layers."
}
]