**Hint1**

Let's consider that $$$l_1$$$, $$$l_2$$$, and $$$l_3$$$ are sorted working segments. Can we explicitly say something about one of them?

**Answer to Hint1**

$$$l_1$$$ must be equal to $$$1$$$.

**Solution**

Let's consider that $$$l_1$$$, $$$l_2$$$, and $$$l_3$$$ are sorted working segments.

If $$$l_1$$$ is not equal to $$$1$$$ then we can decrease $$$l_1$$$ by $$$1$$$ and increase $$$l_3$$$ by $$$1$$$. So we'll increase the answer.

We've got that $$$l_1 = 1$$$ and we have to work just with $$$l_2$$$ and $$$l_3$$$.

Now, our problem can be rewritten as:

$$$l_2 + l_3 = n - 4$$$, maximize $$$min(l_2 - 1, l_3 - l_2)$$$.

And as we know that $$$l_3 = n - 4 - l_2$$$, just:

maximize $$$min(l_2 - 1, n - 4 - 2 \cdot l_2)$$$.

If we increase both values under the minimum scope by one, solutions don't change:

maximize $$$min(l_2, (n - 3) - 2 \cdot l_2)$$$.

If we choose $$$l_2 = \left\lfloor\frac{n-3}{3}\right\rfloor$$$, then $$$min(l_2, (n - 3) - 2 \cdot l_2) = \left\lfloor\frac{n-3}{3}\right\rfloor$$$.

If the answer is greater, then $$$l_2 > \frac{n - 3}{3}$$$ and $$$(n - 3) - 2 \cdot l_2 > \frac{n - 3}{3}$$$, and it means that $$$2 \cdot (l_2) + ((n - 3) - 2 \cdot l_2) > n - 3$$$ but $$$2 \cdot (l_2) + ((n - 3) - 2 \cdot l_2) = n - 3$$$.

The only thing is left to do is to calculate final answer. And it is $$$\left\lfloor\frac{n-3}{3}\right\rfloor - 1$$$ or just $$$\left\lfloor\frac{n}{3}\right\rfloor - 2$$$.

It was a mathematician way of solving. As it's pretty obvious that $$$l_2$$$ is approximately $$$\frac{n}{3}$$$, you could check $$$l_2 = \frac{n}{3} \pm 5$$$ and choose the best among them.

**Code**

**Hint1**

Is there a way to cut pieces to save the minimum value and satisfy required conditions?

**Hint2**

What is the minimum possible number of operations to perform it?

Is there any better solution?

**Solution**

Let's start with a simple solution.

Let's choose the minimum piece from $$$a$$$ and assume that it will remain the minimum until the end.

As the array is sorted, let's define the minimum piece as $$$a_1$$$.

It means that in the end, all pieces must be smaller or equal to $$$2 \cdot a_1 - 1$$$.

The lower bound of the answer for this solution is $$$\displaystyle{\sum\limits_{i=1}^{n}\left\lceil\frac{a_i}{2 \cdot a_1 - 1}\right\rceil}$$$.

Let's show that this is achievable.

For each piece, while its size greater than $$$2 \cdot a_1 - 1$$$, let's cut off a piece of size $$$2 \cdot a_1 - 1$$$.

The only problem is that we could get a piece smaller than $$$a_1$$$ in the end.

But it means that before the last cut we had a piece in the range $$$[2 \cdot a_1, 3 \cdot a_1 - 2]$$$. All pieces in this range can be easily cut into pieces of the right size in one move.

The only left question is why the minimum piece in the end should have size $$$a_1$$$. Actually, it shouldn't, but it gives the best answer anyway.

As was described above, the lower bound of the solution with the minimal piece of size $$$x$$$ in the end is $$$\displaystyle{\sum\limits_{i=1}^{n}\left\lceil\frac{a_i}{2 \cdot x - 1}\right\rceil}$$$.

Having a minimal piece with a smaller size, we can't get anything better, because the lower bound will be equal or greater for all $$$x < a_1$$$.

**Code**

**Hint1**

What is the first letter in the answer?

**Answer to Hint1**

$$$a$$$ if $$$t$$$ doesn't start with $$$a$$$ and $$$b$$$ otherwise.

**Hint2**

