跳到正文

个人记录

Osijek Competitive Programming Camp 2023 Day 8: Dilhan Salgado Contest Solutions

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

文章信息

发布
2024年2月2日
收录
2026年8月6日
更新
2026年11月6日
篇幅
约 9 分钟

版本

  1. v1当前

Problem A. And Xor Tree

Score: 5/45/4.

Since we only care about squaring, we can enumerate the contributions generated by the two bits 2i,2j2^i,2^j. Then you turn all the numbers into integers between [0,3][0,3]. Feel free to dp it.

Problem B. Balanced Permutations

Score: nan/nan\text{nan/nan}.

I can’t do it, and the official problem solution isn’t very complete.

It’s probably just that you build the Cartesian tree and find that it’s pretty average. I’m not too good at the specifics.

Problem C. Cyclic Shifts

Score: 7/97/9.

Good question!

You notice that k=nk=n doesn’t do much, and you note that k=n−1k=n-1 presumably means swapping two elements (if you treat the original sequence as a ring). Further, it is possible not to select consecutive positions so that several positions are exchanged at the same time, which would cost no more than 2n\dfrac 2n.

With parity sorting, we can use exactly nn operations to order the original sequence, where since we are treating the original sequence as a ring, we have to do exactly nn operations in order to get rid of the effect of the cyclic shifts.

Problem D. Distinct Subsequences

Score: 8/78/7.

Consider a subsequence automaton that matches greedily. The complexity is too high, how to optimise?

We split the original sequence into left and right L,RL,R segments of roughly equal length. After each solve segment, we return a few dp fi,j,kf_{i,j,k} indicating the number of matches that can’t be made in L/RL/R if the current length is ii, starts with j∈{0,1}j\in\{0,1\} and is followed by k∈{0,1,2}k\in\{0,1,2\}. (k=2k=2 is in fact the number of matches that can’t be made in L/RL/R. (k=2k=2 is actually all the legal numbers).

Consider how the information returned by L,RL,R can be used to calculate the information for L+RL+R. It is easy to see that for L+RL+R a legal string, there are two cases:

  • Case 11: the subsequence only passes through LL. Superimpose the LL information.
  • Case 22: the subsequence passes through RR, so the beginning of the subsequence on that side of RR cannot be added to LL.

This completes the transfer.

Using NTT convolutional optimisation this can be done O(nlog⁡2n)\mathcal O(n\log^2 n).

Problem E. Epidemic Escape

Score: 7/17/1.

For a critical point AA, make a AOAO plumb line ll. Then if the escape route touches ll the defence is reduced by one. The problem becomes the kkth straight line through which a ray passing through the origin passes.

Pull out the convex envelope that surrounds OO, then delete those edges and pull out the rest of the edges to make the convex envelope. Do this kk times. For the query, for kk convex packets, we add all 55 edges next to the ray to the preselected answer, and output the kkth smallest preselected answer.

Problem F. Five Letter Warning

Score: 6/66/6.

Enumerate the centre of the echo, assuming fi,A,Bf_{i,A,B} denotes the number of ABAB substrings in s[1,i]s[1,i]. gi,A,Bg_{i,A,B} denotes the number of ABAB substrings in s[i,n]s[i,n].

Then you find that the time, space complexity is O(nΣ2)\mathcal O(n\Sigma^2).

You find that space can be rolled off, and time can be done in time O(nΣ)\mathcal O(n\Sigma) for two adjacent f,gf,g with only O(Σ)\mathcal O(\Sigma) elements changed.

Problem G. Gridlandia

Score: 2/22/2.

Constructed Question. Will not.

Problem H. Holiday Regifting.

Rating: 7/87/8.

Actually, the order in which the elf hands out the gifts is not necessary. We can solve all the requirements of 1,2,…,n1,2,\dots,n in turn.

Maintain ansans, initially 11. Maintain the gifts aia_i received by each person at ansans time. Enumerate i=1,2,…,ni=1,2,\dots,n sequentially.

  • If when ci∣aic_i|a_i, then just push the gift to the back.
  • Otherwise, we need to double time, specifically, doubling cigcd⁡(ai,ci)\dfrac{c_i}{\gcd(a_i,c_i)} and then just doubling all the aia_i that follow.

Time complexity O(nm)\mathcal O(nm).

Problem I. Julienne the Deck

Scoring: 2/32/3.

If n≤2n\leq 2 the answer is nn, otherwise the answer is 2n2n.

Problem J. Knight’s Tour Redux

Score: 6/46/4.

Slap this plane flat and only care about the transformations on your rows and columns. You find that only n=2,3,4n=2,3,4 is unsolvable.

You find that n=7n=7 has a construction going from (1,1)(1,1) to (7,7)(7,7). You can then generalise the construction.

原文
存档评论1 条抓取于