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

· · 个人记录

Problem A. And Xor Tree

Score: 5/4.

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

Problem B. Balanced Permutations

Score: \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/9.

Good question!

You notice that k=n doesn't do much, and you note that k=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 \dfrac 2n.

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

Problem D. Distinct Subsequences

Score: 8/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,R segments of roughly equal length. After each solve segment, we return a few dp f_{i,j,k} indicating the number of matches that can't be made in L/R if the current length is i, starts with j\in\{0,1\} and is followed by k\in\{0,1,2\}. (k=2 is in fact the number of matches that can't be made in L/R. (k=2 is actually all the legal numbers).

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

This completes the transfer.

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

Problem E. Epidemic Escape

Score: 7/1.

For a critical point A, make a AO plumb line l. Then if the escape route touches l the defence is reduced by one. The problem becomes the kth straight line through which a ray passing through the origin passes.

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

Problem F. Five Letter Warning

Score: 6/6.

Enumerate the centre of the echo, assuming f_{i,A,B} denotes the number of AB substrings in s[1,i]. g_{i,A,B} denotes the number of AB substrings in s[i,n].

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

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

Problem G. Gridlandia

Score: 2/2.

Constructed Question. Will not.

Problem H. Holiday Regifting.

Rating: 7/8.

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

Maintain ans, initially 1. Maintain the gifts a_i received by each person at ans time. Enumerate i=1,2,\dots,n sequentially.

Time complexity \mathcal O(nm).

Problem I. Julienne the Deck

Scoring: 2/3.

If n\leq 2 the answer is n, otherwise the answer is 2n.

Problem J. Knight's Tour Redux

Score: 6/4.

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

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