Ask the same question as Hint1 for each position.

**Hint3**

When we can't choose the minimum unused letter?

**Answer to Hint3**

If we form a circle of size less then $$$26$$$.

Maintain any structure to check it.

**Solution**

First of all, the encryption process is reversible. If we obtained $$$t$$$ from $$$s$$$ using the circle $$$c$$$, we can obtain $$$s$$$ from $$$t$$$ using the same cycle $$$c$$$, but reversed.

So, let's think in terms of encryption of $$$t$$$.

Lexicographical order itself is a greedy thing. So, we can create a greedy algorithm.

Let's go from left to right and generate the result letter by letter. We have to choose the best possible option at each step. Let's describe the options we have.

- If the current letter was used earlier, we already know the replacement we need to choose.
- Otherwise, we would like to choose the minimum possible option. We need to maintain some structure to know what is acceptable.

Let's keep the circle that is already generated(it's a graph). For each letter we have one incoming edge and one outgoing edge in the end. Let's keep them for every letter: arrays $$$in[26]$$$, $$$out[26]$$$.

When we want to generate an outgoing edge at some step(let's define the letter on this step as $$$x$$$), we have to choose the minimum letter that doesn't have an incoming edge yet. With one exception: if creating the edge using this rule creates a circle of size less than $$$26$$$. It would mean that we wouldn't have a full circle in the end. It's easy to see that there is no more than one such letter, as this letter is just the end of a chain starting in $$$x$$$.

To check that a small circle wasn't generated, we can go along an outgoing edge $$$26$$$ times, starting at $$$x$$$. If we end up in $$$x$$$ or there was no edge at some step then everything is ok, we can create this edge.

Complexity is $$$\mathcal{O}(26 \cdot 26 + n)$$$, that is, $$$\mathcal{O}(n)$$$.

**Code**

**Hint1**

How many sets can fit in $$$5$$$ cards?

**Answer to Hint1**

At most two.

If there are two sets among $$$5$$$ cards, there will be a central card.

Consider each card as a central card.

**Solution**

For every two cards, there is always a single card that forms a set with them.

[1] That means that two sets can share at most one card.

Let's prove that there are no more than $$$2$$$ sets in a meta-set.

Let's define $$$5$$$ cards as $$$c_1, c_2, c_3, c_4, c_5$$$. Let's guess that $$$(c_1, c_2, c_3)$$$ is a set.

All other sets can have at most one card among $$$(c_1, c_2, c_3)$$$ (according to [1]), so they must include $$$c_4$$$ and $$$c_5$$$. So we have at most one other set, otherwise they would have two same cards, which is prohibited according to [1].

So, every meta-set looks like $$$2$$$ sets with one common card. Let's call this card a central card.

Now there is just a simple combinatorics. For each card, we want to know the number of sets that include it. If this number is $$$s$$$, then we should add $$$\frac{s(s-1)}{2}$$$ to the answer — it is the number of meta-sets with this card as a central card.

To get the number of sets for each card, we can iterate over all pairs of cards $$$(i, j)$$$, generate the complement to the set, and add $$$1$$$ to that card in a map/hashmap.

Complexity is $$$\mathcal{O}(kn^2\log(n))$$$ or $$$\mathcal{O}(kn^2)$$$.

**Code**

**Hint1**

How many possible options are there for the distance between $$$p_1$$$ and $$$p_2$$$.

**Answer to Hint1**

We can limit it with $$$2 \cdot n$$$ options.

Consider options $$$d_1[1] + d_2[i]$$$, $$$|d_1[1] - d_2[i]|$$$. Solve each one in linear(almost) time.

**Hint2**

Consider the biggest distance among $$$d_1$$$ and $$$d_2$$$.

Can we match it with something?

**Hint3**

Remove them one by one while they exceed the distance between $$$p_1$$$ and $$$p_2$$$. Then the problem is trivial.

**Solution**

Let's assume that considered point $$$p_1$$$ was to the left of considered point $$$p_2$$$.

Let's assume that we know the distance $$$l$$$ between considered points $$$p_1$$$ and $$$p_2$$$. Let's show how to solve this problem in linear time(almost linear).

As long as there is a value greater than $$$l$$$, let's get the largest among them(let's call it $$$x$$$). Let's assume that this value is from $$$d_1$$$.

