· Olympiad in Informatics

[Codeforces 666C] Codeword — Solution

That’s it? A brain-dead problem.

I feel like I've done this before. Clearly the answer has nothing to do with the characters. We need to fix the leftmost subsequence, then enumerate the last position, and we get the result (subsequence \(T\), target string length \(n\)):

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

BZOJ2138: stone — Solution

First, we can see that this thing can be viewed as a bipartite graph model, except that now we need to compute its maximum matching quickly. Then, by Hall's theorem, if for any left vertex \(x \in U, |U| < |V|\), the set \(M\) of right endpoints it connects to satisfies \(|M| > |U|\), then a perfect matching exists.

This problem has a property: no interval contains another. So satisfying Hall's theorem actually just requires that for every segment, \(\sum_{i = l}^r b_i \leq \sum_{i = L[l]}^{R[r]} a_i\) holds, where \(b_i\) means that for the \(i\)-th segment we take \(b_i\) stones.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

[AtCoder Regular Contest 090F] Number of Digits — Solution

This problem is pretty interesting.

First there's a brute force: for \(l\) within \(10^7\) you can just do two-pointers; if it's above \(10^7\), you notice that \(f(r) - f(l) \leq 1\). Then we can consider enumerating the length of this contiguous segment, \(L = x + y\), where \(x\) is the part with \(i\) \(0\)s and \(y\) is the part with \(i + 1\) \(0\)s. There's an equation: \(x \times i + y \times (i + 1) = (x + y)i + y = Li + y = S\). So when enumerating \(L\), if \(S \bmod L \equiv 0\), that means \(y = 0\), and you count the left endpoints within \(10^i\) (it's really just subtracting an extra \(L - 1\)). If \(S \bmod L \neq 0\), that means \(x, y\) are determined, so you just ++.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

AtCoder Grand Contest 044 - Problem-Solving Report

A DP. Consider constructing it in reverse: from \(0\) to \(X\). The process will surely end up as adding and subtracting a bit first, then dividing, and so on and so forth.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

[QuestOJ] Product — Solution

Just grind through the algebra and you're done:

\[\begin{aligned} g(n) &= \sum_{i = 1}^n \frac{n}{\gcd(i, n)} = n \sum_{d|n} \frac{1}{d} \sum_{i = 1}^n [\gcd(n, i) = d] \\ &= n \sum_{d|n} \frac{1}{d} \sum_{i = 1}^{\frac{n}{d}} [\gcd(\frac{n}{d}, i) = 1] = \sum_{d|n} \frac{n}{d} \varphi(\frac{n}{d}) = \sum_{d|n} d \varphi(d) \\ &= \sum_{d|n} d^2 \prod_{p_i} (1 - \frac{1}{p_i}) = \prod_{p_i} (1 + \sum_{g = 1}^{e_i} p_i^{2g} (1 - \frac{1}{p_i}) ) \\ &= \prod_{p_i} (1 + \sum_{g = 1}^{e_i} p_i^{2g} - \sum_{g = 1}^{e_i} p_i^{2g - 1}) = \prod_{p_i} (1 + \sum_{g = 1}^{e_i} p_i^{2g} - \frac{ \sum_{g = 1}^{e_i} p_i^{2g} }{p_i} ) \\ &= \prod_{p_i} (1 + (1 - \frac{1}{p_i}) (\sum_{g = 1}^{e_i} p_i^{2g}) ) = \prod_{p_i} (1 + (1 - \frac{1}{p_i}) \frac{p_i^2 (1 - p_i^{2e_i})}{1 - p_i^2}) \\ &= \prod_{p_i} (1 + \frac{(p_i - 1)}{p_i} \frac{p_i^2 (1 - p_i^{2e_i})}{(1 - p_i)(1 + p_i)} ) \\ &= \prod_{p_i} (1 - \frac{p_i (1 - p_i^{2e_i})}{1 + p_i} ) = \prod_{p_i} \frac{1 + p_i - p_i + p_i^{2e_i + 1}}{1 + p_i} \\ &= \prod_{p_i} \frac{p_i^{2e_i + 1} + 1}{1 + p_i} \end{aligned}\]

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

[JOISC 2017 Day 2] Arranging Tickets — Solution

Holy crap, this one is seriously hard. I spent a whole afternoon staring blankly at pty's solution.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

AtCoder Grand Contest 045 - Problem-Solving Report

Feels kind of idiotic.

For 0, we just need the final answer to be 0. So we maintain things from back to front: maintain the linear basis formed by combining the values at the \(0\) positions, and each time we reach a \(1\) position, just query it in there. If it isn't found, then for \(1\), the later \(0\)s aren't enough to cancel that operation, so we can declare \(1\) the winner, and vice versa.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

AtCoder Grand Contest 046 - Problem-Solving Report

A stupid problem, no explanation needed.

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Things

JXOI 2020 Diary

As for a person's fate, of course it depends on one's own struggle, but one must also take into account the journey of history.

The Elder

Continue reading →Chinese original · English translation by Claude Opus 5.5

· Olympiad in Informatics

LibreOJ#6181: A Certain Standard-Trick Summation Problem — Solution

What a good problem.

Notice that \(f(x)\) brings no benefit for any number with a square factor, so we only consider \(f(x) = \prod_{i = 1}^m p_i\). Then it is easy to see that \(f(x) = \prod_{r = 0}^m (-1)^{2^{(r - 1)}}\), so:

\[f(x) = \begin{cases} -1, x \in primes or x = 1 \\ 1, otherwise \end{cases}\]

Continue reading →Chinese original · English translation by Claude Opus 5.5