· Olympiad in Informatics

Late 2018 · Yali Training Camp

I have finally made it to Yali Middle School in Changsha, which I had been looking forward to for so long. After arriving in Yali's computer lab I wasn't all that excited, because I had prepared myself before coming — yes, I'm just here along for the ride. Watching the gods around me all reading those incomprehensible WC2019 mock problems, it suddenly hit me that they're in their first year of high school too. Thinking back to my crushing defeat at NOIp 2018, my mood in the lab stayed steadily low. I wasn't really down in the dumps, or unmotivated as you might put it; I could just clearly see the gap between me and the gods. They started learning in middle school; I didn't. They have already written lots of problems; I haven't. Their school has just about the best coach in Jiangxi; we don't. I watched them having a lively discussion about some godlike stuff and thought: the liveliness is theirs, and I have nothing. I'm just a weakling, that's all.

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

· Olympiad in Informatics

POJ1167: [IOI 1994] The Buses — Solution

Just use a struct \(gap\) to maintain each time interval and search. See the comments for the details.

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

· Olympiad in Informatics

CCF NOIp 2009: Target Sudoku — Solution

It's really just an idiotic search problem, sped up with bitwise operations. You might want to read the article Speeding Up Sudoku with Bitwise Operations first, to learn how to use bitwise operations to handle an ordinary sudoku.

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

· Olympiad in Informatics

CH2601: Circuit Repair — Solution

We can think of the whole circuit system as an undirected graph: if going from point \(A(x_1,y_1)到B(x_2,y_2)\), the circuit in the cell along this path matches the direction, then we take the edge weight of this path to be \(0\); if it goes against the direction, the edge weight is \(1\). To make a reasonable optimization, we can use a deque, process edges of weight \(0\) first, and then just make sure each point is visited only once. The complexity is fairly low; just look at the code.

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

· Olympiad in Informatics

POJ3322: Bloxorz I — Solution

This problem is just a fairly typical BFS search problem. We can first precompute some arrays to help us make the moves. Use a struct to store the position of each step and the way the block is lying down, then put them into the queue to wait. Once you've got how the positions are stored figured out, this problem should be fairly clear. Here is the code:

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

· Olympiad in Informatics

POJ1011: Sticks — Solution & a Classic Pruning Example

The pruning techniques in this problem are very ingenious, and many of them can be put to good use when solving problems. I'll post the code first, and then we'll analyze it.

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

· Olympiad in Informatics

POJ3074: Sudoku — Solution

The method this problem uses is utterly godlike: it uses bitwise operations to decide whether each digit is chosen or not. First, let’s build a few helper arrays so that the values of the mapping arrays \(X,Y,Box\) are computed in advance, and then handle a few helper arrays for the bitwise operations. Since the approach is way too godlike to explain, just read the code.

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

· Olympiad in Informatics

BZOJ2288: Birthday Gift — Solution

Actually, this problem is just asking for the maximum sum of at most \(M\) (possibly mutually overlapping) subsequences of a sequence. We can merge all the consecutive positive numbers and negative numbers in the sequence together: positives merge with positives, negatives merge with negatives. Then I add all the positive numbers to the answer, put them into a min-heap keyed by their absolute values, and count them, while at the same time building a doubly linked list structure. After that, we can use \(cnt>m\) as the loop condition and keep taking elements out of the queue to process them.

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

· Olympiad in Informatics

P1801: Black Box — Solution

We can consider a godlike structure: the two-heap structure. Create a max-heap \(qmax\) and a min-heap \(qmin\). We first store the data in an array. Then, for a given query, we need to find, among the first \(u(i)\) numbers of the whole sequence, the \(i\)-th smallest number. At each query, we put the first \(u(i)\) numbers into the max-heap, and when the number of elements in the max-heap equals \(i\), we move the largest number in the max-heap (the heap top) into the min-heap. In the end, the max-heap holds \(i-1\) elements, and the \(i\)-th smallest number we are looking for must be at the top of the min-heap.

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

· Olympiad in Informatics

POJ2185: Milking Grid — Solution

The problem asks for the smallest submatrix that can tile the original matrix. We can solve this with the KMP approach. First we need to find the horizontal length of the periodic matrix, which we can handle with naive matching:

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