It's easy to see that this point is to the right of the considered point $$$p_2$$$ (because the largest distances is to the point $$$p_1$$$). It means that we can match distance $$$x$$$ from $$$d_1$$$ to the distance $$$x - l$$$ from $$$d_2$$$.

When there is no value greater than $$$l$$$, all other houses are located between considered points. We can match them by sorting.

That is the $$$\mathcal{O}(n log(n))$$$ solution.

Let's limit possible options of $$$l$$$ with $$$\mathcal{O}(n)$$$ options.

If we know that some house has distances $$$x$$$ and $$$y$$$ to considered options, then there are $$$2$$$ options of $$$l$$$: $$$x + y$$$ and $$$|x - y|$$$.

Let's consider $$$2 \cdot n$$$ options $$$d_1[1] + d_2[i]$$$, $$$|d_1[1] - d_2[i]|$$$.

Complexity is $$$\mathcal{O}(n^2 log(n))$$$.

**Code**

**Hint1**

Draw currencies on 2D plane.

Assume that you can throw out any amount of money at any moment.

What will an area of possible points look like?

**Hint2**

It will look like a convex polygon in the upper-right quarter.

Keep its edges.

How does the structure change when a new day comes?

**Hint3**

A new segment is added. A prefix of old segments is shifted by vector, the remaining suffix of old segments is shifted by opposite vector,

**Solution**

Let's draw currencies on 2D plane. Having $$$x$$$ pebbles and $$$y$$$ beads is described as point $$$(x, y)$$$.

Let's assume that we can throw out any amount of money at any moment. In this case, an area of possible points can be described as a convex polygon in the upper-right quarter. Initially it is the rectangle $$$[(0, 0), (0, b), (a, b), (a, 0)]$$$.

At any moment, this polygon can be described as a list of segments starting at point $$$(0, y_0)$$$ and finishing at point $$$(x_k, 0)$$$. In the rectangle described above, there are $$$2$$$ segments.

Let's keep those segments sorted by angle.

When a new day comes, each point can be shifted by the vector $$$c\cdot(p_i, -q_i)\ \forall c \in [-1, 1]$$$ if the new point has non-negative coordinates.

If we forget about new points to be non-negative, how new segments look like?

We just have to add new segment $$$(2 \cdot p_i, -2 \cdot q_i)$$$ and shift a prefix of old segments by $$$(-p_i, q_i)$$$ and remaining suffix of segments by $$$(p_i, -q_i)$$$.

Then the only thing left to do is to cut segments to keep our polygon non-negative.

Sounds great, but sounds like $$$\mathcal{O}(n^2)$$$.

Do we need to maintain segments explicitly?

No!

Let's just keep the set of their lengths and angles. Knowledge of extreme points $$$(0, y_0)$$$ and $$$(x_k, 0)$$$ is enough.

So we need to:

- Insert a new segment to the set. (You need just length and angle).
- Shift extreme points $$$(0, y_0)$$$ and $$$(x_k, 0)$$$ by $$$(-p_i, q_i)$$$ and $$$(p_i, -q_i)$$$ correspondingly.
- Delete or cut the last and first segments while they are out of the non-negative area.

Complexity $$$\mathcal{O}(nlog(n))$$$.

There is another simple $$$\mathcal{O}(n^2log(n))$$$ approach:

We can keep the area as a polygon. At each step, create two copies shifted by corresponding vectors. Build a convex hull of them. Cut this convex hull to be in the non-negative area.

It won't fit. Mentioned just for fun.

**Code**

lol I hopcroft-karp'ed the E

Upd: mine got tle lol. guess it's not my lucky day

