· Olympiad in Informatics

[Fortuna OJ] Aug 21 - Group A Problem-Solving Report

Consider a super brute force: define the state \(dp[k][i][j]\) as the answer after walking \(k\) steps and ending up at \((i, j)\):

\[dp[k][i][j] = mp[i][j] + \max \begin{cases} dp[k - 1][i - 1][j] \\ dp[k - 1][i + 1][j] \\ dp[k - 1][i][j + 1] \\ dp[k - 1][i][j - 1] \end{cases}\]

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

· Olympiad in Informatics

[Fortuna OJ] 4606 - Sequence / HEOI 2016 Sequence

Since I am weak at divide and conquer, I came to grind divide-and-conquer problems.

First, think about the 50-point \(O(n^2)\) approach. Record each position's original value, its maximum value after changes, and its minimum value after changes. Then you find that a position \(i\) contributes to a later position \(j\) if and only if:

\[\begin{gathered}a_i < minVal_j \ (1) \\ maxVal_i < a_j \ (2) \end{gathered}\]

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

· Olympiad in Informatics

[Fortuna OJ] Aug 18th - Group A Problem-Solving Report

This problem was truly suffocating, and it also taught me that going on QQ during a contest is a very bad habit.

The 60-point solution to this problem is extremely obvious: group items of the same volume into one item, whose value is the largest value among that volume. This squeezes the number of items down to under 100.

But this can't get the full score, and the capacity for the full score is enormous, so the usual DP optimizations won't work. After doing the compression above, we can consider some greedy optimization. Next I'll introduce this greedy strategy in detail:

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

· Olympiad in Informatics

A Class of LCT Problems

LCT (Link Cut Tree) is a flexible data structure for maintaining tree paths. Unlike a segment tree, an LCT usually uses Splay, a very elegant and flexible data structure, to maintain the tree paths. Because an LCT supports adding and deleting edges dynamically, many problems can be solved by breaking through some of their restrictions.

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

· Olympiad in Informatics

[Fortuna OJ] Aug 13th - Group A Problem-Solving Report

So hard.

Simply put, the problem asks: given the condition \(\{x_i \mod m \in [1, m - 1]\}\), count the \(k\)-tuples that meet it. We can first take every \(x_i\) modulo \(m\), then let \(A = \sum_{i = 1}^k (x_i \mod m)\) (note: \(A\) is not taken modulo as a whole, it is just the sum of the individual remainders). We know that \(A \mod m = n \mod m\), and the upper bound of \(A\) is \(A = k(m - 1)\) (the upper bound of each term).

After this setup, the problem can be turned into: for each distinct \(A\), with \(A \mod m = n \mod m\) and \(A = \sum_{i = 1}^k (x_i \mod m), \forall i, x_i \in [1, m - 1]\) holding, how many ways there are to form the \(k\)-tuples. First, we can enumerate each \(A\) to narrow down the problem. Based on the conditions \(A\) satisfies, we can iterate over \(i\) like this to get every \(A\):

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

· Olympiad in Informatics

[Fortuna OJ] Aug 12th - Group A Problem-Solving Report

This problem is pretty good. It showed me that segment trees can pull off moves like this.

Consider a segment tree that maintains, for a range, the shortest paths from the row entrances to the row exits; the way it is maintained is, roughly, a lot like Floyd. There’s not much to say, just read the code.

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

· Olympiad in Informatics

[Fortuna OJ] Aug 10th - Group A Problem-Solving Report

For this problem, the quadratic-function brute force is worth 60 points; the intended solution comes from a paper.

This problem mainly uses a conclusion, and applies an idea from the Euclidean algorithm to simplify the problem. First, we adjust the vectors to the same direction, and make \(|\vec{a}| < |\vec{b}|\), and then we derive a conclusion:

Conclusion For \(\vec{a}, \vec{b}\), if \(<\vec{a}, \vec{b}> \geq \frac{\pi}{3}\), then the answer is \(min\{|\vec{a}|, |\vec{b}|\}\).

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

· Olympiad in Informatics

[Fortuna OJ] Aug 9th - Group A Problem-Solving Report

It's really just walking along the walls, and then all the messy stuff can be handled with Djisktra.

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

· Olympiad in Informatics

[Fortuna OJ] Aug 7th - Group A Problem-Solving Report

This problem's formula is the same as the one in an F problem on Codeforces, which made me think it was BSGS or some such thing, but in the end it turned out to really be a matrix multiplication problem.

Consider that any answer is made up of a product of powers of \(\{f_n\}\). Since \(k\) is small, we can consider computing the exponent of each \(f\), and then we can use fast exponentiation to compute these things.

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

· Olympiad in Informatics

P3211: [HNOI2011] XOR Sum Path — Solution

First, in this problem probability and expectation are computed separately, and the DP is really a DP over probabilities. Consider splitting by bits: let \(dp_b [u]\) be the probability that, going from \(u \to n\), bit \(b\) is \(1\). Then clearly:

\[dp_b[u] = \frac{1}{deg[u]}( \sum_{weight(u, v) !\& b} dp_b[v] \sum_{weight(u, v) \& b} (1 - dp_b[v]) )\]

Here \((1 - dp_b[v])\) is the probability that \(v\) is \(0\), and once the elimination is done the final answer is \(\sum_{i = 1} ans[i] 2^i\).

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