Skip to content

Commit b0bbaf3

Browse files
committed
2 parents 5baf612 + 775a3bc commit b0bbaf3

File tree

9 files changed

+193
-197
lines changed

9 files changed

+193
-197
lines changed

.github/workflows/update-usaco.yml

+18-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@ jobs:
1313
with:
1414
repository: ${{ github.repository_owner }}/usaco-problems
1515
path: usaco-problems
16+
- name: Generate a token
17+
id: generate_token
18+
uses: actions/create-github-app-token@v1
19+
with:
20+
app-id: ${{ secrets.APP_ID }}
21+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
22+
owner: ${{ github.repository_owner }}
1623
- name: Build list of problem ids
1724
run: |
1825
git branch auto
1926
git checkout auto
2027
yarn
21-
yarn develop &
22-
sleep 20
23-
pkill -f 'yarn develop'
24-
ls
28+
yarn build
29+
echo 'ids.log tail:'
30+
cat -b ids.log | tail -n 10
2531
- name: Add new problems
2632
run: |
2733
npx ts-node --skipProject usaco-problems/add_problems ../ids.log ../content/extraProblems.json
@@ -30,7 +36,12 @@ jobs:
3036
git config --global user.email usaco-autofetch[bot]@users.noreply.github.com
3137
git commit -m 'problem auto-updates'
3238
git push -f origin auto
33-
gh pr close $(gh pr list --json number --jq '.[0].number' --author 'usaco-autofetch[bot]') || true
34-
gh pr create --title 'Problem auto-updates' -F usaco-problems/out/report.txt
39+
export pr_number=$(gh pr list --json number --jq '.[0].number')
40+
if [ -z "$pr_number" ]
41+
then
42+
gh pr create --title 'Problem auto-updates' -F usaco-problems/out/report.txt
43+
else
44+
gh pr edit $pr_number -F usaco-problems/out/report.txt
45+
fi
3546
env:
36-
GH_TOKEN: ${{ github.token }}
47+
GH_TOKEN: ${{ steps.generate_token.outputs.token }}

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
- id: check-yaml
88
- id: check-added-large-files
99
- repo: https://github.com/pre-commit/mirrors-prettier
10-
rev: v4.0.0-alpha.4
10+
rev: v4.0.0-alpha.8
1111
hooks:
1212
- id: prettier
1313
additional_dependencies:

content/3_Silver/Two_Pointers.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,13 @@ print(ans)
431431
<Quiz.Answer>
432432
The time complexity of a standard two pointers algorithm is $\mathcal{O}(N)$ when not considering any other operations on the array.
433433
<Quiz.Explanation>
434-
Incorrect. Assuming that both pointers move one step at a time and the array isn't sorted, both pointers would take a maximum of $N$ steps.
434+
Incorrect. Assuming that both pointers move one step at a time, both pointers would take a maximum of $N$ steps.
435435
</Quiz.Explanation>
436436
</Quiz.Answer>
437437
<Quiz.Answer>
438438
The space complexity of a standard two pointers algorithm is $\mathcal{O}(1)$ when not considering the space taken up by the array.
439439
<Quiz.Explanation>
440-
Incorrect. Assuming that both pointers move one step at a time and the array isn't sorted, there would be a constant space complexity.
440+
Incorrect. Assuming that both pointers move one step at a time, there would be a constant space complexity.
441441
</Quiz.Explanation>
442442
</Quiz.Answer>
443443
<Quiz.Answer correct>

