· Olympiad in Informatics

POJ1639: Picnic Planning — Solution

Have you done LCT before? (If you have, you can basically knock off this problem.)

Consider removing the root node first; this produces many connected components: for each connected component, compute its minimum spanning tree, then find the smallest edge connecting the whole component to the root node, and connect it.

After that, if there is still some usable degree left, we can consider using the root node’s remaining edges to update the whole minimum spanning tree. Specifically, we find an unused edge \((1, v)\), then we look at all the edges on \(1 \to v\) and find the one with the largest difference. If this difference is positive, add this edge and delete the previous one, and you will find the answer drops by this positive difference. Repeat this over and over to get the answer.

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

· Olympiad in Informatics

[2018 Quanzhou National Day Training Camp #1] - Problem-Solving Report

Stupid brute force works miracles, toying with people's feelings.

So it turns out your damn \(1e9\) complexity passes too? I'm honestly floored.

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

· Olympiad in Informatics

Educational Codeforces Round 72 Div. 2 Problem-Solving Report (CF1217)

This problem is pretty stupid.

Consider recording the position of the nearest previous \(1\) as \(nxt_i\). Then, clearly: if in the \(O(n \log n)\)-time scan we scan to an \([l, r]\) that is greater than the current interval, we consider whether there are enough zeros to the left of \(l\) to make up the length. And then you can happily get AC on this problem.

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

· Things

Summer Summary

I haven't written a summary in a long time. After the final exams went to pieces I was never really in the mood, so I didn't write June's summary either. The final exams were simply a nightmare: math and Chinese dragged my whole performance down. The strangest part was math, because the problems I thought I had all insta-solved all went GG in the end. So the only thing worth mentioning about the final exams is that combined science got back to a normal IQ level; everything else was all GG.

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

· Olympiad in Informatics

[Libre OJ] 6014 [24 Network Flow Problems] Longest k-Overlapping Interval Set — Solution

This problem is still pretty clever; I only got as far as max-cost max-flow, and after that I was stuck.

Here we present a solution with \(O(n)\) edges. Consider discretizing all the endpoints into \(2n\) consecutive points, then connecting each pair of adjacent endpoints \(i, i+1\) with an edge of infinite capacity and zero cost. Consider the left and right endpoints of each interval: connect the left endpoint to the right endpoint, with capacity \(1\) and cost equal to the length of the interval. Finally, connect the source to the left endpoint, and connect the sink to the right endpoint.

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

· Olympiad in Informatics

P4556: [Vani Has a Date] The Tail of the Rainy Day — Solution

This problem can be answered offline, and it is very likely some difference-on-trees kind of thing. But difference on trees can't maintain range information, so then I thought of maintaining it with a value segment tree. If we brute-force it by opening \(1e5\) segment trees to maintain this, it's GG, but we can allocate nodes dynamically, and then the segment tree for each node is roughly of size \(O(\log n)\), so the space becomes acceptable.

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

· Olympiad in Informatics

[Fortuna OJ] 4682 [GDOI2017 Mock 8.11] Biologist

The original solution author's approach to this problem is very clear. Let me lay it out.

First, think about what the answer means: it must be the total sum of the weights minus:

  • the sex-change costs
  • the sponsorship money we give up
  • the tea-drinking expenses

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

· Olympiad in Informatics

[Fortuna OJ] 4681 [GDOI2017 Mock] 8.11 Selection

In this problem, the upper bound on the value of any purchase plan is \(a_i \times k\), roughly on the order of \(1e5\). Consider a super brute force: let the state \(f[i][j][w]\) be whether it is feasible to have made \(i\) picks, with the last pick being coin type \(j\) and the current total being \(w\). Counting the value bound, this transition is roughly \(O(n^4)\), which only passes part of the points.

Consider transforming the state. We first subtract the minimum price from the prices of all items; then the remaining purchase plans take the form \(k*minVal + sum\). Then we let the state \(f[i][j]\) be the minimum number of picks where the last pick is item type \(i\) and the total reached is \(j\), and we just count the states whose number of picks is less than \(k\).

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

· Olympiad in Informatics

P4091: [HEOI2016/TJOI2016] Sum — Solution

Really fucking nasty.

The original formula looks like this:

\[f(n) = \sum_{i = 0}^n \sum_{j = 0}^i \begin{Bmatrix} i \\ j \end{Bmatrix} 2^j (j!)\]

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

· Olympiad in Informatics

BZOJ 4671: XOR Graph — Solution

We notice that directly counting a single connected component is really hard. At this point we can try inclusion–exclusion. We notice that the “at least” kind is especially easy to count: denote the answer for partitions into at least \(i\) connected components by \(g(i)\). \(g(i)\) is fairly easy to compute: we can use DFS to enumerate the component root of every vertex, then put the connectivity situation into a linear basis. If the insertion into the linear basis fails, the current situation cannot be represented, and this state fits the partition, so it is counted into a small answer \(tot\). In the end, the contribution to the answer is: \(2^{tot}\).

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