You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/festivals.md
+30-26Lines changed: 30 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,29 +3,33 @@ title: "IOI 2025: Festivals"
3
3
---
4
4
[Problem](https://qoj.ac/problem/13905)
5
5
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)$.
> 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)$.
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 :)
0 commit comments