跳到正文

个人记录

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

Otomachi_Una_约 13 分钟
原文
文章信息与版本

文章信息

发布
2024年1月15日
收录
2026年6月29日
更新
2026年11月6日
篇幅
约 13 分钟

版本

  1. v1当前

Note: The score x−yx-y indicates the actual difficulty xx and the quality index yy.

Problem A. Aliases

Rating: 1−11-1.

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

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

Problem B. Bars

Rating: 3−43-4.

It’s easy to write the dp formula: fi=max⁡j<i(fj+(i−j)×(pi+pj))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 fnf_n solving for is the convex packet area. A little maintenance of the convex packet is all that’s needed.

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

Problem C. Ctrl+C Ctrl+V

Scoring: 1−11-1.

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

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

Problem D. Dazzling Mountain

Scoring: 2−22-2.

You take the de-enumeration dd 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: O(nlog⁡n)\mathcal O(n\log n).

Problem E. Euclidean Algorithm

Scoring: 5−85-8.

The following fractions are all rounded down.

Notice that x,y(x<y)x,y(x<y) satisfies if and only if x≡gcd⁡(x,y) mod (y−x)x\equiv \gcd(x,y)\bmod (y-x), and try to enumerate g=gcd⁡(x,y)g=\gcd(x,y), that is, counting Y−X∣X−1Y-X|X-1 at 1≤X<Y≤m=ng1\leq X<Y\leq m=\dfrac ng (which satisfies that this thing must have gcd⁡(X,Y)=1\gcd(X,Y)=1 ), which is actually ∑i=1m−1d(i)=∑i=1m−1m−1i\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 O(m)\mathcal O(\sqrt m) to find out.

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

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

Problem F. Flower Garden

Rating: 7−97-9.

This thing is a lot like 2-sat, in that [ai,bi][a_i,b_i] with violets in it can launch [ci,di][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 3n3n, choose a derived subgraph weights between [n,2n][n,2n]. The approach is:

  • If you don’t pick a point with weight ≥n\geq n, then greedily pick surely one of the moments will be in [n,2n][n,2n]. A direct topological order is sufficient.
  • If we pick, we just need to minimize the weights and get the derived subgraph containing this point directly, there will be no more than 33 points of this kind.

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

Problem G. Great Chase

Score: 2−42-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: O(nlog⁡V)\mathcal O(n\log V).

Problem H. Hyperloop

Score: 7−37-3.

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

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

Problem I. Investors

Score: 4−34-3.

Interval inverse pairs satisfy quadratic inequality. Direct partition optimization.

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

Problem J. Job for a Hobbit.

Score: 8−108-10.

First it is easy to find out that it is legal if and only if:∑cik≤n+2\sum \dfrac{c_i}{k}\leq n+2, where it is rounded upwards and cic_i is the number of occurrences of the ii 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 goalgoal, we just need to figure out how to reach the target sequence goalgoal, 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 nn 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,21,2 positions. The task of 11 is to preserve the construction and the task of 22 is to assist in the construction. We consider moving each point to the 11 column one at a time from the bottom up.

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

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

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

A small problem is that if (x,y)(x,y) is at the bottom of the xx column and the xx 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−2x-2 above the empty space, then we move the top element of xx to x−2x-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: O(n2k2)\mathcal O(n^2k^2).

Problem K. Kooky Tic-Tac-Toe

Score: 2−12-1.

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

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

Problem L. Line Replacements

Rating: 4−54-5.

A sufficient condition for legality is that for points that can’t be used as starting points, there are 2max⁡(u,v)∈Ew(u,v)≤∑(u,v)∈Ew(u,v)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: O(nlog⁡n)\mathcal O(n\log n).

Problem M. Minor Evil

Scoring: 3−53-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: O(n)\mathcal O(n).

原文
存档评论1 条抓取于