content/extraProblems.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@
611611
"isStarred": false,
612612
"tags": ["Complete Search"],
613613
"solutionMetadata": {
614-
"kind": "USACO",
615-
"usacoId": "1180"
614+
"kind": "internal"
616615
}
617616
},
618617
{

port_problems.mjs

-45
This file was deleted.

solutions/bronze/usaco-1180.mdx

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
id: usaco-1180
3+
source: USACO Bronze 2022 January
4+
title: Non-Transitive Dice
5+
author: Nimeesh Sharma
6+
---
7+
8+
[Official Analysis (C++, Java, Python)](http://www.usaco.org/current/data/sol_prob2_bronze_jan22.html)
9+
10+
## Explanation
11+
12+
To begin with this problem, we must first understand what it means for three dice to be transitive.
13+
Dice are transitive when dice $A$ beats dice $B$, dice $B$ beats dice $C$, and dice $C$ beats dice $A$.
14+
Dice $A$ beats dice $B$ when there are more pairs $(x, y)$ where $x$ is a side of dice $A$ and $y$ is a side on dice $B$ where $x > y$ compared to when $y < x$.
15+
16+
Since each dice has four sides and there are ten possible values for each side, there are $10^4 = 10,000$ possible dice to test.
17+
This number is small enough that we can test every possible dice for non-transitivity via brute force.
18+
19+
## Implementation
20+
21+
**Time Complexity**: $\mathcal{O}(1)$ for each test case
22+
23+
<LanguageSection>
24+
<CPPSection>
25+
26+
```cpp
27+
#include <bits/stdc++.h>
28+
using namespace std;
29+
30+
using Die = array<int, 4>;
31+
32+
/** @return whether dice A beats dice B */
33+
bool beats(const Die &a, const Die &b) {
34+
int wins = 0, losses = 0;
35+
for (int i = 0; i < 4; i++) {
36+
for (int j = 0; j < 4; j++) {
37+
if (a[i] > b[j]) { wins++; }
38+
if (a[i] < b[j]) { losses; }
39+
}
40+
}
41+
return wins > losses;
42+
}
43+
44+
int main() {
45+
int test_num;
46+
cin >> test_num;
47+
for (int i = 0; i < test_num; i++) {
48+
Die A, B;
49+
string ans = "no";
50+
for (int j = 0; j < 4; j++) { cin >> A[j]; }
51+
for (int j = 0; j < 4; j++) { cin >> B[j]; }
52+
53+
// Iterate through all 10,000 possibilities
54+
// and check if there is a possible transitive dice
55+
for (int a = 1; a <= 10; a++) {
56+
for (int b = 1; b <= 10; b++) {
57+
for (int c = 1; c <= 10; c++) {
58+
for (int d = 1; d <= 10; d++) {
59+
Die C{a, b, c, d};
60+
if (beats(A, B) && beats(B, C) && beats(C, A)) {
61+
ans = "yes";
62+
}
63+
if (beats(B, A) && beats(C, B) && beats(A, C)) {
64+
ans = "yes";
65+
}
66+
}
67+
}
68+
}
69+
}
70+
71+
cout << ans << "\n";
72+
}
73+
}
74+
```
75+
76+
</CPPSection>
77+
<JavaSection>
78+
79+
```java
80+
import java.io.BufferedReader;
81+
import java.io.IOException;
82+
import java.io.InputStreamReader;
83+
import java.util.StringTokenizer;
84+
85+
public class NonTransitiveDice {
86+
/** @return whether dice A beats dice B */
87+
static boolean beats(int[] dice1, int[] dice2) {
88+
int diff = 0;
89+
for (int x : dice1) {
90+
for (int y : dice2) { diff += Integer.signum(x - y); }
91+
}
92+
return diff > 0;
93+
}
94+
95+
public static void main(String[] args) throws IOException {
96+
BufferedReader in =
97+
new BufferedReader(new InputStreamReader(System.in));
98+
StringBuilder out = new StringBuilder();
99+
for (int n = Integer.parseInt(in.readLine()); n > 0; n--) {
100+
StringTokenizer tokenizer = new StringTokenizer(in.readLine());
101+
int[] diceA = new int[4];
102+
for (int j = 0; j < 4; j++) {
103+
diceA[j] = Integer.parseInt(tokenizer.nextToken());
104+
}
105+
int[] diceB = new int[4];
106+
for (int j = 0; j < 4; j++) {
107+
diceB[j] = Integer.parseInt(tokenizer.nextToken());
108+
}
109+
110+
String ans = "no";
111+
// Iterate through all 10,000 possibilities
112+
// and check if there is a possible transitive dice
113+
for (int a = 1; a <= 10; a++) {
114+
for (int b = 1; b <= 10; b++) {
115+
for (int c = 1; c <= 10; c++) {
116+
for (int d = 1; d <= 10; d++) {
117+
int[] diceC = {a, b, c, d};
118+
if (beats(diceA, diceB) && beats(diceB, diceC) &&
119+
beats(diceC, diceA)) {
120+
ans = "yes";
121+
}
122+
if (beats(diceB, diceA) && beats(diceA, diceC) &&
123+
beats(diceC, diceB)) {
124+
ans = "yes";
125+
}
126+
}
127+
}
128+
}
129+
}
130+
131+
out.append(ans).append('\n');
132+
}
133+
134+
System.out.print(out);
135+
}
136+
}
137+
```
138+
139+
</JavaSection>
140+
<PySection>
141+
142+
```py
143+
def win(a: list[int], b: list[int]) -> bool:
144+
""":return: whether dice A beats dice B."""
145+
return sum([x > y for x in a for y in b]) > sum([y > x for x in a for y in b])
146+
147+
148+
for _ in range(int(input)):
149+
l = [int(x) for x in input().split()]
150+
a_die = l[0:4]
151+
b_die = l[4:8]
152+
153+
ans = "no"
154+
# Iterate through all 10,000 possibilities and check if there is a possible transitive dice
155+
for a in range(1, 11):
156+
for b in range(1, 11):
157+
for c in range(1, 11):
158+
for d in range(1, 11):
159+
c_die = [a, b, c, d]
160+
if win(a_die, b_die) and win(b_die, c_die) and win(c_die, a_die):
161+
ans = "yes"
162+
if win(b_die, a_die) and win(c_die, b_die) and win(a_die, c_die):
163+
ans = "yes"
164+
165+
print(ans)
166+
```
167+
168+
</PySection>
169+
</LanguageSection>

src/components/markdown/ProblemsList/DivisionList/div_to_probs.json

+2-26
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,7 @@
193193
["1304", "2023 February", "Moo Route II"],
194194
["1326", "2023 US Open", "Milk Sum"],
195195
["1327", "2023 US Open", "Field Day"],
196-
["1328", "2023 US Open", "Pareidolia"],
197-
["[object Undefined]", "2023 US Open", "Milk Sum"],
198-
["[object Undefined]", "2023 US Open", "Field Day"],
199-
["[object Undefined]", "2023 US Open", "Pareidolia"],
200-
["[object Undefined]", "2023 US Open", "Milk Sum"],
201-
["[object Undefined]", "2023 US Open", "Field Day"],
202-
["[object Undefined]", "2023 US Open", "Pareidolia"],
203-
["[object Undefined]", "2023 US Open", "Milk Sum"],
204-
["[object Undefined]", "2023 US Open", "Field Day"],
205-
["[object Undefined]", "2023 US Open", "Pareidolia"],
206-
["[object Undefined]", "2023 US Open", "Milk Sum"],
207-
["[object Undefined]", "2023 US Open", "Field Day"],
208-
["[object Undefined]", "2023 US Open", "Pareidolia"]
196+
["1328", "2023 US Open", "Pareidolia"]
209197
],
210198
"Gold": [
211199
["573", "2015 December", "High Card Low Card (Gold)"],
@@ -302,19 +290,7 @@
302290
["1307", "2023 February", "Piling Papers"],
303291
["1329", "2023 US Open", "Custodial Cleanup"],
304292
["1330", "2023 US Open", "Pareidolia"],
305-
["1331", "2023 US Open", "Tree Merging"],
306-
["[object Undefined]", "2023 US Open", "Custodial Cleanup"],
307-
["[object Undefined]", "2023 US Open", "Pareidolia"],
308-
["[object Undefined]", "2023 US Open", "Tree Merging"],
309-
["[object Undefined]", "2023 US Open", "Custodial Cleanup"],
310-
["[object Undefined]", "2023 US Open", "Pareidolia"],
311-
["[object Undefined]", "2023 US Open", "Tree Merging"],
312-
["[object Undefined]", "2023 US Open", "Custodial Cleanup"],
313-
["[object Undefined]", "2023 US Open", "Pareidolia"],
314-
["[object Undefined]", "2023 US Open", "Tree Merging"],
315-
["[object Undefined]", "2023 US Open", "Custodial Cleanup"],
316-
["[object Undefined]", "2023 US Open", "Pareidolia"],
317-
["[object Undefined]", "2023 US Open", "Tree Merging"]
293+
["1331", "2023 US Open", "Tree Merging"]
318294
],
319295
"Platinum": [
320296
["576", "2015 December", "Max Flow"],

usaco_info.json

-3
This file was deleted.

0 commit comments

Comments
 (0)