Hello, Codeforces!

It's our pleasure to announce the the finals of the 11th Bubble Cup! Bubble Cup is a programming competition organized by Microsoft Development Center Serbia (MDCS). The contest will take place on Saturday, 22nd of September at 11:00 UTC+2 in Belgrade, and will last for 5 hours. Live results will be available on the official Bubble Cup website. Results will be frozen during the last hour of the competition. The winners will be announced at the closing ceremony.

The format of the competition is very similar to ACM-ICPC — teams consisting of up to three people are allowed, and they have one computer and five hours to solve problems without partial scoring. Ties are broken using the usual time penalty rules.

Just like in the previous years, there will be an online mirror of the finals here at Codeforces, starting on Saturday, 22nd of September at 12:35 UTC+2. Unlike in the previous years, the mirror will be on the same day as the onsite finals.

This year, the onsite competition is divided in two "divisions", called Premier League and Rising Stars. The two contests will have most of their problems in common, but the Rising Stars competition will feature some easier tasks targeted at high school contestants. We do not guarantee that every problems unique to Div2 is easier than every problem that is not.

Both of the contests will be mirrored here on Codeforces, with Premier League mapping to the Div1 contest and Rising Stars mapping to the Div2 contest. The mirror will use native Codeforces ACM-ICPC team contest rules.

Both contests will be **unrated**, due to the format and the length of the mirror being dissimilar to the standard Codeforces rated rounds. Note that this is a **team contest**, i.e. competing in teams up to three people is allowed. (Of course, you can also compete in a 1-person team.) There will be at least 9 problems in each division.

*As of now, Codeforces does not support rating-based divisions in team contests, so we came with the following ad-hoc rule:* *teams with the maximum rated member having rating less than 1900 should enter the Div2 contest. Teams with the maximum rated member having rating at least 2100 should definitely enter the Div1 contest. The teams not covered by the previous two criteria are free to choose.*

Here are the past Bubble Cup mirrors on Codeforces:

Bubble Cup 8 — Finals [Online Mirror]

Bubble Cup 9 — Finals [Online Mirror]

Bubble Cup X — Finals [Online Mirror]

The problems and their solutions were created by employees and interns of Microsoft: Milanin, ibra, balsa_knez, Kole, radras, fulu, pedja, niksmiljkovic, davidmilicevic97, FilipVesovic, yours truly, and many more. Most of the team works in MDCS.

We express gratitude to KAN and 300iq for round coordination, and MikeMirzayanov and the rest of the team for the great Codeforces and the wonderful Polygon platform. We thank testers DBradac and especially the extremely helpful knightL, for helping prevail various difficulties.

The full editorial, together with the statements and solutions of the tasks from the qualification rounds, will be available in the booklet section of the Bubble Cup website on Sunday. An editorial with short descriptions of solutions may appear on Codeforces before that.

Good luck to all participants!

EDIT: Congrats to everyone that competed! In total, there were over 800 teams that solved at least one problem.

The winners of Div1 are:

Merkurev, I_love_Tanya_Romanova, Um_nik — a special congratulations for being the only team on the mirror to solve all problems, two of them in the last 5 minutes!

LHiC — the best one-man team, with 9 problems solved

The winning team of Div2 is:

- fengyecong, Als123, 200815147 — winning with three problems to spare!

This post will be updated again when the booklet is online, which should be before the end of the day in UTC+2. Also, onsite results won't be known until the awards ceremony in the evening.

Thanks all for participating!

EDIT 2: **The editorial is up!**

How pathetic

Just trying to raise your contribution

Auto comment: topic has been updated by dpaleka (previous revision, new revision, compare).does the one-computer rule apply to unofficial participants too or only the onsite contestants?

Nobody can really come to your house/wherever you do the contest and force you to use one computer. Depends how you want to do it, and how honest you are with yourself.

That's an excellent question! We should have put this in the announcement:

After some thinking, we decided to adapt the Bubble Cup onsite rules, i.e. the rule on the mirror is that

at most one person in the team is writing code at any time. Using more computers than one is OK, as long no two people code at the same time.The reason for this is twofold:

we want to "mirror" the onsite competition at closely as possible, and enable comparison the results of the onsite and online teams

we want to enable teams to have this Bubble Cup mirror as a practice contest for the coming ACM-ICPC season

As everyone knows, this rule

cannot be enforcedefficiently except in the most outrageous cases. However, we made the round unrated, and we think it would be really sad to see cheating en masse on an unrated Codeforces round.Good luck everyone!

In my opinion it is quite a silly rule for anyone not participating at an ACM ICPC competition. The rule only makes you waste time. It would be wonderful if you could have an option which you check if you are obeying the rule. That's the most honest and fair you can get for everyone.

Is it rated?

No, Both contests will be unrated, due to the format and the length of the mirror being dissimilar to the standard Codeforces rated rounds. Note that this is a team contest, i.e. competing in teams up to three people is allowed. (Of course, you can also compete in a 1-person team.) There will be at least 9 problems in each division.

Why didn't CodeForces evaluate the code?

Unrelated questions :

1. Why is there no participants in Technocup 2019 — Elimination Round 1?