YES! I had same solution but i had no time to implement it. Sad :(

I tried and got WA :( dunno how I messed it up.

lmao same, i did dinics. Only took 187 ms too, good flow templates r just too fast.

Could you describe your flows approach?

WLOG, $$$p_1=0$$$ (u can shift at the end to make all the vals in $$$[0, 2e9]$$$). Each element for $$$d_2$$$ that you can match $$$d_1[0]$$$ to gives u two options for $$$p_2$$$, so we want to test a $$$p_1, p_2$$$ pair relatively fast.

Each $$$d_2$$$ val has two possibilities for a distance from $$$p_1$$$. If we frequency bucket the $$$d_2$$$ and $$$d_1$$$ values, we can setup a flow network which is like bipartite matching except that the edges from S / to T have capacity of the frequency of that element.

Each flow run has $$$2n=O(n)$$$ edges and $$$O(n)$$$ nodes, so (by a little handwaving that this is basically bipartite matching) it takes $$$O(m*\sqrt{n}) = O(n^{1.5})$$$. We do this flow $$$O(n)$$$ times, so overall $$$O(n^{2.5})$$$.

This comment got me curious. Does Dinic outperform Hopcroft-Karp?

Bro, if u know what is Dinic and Hopcroft-Karp, but u are specialist, u are doing something wrong

Can you explain what you mean?

BTW Idk either of those two terms

well I am specialist and I know that dinic and hopcroft-karp are both algorithms for the network flow problems. and also that dinic is usually fast but the optimal algorithm always depends on the problem in question.

smart boy

So because I am a specialist I shouldn't be learning more about algorithms. I'm sorry but what you are saying is just absurd.

studying more complex algorithms, while not fully working out the easy ones, is not a very good practice

I know flows and graph matchings from reading a book about algorithms, I didn't study them that much. I asked the question because I know that Hopcroft-Karp should be faster than Dinic in unweighted bipartite matchings but it seems that HK got TLE and Dinic passed here. Anyway, thank you for the advice and have a nice day.

As a tester, who solved it using the same technique. I can prove that Dinic is asimptotically correct here. There are $$$m = O(n^2)$$$ edges in total and $$$n$$$ vertices for bipartite matching. Dinic for bipartite matching works in $$$O(m\sqrt{n})$$$ which in this case gives us a solution in $$$O(n^{2.5})$$$ which is fast enough.

Don't u need to run the flow 2n times (for each possibility for p2 given by matching the first d1 to a d2)?

The trick I did was to deduplicate so $$$m$$$ is bounded by $$$O(n)$$$ cuz each d2 guy only has 2 options in d1. This isn't bipartite matching network anymore (non unit capacities from/to S/T) so the bound doesn't hold.

I suspect this is asymptotically still $$$O(n^{1.5})$$$ or something close per flow run, but I have no way to show that.

It's important, that there are a

totalof $$$m$$$ edges, so for each case it will work in $$$O(cntedges_i\sqrt{n})$$$, which in total is $$$O(\sum cntedges_i\sqrt{n}) = O(m\sqrt{n})$$$I did exactly this but I got TLE on test 48. I learned flows quite literally yesterday so I'm not sure if it's something I'm doing wrong or if my template is just inefficient, could you please take a look once?

My submission

I used max bipartite matching from CP4 ch4 and passed :)

well-balanced contest. thank you so much. hated it

logic in A was quite good!

well tbh it was just maths. let's define $$$k$$$ as $$$\lfloor \frac{n-3}{3} \rfloor$$$ and assume $$$n$$$ is a multiple of 3 then probably the 3 segments are $$$[1,k,2k-1]$$$ and the difference is $$$\lfloor \frac{n-3}{3} \rfloor - 1$$$. Didn't prove more (the minimum wouldn't be getting bigger anyways), and got AC.

idk, i just div it for 3 and minus 2

I didn't even understand A... Just needed to find some $$$x$$$ from $$$0$$$ to $$$7$$$ such that $$$\lfloor \frac{1033-x}{3} \rfloor=342$$$

In editorial of D, what is a "central card"?

It's the card that is shared by both sets in a metaset.

It's a card that appears in two different sets within a meta-set.

Two different sets can have at most one overlapping card (two overlaps would imply that the third must be the same as well, but then they're no longer different sets), so a meta-set (which has only five cards) can only fit in two sets if they have exactly one overlapping card. This card is considered as the central card of the meta-set.

(I actually mentally used the term "central card" as well when thinking about this problem during the contest, even though the statement never suggested such a term; I guess the visual explanation kinda screams "central card")

Thanks. I get it now. 2 sets means 2x3 = 6 cards, but we are only considering 5 cards. So 1 card is shared, or in other words, central.

Balanced Difficulties, great Problems, fast Editorial, all in one contest. Rated it as the best contest I have ever participated.

0≤hi,p1,p2≤2⋅109 for what?(((

I agree that it could be better to set $$$-2\cdot10^9 \leq h_i, p_1, p_2 \leq 2\cdot10^9$$$, but I don't find it a big challenge. You just need to shift all the values by an easy found constant in the end.

Yes, it is easy. But at last minute of contest I submitted my solution and got wa5 so now I have negative delta instead of top 40 div2. Unlucky...

My approach to D involved the key observation that three cards form a set if and only if the sum of values for each feature is 0 mod 3 (i.e., either i + i + i or 0 + 1 + 2). We can find the sum of every possible pair of cards, and count them in a structure (like a map). Then we iterate through each card in our input (to consider it as a potential central card) and subtract this card's value from 0 modulo 3 to get the required pair sum it can form a set with. We can then add sC2 as described in the editorial, where $$$s$$$ is the number of times this pair sum appears.

If we form a circle of size less then 26. Maintain any structure to check it.

Is there anyone who thinks he has implemented a very nice structure to check whether there is a cycle of small length or not?

well we already have the DSU???????Writing DSU takes too much time i didn't had pre written code for it.

And copy pasting code from online sites is not my style.

Oh come on, I took less than two minutes typing it. You didn't even have to apply two compressions here, one compression (path compression is what I used) was more than enough.

having some snippets is really useful. It makes your life easy a lot of times.

I used a dsu, but it isn't necessary. You can store for each letter the previous and the next. When you make 25 connections in this structure you have a unique set and can connect the ends

edit: no w8 that's not right. You still have to assign some number to the whole structure each time so you can understand if you aren't connecting a loop too soon. But you can do it the stupid way assigning an id to each member of the sequence you change each time. It's like O(n+alphabet²) complexity if i'm not wrong

You don't need a number for the whole structure; just storing the previous and next is enough, due to the nature of this problem. When we want to consider whether we can assign $$$c_2$$$ to be after $$$c_1$$$, this requires that $$$c_1$$$ doesn't already have a next character assigned, and $$$c_2$$$ doesn't already have a previous character assigned. So you can simply check the previous character from $$$c_1$$$, and then the previous character of that, and so on, counting how many steps this takes. If we took 25 steps, then the chain has all 26 letters, and we only need to complete the cycle. Otherwise, we can only link $$$c_1$$$ to $$$c_2$$$ if $$$c_2$$$ isn't at the end of this predecessor chain from $$$c_1$$$.

A simple while loop will work. 174406487

I used DSU, which is probably overkill when the size is max 26.

It should suffice to simply store which character precedes another in our circular wheel, using a simple array, e.g., pred[0] = 3 means D precedes A. To check if it's okay to set $$$c_1$$$ as the predecessor of $$$c_2$$$, we can check the predecessor of $$$c_1$$$ and then its predecessor, and then its predecessor, and so on. If we find $$$c_2$$$ at some point, then it forms a cycle, which is only okay if we saw all 26 letters in this chain. You could, of course, store successors instead of predecessors with similar logic.

In E distance arrays can be sorted just once and then each candidate (distance between $$$p1$$$ and $$$p2$$$) can be checked in $$$\mathcal{O}(n)$$$ with two pointers resulting in $$$\mathcal{O}(n^2)$$$ complexity

I think Problem A was very confusing.

Some experience and you will solve it very fast

Can someone tell me what's wrong is my approach for A or I read it incorrect? For a 0 based indexing,

I marked index 1 as Off Day, so I have index n-1,1 as Off days and now I need to find one more index which is Off such that my answer is maximum. I did that by finding such possible index b/w 1 and n-1. I can't take index 2 and index n-2 as Off days as they are adjacent to index 1 and index n-1. So I have (n-2-2)-1 possible indexes for the 3rd Off day. I choose this position by finding the middle of middle of that subarray. So the 3rd Off Day should be res/4 + 3 by my logic where res = (n-2-2)-1.

I think you're making it complicated by thinking on indexes. If you think about the way the intervals become it should get more clear. You have this setup: |w-ww...ww-| with a gap of length 1 and a gap of length n-3. Now if the answer is x the ranges are 1, x+1 and 2x+1 long (add the remainder to the last). The ranges x+1 and 2x+1 are in the part that's long n-3, so you can find x by the simple equation n-3 = 3x+2 + 1(this 1 is the day off) => (n-6)/3 = x

got FST on pE, at first glance I think it is because dinic but turn out to be map<int, vector<pair<int, int>> being tooooooooo slow :/

fix the latex typo in B solution it looks like:

[2 \cdot a_1, 3 \cdot a_1 — 2]

Fixed, thanks!

damn these aholes destroy the fun** https://www.youtube.com/watch?v=IZSyj2pTe_I T_Tyes

In problem D if it is allowed that 2 cards have the same feature set then problem becomes really hard I guess. If anybody has any solution ideas to this

did anybody else find B confusing ?

I found the problem itself easy, but I think the wording of the problem could have been a bit better (the twice part)... Also, one thing in B that threw me off the hook a bit was the test case given where the minimum element changed, but later I just assumed that min will remain same and coded accordingly as it didnt affect anything.

Me

SORRY to Bother u by mentioning :"" Akulyat... But i think some links in problems' codes are swapped.

BTW.. A,B,C Problems are great ^_^

Thanks! Fixed

And don't worry about mentioning, it helps others get the correct information faster.

I assume it was unintended, but a lot of $$$O(K N^3)$$$ solutions passed under the time limit in D.

$$$\mathcal{O}(kn^2log(n))$$$ with vectors was intended to pass freely. Also $$$\mathcal{O}(kn^2log(n) + n^3)$$$ with a low constant is ok.

Could you share some links to solutions with $$$\mathcal{O}(kn^3)$$$?

From the last page of submissions, sorted by execution time: 174409139,174420917,174438219,174428203,174409139.

174402025 too, but the amount of pragmas in his template deserves a special mention :D

UPD: I managed to hack one submission, probably because they didn't even have break statements anywhere. The rest of them pass in >3000ms. Perhaps a TL of 2 seconds would have been better!

In B why would you not just half the values at each step rather than removing 2 × a1 — 1 at each step?

Surely if you repeatedly half the value it will get smaller soon which means less number of steps.

Halving each time is not correct. For example, take 2550 -> (halving) -> 2 pieces of size 1275 for those 2 pieces, we again need to use 1-1 operations to make all pieces less than 1200 (600*2), so in total, we used 3 operations while we only need to use two operations if use operations like this 2550 -> 1199 and 1351, 1351 -> 1199 and 152

You are right, but how did you come up with the idea that halving might not be optimal.

Edit it was in the sample test case. I missed it.

The link to the code for C problem , directs to the solution code for D problem. An update would be appreciated :)

FIXYou accidentally put the link of D submission in the Code section for problem C.

The solutions are not at the correct question number.

Provided solution for problem D looks wrong: https://codeforces.com/contest/1735/submission/174443540

Sample testcase: 3 3 0 0 0 0 0 0 0 0 0

Actual answer should be 0. But it gives 9. This is happening because it doesn't take into account that central card should not be part of calculated set of pairs from which meta-set is created.

Akulyat: can you please look into this?

It is given that all the n cards are distinct in the input so the test case is not valid.

I see. This further simplifies the problem btw. Thanks for resolving my confusion!!

could someone explain editorial of A problem ... I am fine till "If we increase both values under the minimum scope by one, solutions don't change: maximize min(l2,(n−3)−2⋅l2)" but after that things are above my mind .

has someone solved problem A with binary search ?

Yes. Submission

I just couldnt form any mathematical formulation, and finally binary search was only thing I knew will work for sure.

can u please explain your approach ?

Submission I figured that L1=1, that means that there are n-4 days to distribute between L2 and L3. So i am searching for L2=mid and L3=n-4-mid, I am looking to maximize L2-L1 while still keeping (L3-L1 bigger than L2-L1) and (L3-L2 bigger than L2-L1).

can anyone explain ques C. Its difficult for me to understand whats written in editorial.

I got wa on pretest 14 in problem F during the competition, but when I replaced double with long double I got accepted... My error was about 10

^{-5}...Yeah it's a little unfair for languages that don't have 80-bit floating point (and those who may avoid

`long double`

out of principle due to architecture specificity). I basically had to hand-roll fixed-point arithmetic just to get it to pass in Rust: 174869219Interestingly it is important in this implementation that the multiply be performed before division, otherwise it loses enough precision to fail.

UPD: I found a way to get 64-bit floats to pass: 174932779, compare with failing submission 174826031. Basically, truncating the convex hull from the "pebbles" axis first apparently gives more accurate results, since that's the result you have to output.

It may also be more optimal for accuracy if, when interpolating, you reuse the slope values from the input, rather than recalculating the slope from the rounded-off endpoints.

I don't know why but I felt A to be bit harder than usual.

Does anyone have ideas on how to solve D if the cards are NOT distinct?

There is two option :

1-ABCDE = combine ABC and CDE and ignore clones of them. Use clones just for how many different A can come etc.

2-AAA??, AAAA??, AAAAA = iterate A over all different cards and let $$$x$$$ be frequency of a card increase ans by $$$C(x,3)*C(n-x,2)+C(x,4)*C(n-x,1)+C(x,5)$$$.

There's an intersection AAABC and you can calculate it with iteration over suitable ABC's (iterate A and B, find C at $$$O(log(n))$$$) and some combinations using A, B and C's frequencies.

But this solution can require so much casework.

(Sorry if this solution is wrong or has missing part, and for my poor English.)

Deleted

https://codeforces.com/contest/1735/submission/174486190

can anybody tell why my solution from problem D gives me wrong answer ?. I am taking ith card as central card and finding no of sets formed with ith card as central card.

Consider this case:

caseIt is the same as the first example, only that the card "0 0 0 0" is now the last card. Your code returns 0, but the correct answer is 1.

This round is so great that I cannot understand the meaning of the problem D.

Can someone explain the flows solution to E?

I get the general idea, there are $$$O(n)$$$ possible values for the distance between $$$p_1$$$ and $$$p_2$$$ and you run a max flow for each of these options, what I don't quite understand is how, for some house $$$h_i$$$ and some candidate distance $$$d$$$, it could be that $$$|p_1 - h_i| + |p_2 - h_i| = d$$$, or $$$||p_1 - h_i| - |p_2 - h_i|| = d$$$, how do I formulate this into a max flow / max bipartite matching problem?

Actually $$$|p - h_i|$$$ is just the distance between point $$$p$$$ and the house, so the above equation can be rephrased as $$$d_{1, j} + d_{2, k} = d$$$ or $$$|d_{1, j} - d_{2, k}| = d$$$ for some index $$$j, k$$$.

So just let $$$d_{1, 1...n}$$$ be the vertices of left part($$$L_{1...n}$$$) and $$$d_{2, 1...n}$$$ be the vertices of right part($$$R_{1...n}$$$), and for every pair of $$$(j, k)$$$ satisfy $$$d_{1, j} + d_{2, k} = d$$$ or $$$|d_{1, j} - d_{2, k}| = d$$$ connect $$$L_j$$$ and $$$R_k$$$.

Ahh, so you don't need to distinguish between the plus and minus parts. Thank you I'll try that

can anybody tell why my solution (https://codeforces.com/contest/1735/submission/174557086) from problem E has tle, but https://codeforces.com/contest/1735/submission/174558165 — normal what is the difference?

a harder version of D with k<=100 or with more than 3 values for a characteristic would be great imo

174937931 I understood the editorial of C but I am unable to find whats wrong in my solution. I am getting WA in test case 3. If possible can someone tell me the test case where my solution is wrong.

Thank you in advance.

Take a look at Ticket 16251 from

CF Stressfor a counter example.Thank you very much Made some changes and now solution is accepted.

C and D are really good problems, I especially love how D balances implementation and thinking so well.

My E was TLE on #45.

Anyone can tell me why it got TLE?

Submission: 175739035

[deleted]

[deleted]

how can we check the cycle in problem c ?

without using dsu

Why does set or map of string takes far more time than set or map of vector doing same operations . See my submissions there is a reasonable time reduction . Submission — https://codeforces.com/contest/1735/submission/266351992 (890ms) https://codeforces.com/contest/1735/submission/266349652 (3889ms)