The 2022 ICPC Polish Collegiate Programming Contest (AMPPZ 2022) Solutions

· · 个人记录

Note: The score x-y indicates the actual difficulty x and the quality index y.

Problem A. Aliases

Rating: 1-1.

You find that the a=b=0 is satisfied by the c roughly \log level. All we need to do is enumerate a+b\leq \log and throw the English part of each into the map.

Time complexity: \mathcal O(n\log^3n).

Problem B. Bars

Rating: 3-4.

It's easy to write the dp formula: f_i=\max_{j<i}(f_j+(i-j)\times(p_i+p_j)), and you think of that latter lump as the trapezoidal area, and then what you're actually f_n solving for is the convex packet area. A little maintenance of the convex packet is all that's needed.

Time complexity: \mathcal O(n).

Problem C. Ctrl+C Ctrl+V

Scoring: 1-1.

Every time you match \tt ania just change the \tt a right after it to a special character.

Time complexity: \mathcal O(|S|).

Problem D. Dazzling Mountain

Scoring: 2-2.

You take the de-enumeration d and number the leaves in dfs order, with consecutive leaf numbers that a node can cover. Get a line tree or something and you're done.

Time complexity: \mathcal O(n\log n).

Problem E. Euclidean Algorithm

Scoring: 5-8.

The following fractions are all rounded down.

Notice that x,y(x<y) satisfies if and only if x\equiv \gcd(x,y)\bmod (y-x), and try to enumerate g=\gcd(x,y), that is, counting Y-X|X-1 at 1\leq X<Y\leq m=\dfrac ng (which satisfies that this thing must have \gcd(X,Y)=1 ), which is actually \sum_{i=1}^{m-1} d(i)=\sum_{i=1}^{m-1}\dfrac{m-1}{i}, and this thing can be divided integrally into chunks \mathcal O(\sqrt m) to find out.

You find that m=\dfrac ng can divide chunks integrally, just by integrating chunk sets.

Time complexity: \mathcal O(Tn^{0.75}).

Problem F. Flower Garden

Rating: 7-9.

This thing is a lot like 2-sat, in that [a_i,b_i] with violets in it can launch [c_i,d_i] all violets. First the line tree optimizes a building graph, the classic set of shrinking points.

The problem is equivalent to, each scc will have a weight, the sum of the weights is 3n, choose a derived subgraph weights between [n,2n]. The approach is:

Time complexity: \mathcal O(q\log n+n).

Problem G. Great Chase

Score: 2-4.

We only need to consider how long Mad Dog will live and multiply by the time to find the distance.

The mad dog lives for exactly as long as it takes for the person behind the mad dog to first meet the person in front of him. Just bisect it directly.

Time complexity: \mathcal O(n\log V).

Problem H. Hyperloop

Score: 7-3.

Maintaining line trees with high precision is sufficient, much like the classic problem.

Time complexity: \mathcal O(n\log^2 n).

Problem I. Investors

Score: 4-3.

Interval inverse pairs satisfy quadratic inequality. Direct partition optimization.

Time complexity: \mathcal O(n^2\log n).

Problem J. Job for a Hobbit.

Score: 8-10.

First it is easy to find out that it is legal if and only if:\sum \dfrac{c_i}{k}\leq n+2, where it is rounded upwards and c_i is the number of occurrences of the i color.

We find that constructing each color in turn will take up empty space, so we consider constructing the "full" case first, and then push to the target sequence.

Specifically, we arrange the colors from left to right, top to bottom, and we get the target sequence goal, we just need to figure out how to reach the target sequence goal, the rest we can shift one color at a time to meet the construction.

At this point, the problem is converted to one where each point in the original table has a goal position, and the goal positions are only in the first n columns. This way we can construct one column at a time. We only need to construct the first column to construct all the subsequent columns at once.

Each time we have two empty columns, we move the empty columns to the top 1,2 positions. The task of 1 is to preserve the construction and the task of 2 is to assist in the construction. We consider moving each point to the 1 column one at a time from the bottom up.

Consider the current target point position at (x,y) and we consider moving to the top 1,2. First of all if x=3 it's already done. Specifically, move all of the part above (x,y) (including (x,y)) to the 2 column, then move the target to 1, and then move the ones on the 2 column back to 3.

This reveals that we only need to make x fewer each time, without changing the general shape of the elements on the columns.

We consider moving the empty column to x-1, then moving all the elements at the target point to x-1, then moving all the elements on the x-2 column to x-1, and then moving them to x if they can still be moved to x. It is easy to see that this way since x-2,x-1,x has no more than 2k elements in total, it is always possible to make x-2 empty, and then the empty column goes to x-2, with elements of x'=x-1, completing the generalization.

A small problem is that if (x,y) is at the bottom of the x column and the x column is full. At this point the target column must not be full, we can move the top element of all the columns collectively forward one place, the x-2 above the empty space, then we move the top element of x to x-2 can be the same as the above a practice. Note that the top elements should be panned back collectively after this is done.

Operation step: \mathcal O(n^2k^2).

Problem K. Kooky Tic-Tac-Toe

Score: 2-1.

Enumerate the last move, deleting this move the game cannot end. Then just assign it randomly.

Time complexity: \mathcal O(\text{poly}).

Problem L. Line Replacements

Rating: 4-5.

A sufficient condition for legality is that for points that can't be used as starting points, there are 2\max_{(u,v)\in E}w(u,v)\leq \sum_{(u,v)\in E}w(u,v), and the latter thing is even. Just delete from largest to smallest according to edge weights.

Time complexity: \mathcal O(n\log n).

Problem M. Minor Evil

Scoring: 3-5.

Considered from back to front, if a person is going to be used again in front of them keep them, otherwise just kill them off.

Time complexity: \mathcal O(n).