2. Why Codeforces' Submissions has so many "In Queue"?

Update : the problem in question 2 had been fixed

My rating is less than 1900 but I register in Div. 1 without any warning ?1?!? Can I participate in Div. 1?

What does that orange colour indicate (over the team number)?One or more of your team-mates has registered individually. Unregister it before the starting of contest to correct it.

i participated in both round with one handle .am i going to disqualified.

How to solve B?

B is mine, along with C and F.

If

Ais the first bag,Bis the second, a necessary and sufficient condition for some residuexnot being inA+Bis:A=x-A.And this is a string problem, where the characters are the differences of consecutive members of

A!Really liked B, thank you! It was hard for me but people solved it very well.

It is weird how the early accepted solutions on public scoreboards reshape the flow of the contest. On the onsite, B wasn't solved in the first two and a half hours!

Yeah, and here on CF, E was practically unsolved but onsite there were at least three teams who solved it.

And of course, B having more ACs on the mirror than D — I thought it could never happen.

Nice solution! I didn't think of this during the contest and then I did some random approach :

Randomly shuffle the array

A. ConsiderS= {A[0] +A[0],A[0] +A[1], ...,A[0] +A[n- 1]} as the set of all candidate solutions.Let

sbe the sum of allA[i], then ifxis a solution, we must haveNx≡ 2s(modM). Remove elements inSnot satisfying this property.For each remaining candidate

x, I check it againstCrandomA[i] by checking ifx-A[i] is in the array. If it works for allCrandomA[i], then I considerxin the final answer.Cis carefully chosen so that I won't get TLE.I'm not sure why this works or it probably doesn't and it might be possible to find a countercase for it.

with 8 replaced with 9 and 399998 replaced with 399997 is a counter case. since 9 and 399997 along with

x- 8 andx- 399998 are the only witnesses for the invalidity of even numbers (except 6).what a contest!

Clutch submit

wipes sweatP.S. Problem name is Last Chance

Just realized that I had the first and last accepted submission in the Div. 1 mirror.

WoW.

Congrats!

How to solve "Self-exploration" and "Hyperspace Highways"?

Hyperspace Highways:

Find biconnected components. Build a graph where nodes are nodes of old graphs and components; edges are between nodes from old graph and components they belong to. Now you have queries on tree.

My solution for Hyperspace Highways : Construct bfs tree. It can be easily proven that for any two nodes

u,vin the bfs tree, ifuis not a parent ofvor vice versa but there is an edge betweenu,v, thenuandvmust share the same parent if the graph satisfies the given condition.For a query

u,v, ifuis an ancestor ofv(or vice versa) in the bfs tree, the answer must bedist(u,v) in the bfs tree. Otherwise, letLbe the lca ofu,vand letu',v' be the children ofLsuch thatu' is an ancestor ofuandv' is an ancestor ofv. Then, the answer isdist(u,v) - 1 ifu',v' are connected by an edge anddist(u,v) otherwise. (dist is the distance function with respect to the bfs tree).I think your solution fails for this simple test case: 7 7 1 1-2 2-3 3-4 1-5 5-6 6-7 4-7 4 7 How come this solution pass the system test? The test case is simply a cycle! Your code returns 6, whereas the answer is 1. Many have used this approach and their solution have passed, all of them give 6.

The graph you have described does not satisfy the conditions of the problem.

This is literally underlined in the statement: "In other words, the set of planets in every simple cycle induces a complete subgraph."

Why is this upvoted? Am I misunderstanding something?

Isn't it forming a simple cycle? `1-2-3-4-7-6-5-1 ? And the dfs solutions are giving 1 as output whereas bfs solutions are giving 6 as output.

I think I've realized my mistake. I thought that every simple cycle in the graph should be replaced by a clique. The clique was already given in the input graph. Sorry for the inconvenience!

For "Hyperspace Highways": You replace each complete subgraph that has vertices [a1, a2, a3, ..., an] with subgraph with edges [(a1, newV), (a2, newV), (a3, newV), ..., (an, newV)] after this you have a tree. It's easier said than done though. Now enjoy my awkward explanation.

Basic idea is that during dfs-traversal (starting with root depth=0 and increasing depth by one for each layer) for each vertex you go through all it's edges and find neighbour vertex with minimum depth. It is Almost an Id of complete subgraph yet. But not yet, here is an example:

If we start dfs with vertex=1 each vertex will find the vertex 1 as the vertex with minimum depth but there are two separate complete subgraphs here that shouldn't merge. The solution is to keep a stack of dfs-traversal and take not the "stack[minimumDepth]" but "stack[minimumDepth + 1]" as the Id of the subgraph. In this case the complete subgraph Ids will be 2 and 4 as they are "just below" 1 in the traversal tree.

After this you have a tree with no more than 2*N vertices for which you use Least Common Ancestor to find the minimum route length. Code: http://codeforces.com/contest/1046/submission/43264131

I solved it during the contest but 1s time limit seems to be too harsh for this problem so it haven't get accepted during the contest. Few minutes later I replaced dynamic vectors with preallocated memory and this optimisation barely made it in 1s.

