· Olympiad in Informatics

AtCoder Regular Contest 092 Problem-Solving Report

You can consider sorting first, then just handling it greedily, by brute force.

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

· Olympiad in Informatics

[LibreOJ] #2340. [WC2018] State Division — Solution

Fuck, it's this brute-force?

First, for every subgraph, we need to get its validity and its contribution to the answer. Once that's done, just use subset convolution.

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

· Olympiad in Informatics

[LibreOJ] #6682. Number Theory in a Dream — Solution

Actually, if you look at it a little, you'll find that when \([j|i][(j + k)|i]\) holds, \(k\) has no particular restriction, so it can be understood directly as choosing two divisors, and then it turns into:

\[\begin{aligned} & \sum_{i = 1}^n {\sigma_0(i) \choose 2} \\ =& \sum_{i = 1}^n \frac{\sigma_0^2(i) - \sigma_0(i)}{2}\end{aligned}\]

The latter \(\sum \sigma_0(x)\) can be handled directly with divisor-block decomposition, and the former just needs a min_25 sieve. We have \(f(p^k) = \prod (1 + c_i)^2\).

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

· Olympiad in Informatics

[QuestOJ] Grand Celebration — Solution

A shitty bitmask problem.

Once you see that degrees are at most \(10\), you know you need to bitmask the children's information. Consider building a neck array that stores, for each node in the subtree, the index of the node it reaches just below the current subtree root; then every time we jump upward we can adjust this array, and then the DP becomes fairly pleasant.

When handling the \(m\) requests, we pull out the corresponding neck values, mark them, and run the DP by the smaller index.

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

· Olympiad in Informatics

[Universal OJ] #308: [UNR #2] UOJ Rescue Plan — Solution

Seeing this tiny modulus, you know it must be a trick problem; there's no way it wants you to run it on a general graph (probably NPC).

First, with the colors unlabeled, let the number of ways that use \(i\) colors be \(f_i\). Then the answer is:

\[ans = \sum_{i = 1}^k f_i k^{\underline{i}}\]

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

· Olympiad in Informatics

[LibreOJ] #6060 [2017 Shandong Round 1 Training Camp Day 1 / SDWC2018 Day1] Set - Solution

A godlike problem.

Notice that \(x_1 \oplus x_2 = xorsum\), so we try to give as many bits of \(xorsum\) as possible to \(x_2\). If some bit of \(xorsum\) is \(1\), just give it straight to \(x_2\); if it is \(0\), there are two cases, \(0, 0\) and \(1, 1\). So when we build the linear basis, prioritizing the higher bits that are \(0\) makes the answer larger (think about the process of finding the maximum XOR sum with a linear basis: positions with greater weight are inserted first).

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

· Olympiad in Informatics

AtCoder Regular Contest 091 - Problem-Solving Report

The code for this round is all so short.

Stupid-easy problem; just do whatever.

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

· Olympiad in Informatics

[Universal OJ] #310. [UNR #2] Chocolate Before Dawn

Basically, this is taking the XOR convolution of the \((1 + 2x^{a_i})\) terms to get the number of ways to make \(0\). One idea is to run FWT many times, but that will definitely time out. Let's look at some properties.

Actually, the FWT transform is just:

\[b_i = \sum_{j} (-1)^{cnt(i \& j)} a_j\]

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

· Olympiad in Informatics

[LibreOJ] #2072 [JSOI2016] Unique Leaf - Solution

Use rerooting to compute the hash value of the tree's shape with every vertex as the root, then enumerate the leaves in B and just look each one up in the map.

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

· Olympiad in Informatics

Stirling Numbers

This is a post I've flaked on for three months, so today I'm writing it up properly once and for all. Both kinds of Stirling numbers help a lot with solving problems, in simplifying formulas as well as through their own combinatorial meaning.

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