· Olympiad in Informatics

P4501: [ZJOI2018] Fat — Solution

It's fairly obvious that this is an interval-expansion problem, expanding monotonically toward both sides.

A normal brute force could do the expansion in \(n^2\), but this problem clearly has monotonicity, so we can try binary search to optimize away one factor of \(n\). Binary search for a range, then use a sparse table or a segment tree or something like that to query the farthest distance within the region, and then we can check.

The code is a bit long and a bit complicated.

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

· Olympiad in Informatics

AtCoder Regular Contest 094 - Problem-Solving Report

Honestly, this is absolutely the trashiest ARC set I’ve ever done, bar none.

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

· Olympiad in Informatics

P5330: [SNOI2019] Number Theory — Solution

Going back over a problem I did a year ago, it really does feel easy now.

Consider writing it as \(d' \in A, d = d' + xP\), then count how many \(x\) make \(d\) land in \(B\). Brute force just enumerates directly. To optimize the brute force, we notice that there must be a cycle here, of length \(\text{lcm}(P, Q)\), which allows a slight optimization.

Let's think of this modulo \(Q\) as a circular strip, then, for starting position \(start_pos\), mark the \(d \in B\) on this paper strip and take prefix sums. To make it easy to tell the order in which prefix sums are added and subtracted, we also need to mark ranks.

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

· Olympiad in Informatics

P5292: [HNOI2019] Campus Tour — Solution

There is a fairly obvious brute-force algorithm: consider the two cases of odd and even length, and expanding through same-colored vertices with BFS does the job. But the complexity is high: the BFS effectively takes \(\Theta(n^2 + m^2)\) time.

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

· Olympiad in Informatics

P4593: [TJOI2018] Textbook Defile — Solution

This problem is a real pain to read, and once you get through it you find it is just a Stirling-number stupid-easy problem.

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

· Olympiad in Informatics

P4493: [HAOI2018] Substring Covering — Solution

Really just a two-in-one?

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

· Olympiad in Informatics

BZOJ3162: Fishing Alone in the Cold River Snow — Solution

When I first saw this problem I was completely lost... After looking at it carefully I could roughly figure it out: fix a root, then do a DP to get the counts, then distribute the counts among subtrees of the same shape. (But I couldn't write it.)

Concretely, the way to turn it into a rooted tree is to use the centroid as the root (if there are two centroids, add a virtual root), and after each DFS, sort by hash value, then do the transitions group by group.

When transitioning, you can label each case, then use the combinatorial meaning of prefixes to do the transition. Specifically: \(dp[i] = \sum_{uniqueType \in subtree} {dp[uniqueType] + |subtree| - 1 \choose |subtree|}\).

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

· Olympiad in Informatics

P3547: [POI2013] CEN-Price List — Solution

Consider three forms of shortest path: \(A \times dist, \lfloor \frac{dist}{2} \rfloor B + (dist \bmod 2) A, kB\). The first two just take one BFS. The third has a special requirement on the path: there must be no edge outside the edge set that forms a triangle with some two edges of the path.

Speaking of triangles, we can imitate that square-root method: mark first, then enumerate the middle edge. However, here we can't split the edges into one-way edges, so doing the square-root method directly is bogus.

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

· Olympiad in Informatics

[Fortuna OJ] May 6 Provincial Team Selection Group A - Problem-Solving Report

A pattern-spotting problem. As long as you can spot the property that the range of a valid sequence is at most \(1\), you can just compute it. Directly:

\[ans = 2 - n + \sum_{i = 1}^{n - 1} 2^{\gcd(i, n)}\]

Then this can obviously be optimized with number-theoretic functions, the way some Polya problems do it, and that's it.

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

· Olympiad in Informatics

Gaussian Elimination

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