Because I was coming to Yali High School to get beaten up, I came to the city of Changsha. My parents' generation often brings this city up and compares it with Nanchang: a more developed economy, a bigger city, more modern rail transit (it even has maglev), and even with all that, the average housing price is quite a bit lower than Nanchang's. So I never had any clear picture of Changsha; all I had was my mom saying that her one-day trip to Changsha left her with “the impression that the food is really good”.
Continue reading →Chinese original · English translation by Claude Opus 5.5
It's easy to come up with the state \(dp[i][j][k]\), the minimum time for the first \(i\) people with \(j\) minutes of queueing in queue 1 and \(k\) minutes in queue 2. Then you notice that the \(k\) dimension can be eliminated outright, since \(k=sum[i]-j\). So once the linear dependency is eliminated, the equation becomes really refreshingly clean:
Continue reading →Chinese original · English translation by Claude Opus 5.5
At first I wrote pure brute force for this problem, and it got stuck and failed on test 6. Before reading the solution I already had a feeling that this had something to do with math. Let me roughly explain the main method first: while reading in the numbers, use the arrays \(dp2[][]和dp5[][]\) to record how many factors \(2\) and how many factors \(5\) the number contains; then the number of trailing \(0\)s is \(min\{numOf(2),numOf(5)\}\). Then we can process them separately: first process the \(dp2[][]\) array and record the path array \(f2[][]\), and after that process \(dp2[][]和f5[][]\). When computing the answer, we only need to compare \(dp2[n][n]和dp5[n][n]\) and backtrack through \(f2[][]或f5[][]\).
Continue reading →Chinese original · English translation by Claude Opus 5.5
Obviously, this is a dynamic programming problem. The equation for this linear DP is extremely hard to derive, because if you derive it the normal way, you always have to consider the states before a state in order to do the DP. However, there is a refreshingly unconventional way to approach this problem.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem is a bitmask DP problem (see the constraints). We compress whether each pig is dead or alive into the state, and the whole program counts from \(0\). We can derive the following equations: \(f[stat|(1<<i)] = min(f[stat|(1<<i)], f[stat] + 1)\) and \(f[stat|dotset[i][j]] = min(f[stat|dotset[i][j]],f[stat]+1)\), where dotset is the set of points on the parabola passing through points \(i,j\). This algorithm is \(O(Tn^2 2^n)\), which is not good enough. We can use a method to turn \(n^2\) into \(n\). We can precompute, for every state, the index of the first pig still alive, and then we only need to transition on this one pig: since the later pigs will all be handled anyway, we can drop a dimension directly.
Continue reading →Chinese original · English translation by Claude Opus 5.5
First use Floyed to compute the initial shortest paths, then enumerate two points that are not in the same connected component, connect them with an edge and update the current shortest paths, and then use DFS to find the longest chain. My garbage approach to this problem can't get AC without \(O2\), and its time complexity is \(O(n^4)\). (This might be the slowest code I've ever written)
Continue reading →Chinese original · English translation by Claude Opus 5.5
This is a rather nice counting DP problem. At first glance I thought it was bitmask DP, then found the constraints were too large, so I had to rethink it (that is, read the solutions). We can write out the state format:
Continue reading →Chinese original · English translation by Claude Opus 5.5
I'm about to start learning some math stuff lately, and as a basic problem this one couldn't be better. First, what this problem asks is to factorize the factorial \(N!=1*2*3*\dots *N\) into prime factors. We can first find the primes in the range \([1,N]\), and then find the exponents of the prime factors in this expression.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem is so nasty... I originally thought I could just write a DSU and AC it, but it turns out it needs knapsack DP too. Let's go through it piece by piece.
Continue reading →Chinese original · English translation by Claude Opus 5.5