Does someone have an easier solution or better explanation?

We used much simpler DFS-tree solution, and just smart finding of connected components in neighbourhoods of vertices — both solutions can be made to run in , which should run in 0.3s on the system tests. Everything will be explained in the booklet pdf.

Of course, the BFS-tree solution is even better and simpler, but it actually took us by surprise during the contest.

I tried to understand the solution from the booklet. Doesn't look much simpler:)

And I am not sure it's idea is different from my solution as I am also searching for minimumDepth of each complete subgraph.

Can you provide your code?

I didn't code it but does this solution work for Hyperspace highways? We condense each cycle to a vertex and then we can calculate the distance by lca preprocessing. But it seemed like we have to take specific care of some cases like each cycle which we condense should have a cost of 2 and other vertices should have a cost of 1 and also take care when a vertex in one of the queries belongs to a cycle.

Almost, but you replace not just the cycle but all the complete subgraphs. Complete subgraph [a1, a2, a3, ..., an] becomes subgraph with edges [(a1, newV), (a2, newV), (a3, newV), ..., (an, newV)].

In my implementation this also holds true for complete subgraphs of size 2 (not a cycle): [a1, a2] becomes ([a1, newV], [a2, newV])

Then you compute distance using LCA and divide it by two (because all edges where replaced by edge-newVertex-edge)

Cool, Your solution seems neat!

Not really.

This solution seems neat: http://codeforces.com/blog/entry/61905?#comment-460006

Auto comment: topic has been updated by dpaleka (previous revision, new revision, compare).How to solve, 'Palindrome Pairs'? So many people solved it, I feel stupid.

I did it the following way:

For each string, calculate a bitmask, where the

i-th bit will be 1 if you there are odd number of occurrences of thei-th letter in the alphabet, otherwise the bit will be 0. For example, "aabz" will be represented by "100000000000000000000000010", because we have odd number of 'z' and 'b'.Within a map, calculate how many time does each mask occur in the input.

Now let's process each mask one by one. Lets say we have a mask with some number of set bits:

Checkout my code for reference.

Does anyone know a problem very similar to E, or a math problem very similar to F? We're now sure that answers to both of these questions exist, but we cannot find anything.

E : https://ioinformatics.org/files/ioi2006problem6.pdf https://www.ioi-jp.org/camp/2012/2012-sp-tasks/2012-sp-day2-constellation-slides.pdf

F is quite similar to the last problem from https://www.hmmt.co/static/archive/february/problems/2012/algebra.pdf in the sense that the key lemmas in the solutions to both problems are the same.

Yes, I forgot the source of that problem, which more or less inspired this F task.

I actually remembered it without the "any coefficient" part. The solution is the same, except collinear points are now a big problem, as in

y^{2}*P(x). Does anyone have a solution for this, in any complexity?Auto comment: topic has been updated by dpaleka (previous revision, new revision, compare).How come Candidate Master can participate in both Div.1 and Div.2 when both contests are at the same time ?

My opinion on hard problems:

A: Just write the flow and restore the answer. Oh, and we also made constraints insanely high so you will doubt your solution at first. Like, really, we need to run 5000 DFSs (I use the analysis from the editorial here) on a graph with about 350000 edges. This is not OK.

E: Cool problem, but it looks like there were such problem before.

F: One of the best problems this year, at least.

J: We didn't believe that is fast enough, so we come up with

O(NK) ( because we had not enough memory for arrays in trie). And then Merkurev spend 3 hours to squeeze it through ML. This is not cool.Also, 2 of 4 hard problems are geometry (geometry about convex hulls in particular). Well, F is more about coming up with the solution, but the implementation part is also not easy.

For A, I had to do flow on segment tree. Am I dumb?

I would like to share an alternative, easier solution for "AI robots" (Div 1/G, Div 2/A): As in the official solution for each robot I also did 2K+1 queries for different IQ levels. The main idea is to sort all robots by their view radius in the decreasing order and then add robots to the IQ-corresponding-Treap one by one. To count how many robots the current robot can see we simply do one treap request for range [x — r, x + r]. Because we sorted the robots by their viewing radius, all the robots that are already in the treap have viewing radius >= r, and thus can also see the current robot.

Main part of the code:

Submission: http://codeforces.com/contest/1046/submission/43254253

Fun fact about problem A: if we reduce it to maximum matchings in a stupid way (so that the graph may have

O(NM) edges) and run Kuhn with some optimizations, it passes in 374ms (43263725).Can someone tell me how to efficiently generate tests for Hyperspace Highways?

I am the author of the problem, which was made into existence as I read about 2-distance operation on graphs, and wondered if the inverse of the procedure is computable. (When doing 2-distance of a graph, you keep all vertices and connect every two vertices which are two edges apart.)

Trying some examples, I noticed that the graphs obtained from trees were particularly nice — in fact, 2-distance graphs of trees are made of two connected components, each of which satisfies the constraints of the Bubble Cup problem.

So, we created some nice trees, and just applied the 2-distance transformation. For good results, you should have some vertices with degree .

Are there any details I need to know on this problem? I always get one less than correct answer on test #32.