Skip to content

Commit d2b0cfc

Browse files
committed
2025-10-20 14:37:07: add hint/solution sections to festival
1 parent 7d6183e commit d2b0cfc

File tree

5 files changed

+57
-28
lines changed

5 files changed

+57
-28
lines changed

.obsidian/graph.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"collapse-filter": false,
3+
"search": "path:content/",
4+
"showTags": true,
5+
"showAttachments": false,
6+
"hideUnresolved": false,
7+
"showOrphans": true,
8+
"collapse-color-groups": true,
9+
"colorGroups": [],
10+
"collapse-display": true,
11+
"showArrow": false,
12+
"textFadeMultiplier": 0,
13+
"nodeSizeMultiplier": 1,
14+
"lineSizeMultiplier": 1,
15+
"collapse-forces": true,
16+
"centerStrength": 0.518713248970312,
17+
"repelStrength": 10,
18+
"linkStrength": 1,
19+
"linkDistance": 250,
20+
"scale": 1.7988388577202705,
21+
"close": true
22+
}

content/posts/festivals.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@ title: "IOI 2025: Festivals"
33
---
44
[Problem](https://qoj.ac/problem/13905)
55

6-
A natural starting point is to try to find a total ordering for the coupons. This way, we can easily solve the subproblem of checking whether a given subset of coupons is valid by sorting the coupons according to our total order, then simulating.
7-
8-
Define the break-even value of coupon $i$ as the unique number $F_i$ such that $F_i = (F_i - P_i) dot T_i$.
9-
If $T_i = 1$, we set $F_i = infinity$.
10-
11-
Then, we note that if there exists a total ordering, all coupons with the same break-even price should be considered equivalent. For instance, consider several coupons with the same break-even price of $0$: they will all then be of the form $X prime = X dot T_i$, and therefore will always compose into the transformation $X prime = X product T_i$, no matter how they are ordered. A similar argument holds for other values of $F_i$.
12-
13-
This motivates a comparator based on $F_i$, and
14-
we can actually show that it's always optimal to sort in increasing order of $F_i$. Consider two coupons $1$ and $2$ with $F_1 < F_2$, and a starting value of $X = F_1$:
15-
16-
- If we put 1 before 2, we effectively only apply 2 (since by definition, 1 leaves an input of $X = F_1$ unchanged).
17-
18-
- However, if we put 2 before 1,
19-
we first apply 2, which is guaranteed to decrease $X$ since $X = F_1 < F_2$,
20-
and then apply 1, which decreases $X$ again since now $X < F_1$.
21-
22-
Since the slope of the resultant composed coupon is always the same, showing that $1 < 2$ for a single value of $X$ is sufficient to show that $1 < 2$ holds for _all_ values of $X$.
23-
24-
Now, as long as there exists an $i$ with $F_i <= X$, we can always greedily include it in our subset,
25-
so, we now only need to solve the case where all $F_i > X$. We can also assume for now that all $T_i > 1$, since handling $T_i = 1$ is relatively simple.
26-
27-
Under these constraints, we see that the best case (that allows us to take the most coupons) is when all $F_i = X + 1$ and all $T_i = 2$. However, even in this best case, it turns out we can only take at most $log X$ coupons. To see this, we can again consider "shifting our coordinates" such that $F_i = 0$, like we did when proving that coupons with the same $F_i$ are equivalent. In these shifted coordinates, $X$ starts at $-1$ and becomes $-2^k$ after applying $k$ coupons.
28-
29-
This allows us to run a simple knapsack #dp in $cal(O) (n log n)$.
30-
31-
[Implementation](https://qoj.ac/submission/1417041)
6+
> [!info]- Hint
7+
> Try finding a total order for the coupons.
8+
9+
> [!note]- Solution
10+
> A natural starting point is to try to find a total order for the coupons. This way, we can easily solve the subproblem of checking whether a given subset of coupons is valid by sorting the coupons according to our total order, then simulating.
11+
>
12+
> Define the break-even value of coupon $i$ as the unique number $F_i$ such that $F_i = (F_i - P_i) dot T_i$.
13+
> If $T_i = 1$, we set $F_i = infinity$.
14+
>
15+
> Then, we note that if there exists a total ordering, all coupons with the same break-even price should be considered equivalent. For instance, consider several coupons with the same break-even price of $0$: they will all then be of the form $X prime = X dot T_i$, and therefore will always compose into the transformation $X prime = X product T_i$, no matter how they are ordered. A similar argument holds for other values of $F_i$.
16+
>
17+
> This motivates a comparator based on $F_i$, and
18+
> we can actually show that it's always optimal to sort in increasing order of $F_i$. Consider two coupons $1$ and $2$ with $F_1 < F_2$, and a starting value of $X = F_1$:
19+
>
20+
> - If we put 1 before 2, we effectively only apply 2 (since by definition, 1 leaves an input of $X = F_1$ unchanged).
21+
>
22+
> - However, if we put 2 before 1,
23+
> we first apply 2, which is guaranteed to decrease $X$ since $X = F_1 < F_2$,
24+
> and then apply 1, which decreases $X$ again since now $X < F_1$.
25+
>
26+
> Since the slope of the resultant composed coupon is always the same, showing that $1 < 2$ for a single value of $X$ is sufficient to show that $1 < 2$ holds for _all_ values of $X$.
27+
>
28+
> Now, as long as there exists an $i$ with $F_i <= X$, we can always greedily include it in our subset,
29+
> so, we now only need to solve the case where all $F_i > X$. We can also assume for now that all $T_i > 1$, since handling $T_i = 1$ is relatively simple.
30+
>
31+
> Under these constraints, we see that the best case (that allows us to take the most coupons) is when all $F_i = X + 1$ and all $T_i = 2$. However, even in this best case, it turns out we can only take at most $log X$ coupons. To see this, we can again consider "shifting our coordinates" such that $F_i = 0$, like we did when proving that coupons with the same $F_i$ are equivalent. In these shifted coordinates, $X$ starts at $-1$ and becomes $-2^k$ after applying $k$ coupons.
32+
>
33+
> This allows us to run a simple knapsack #dp in $cal(O) (n log n)$.
34+
>
35+
> [Implementation](https://qoj.ac/submission/1417041)

content/thoughts/frieren.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
title: Frieren
33
tags:
4-
- anime
5-
- tv
4+
- tv/anime
65
---
76
ideas
87
- humans v elves
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
22
title: "Demon Slayer: Infinity Castle"
3+
tags:
4+
- film/anime
35
---
46
I went into this movie without having ever watched the show, so the only background knowledge I had came from a 40-second introductory video. Nonetheless, I really enjoyed nearly every aspect of it: the visuals (of course), the fight scenes, the music, and of course, the flashbacks. I truly wasn't expecting Akaza's backstory to be so emotional (and the score was unbelievably good as well). All in all, I'm very excited for the next movie and who knows, I might even watch some of the show while waiting :)

content/thoughts/shortest-paths.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
title: Shortest Paths
3+
tags:
4+
- "#cs"
35
---
46
djikstra idea: find shortest path, then second shortest, then next shortest---guaranteed to work
57

0 commit comments

Comments
 (0)