Hello, Codeforces!
I'm glad to invite you to Codeforces Round 600 (Div. 2), which will be held on Nov/16/2019 17:35 (Moscow time). It will be rated for all participants with rating below 2100. You will be given six problems and two hours to solve them. As usual, the score distribution will be announced shortly before the round.
The problems were invented and prepared by me. Huge thanks to:
faremy for taking time to solve and give me precious feedback on most of the problems I have considered putting into my round throughout its whole creation (more than 6 months!)
300iq for coordinating the round and giving helpful advices
MikeMirzayanov for great systems Polygon and Codeforces
dorijanlendvaj, McDic, nvmdava, Kuroni, fedoseev.timofey, budalnik, _overrated_, aneesh2312, arthurconmy, Ifugao, sdssudhu, Savior-of-Cross, cfalas, teekteek and Ashishgup for testing
This is the first french round on Codeforces, I hope that everybody will enjoy it :) GL&HF to all!
UPD1: Scoring distrubtion is 500-1000-1500-1750-2250-2750
UPD2: Editorial is out
UPD3: Thanks for participating! Congratulations to the winners:
Div.1 (unofficial) participants
- Um_nik (solved all problems in 38 minutes!)
- dreamoon_love_AA
- mango_lassi
- imeimi
- cerberus97
Div.2 participants
First solve
This is the first french round on CF, I hope that there won't be any DDOS attacks.
I wish this will not happened
I really hope it doesn't happen today
Unfortunately, right in the middle of the two contest days of CSP-S 2019
Why don't stay up late XD
How to learn the culture of other countries?
Google (×) Codeforeces (√)
"Bonne chance et bonne note!"
It is correct?
I think we would just say "Bonne chance !" in french. We don't add anything comparable to "wish you high ratings", it would be redudant :)
Thanks for your advice!
Good luck to everyone in this round! Hope it will be unique and interesting (because it is anniversary).
Martin&Frederick instead of Alice&Bob :think:
I hope your first contest will be my best ;) Good Luck to everyone
Round clashes with COCI #2. Please do smth. I really don't want to skip either COCI or Round, where McDic is tester
what's COCI?
Croatian open competition in informatics
I'm very sorry for this issue, I knew it too late :( It would be very difficult and annoying for me to reschedule the round. Still, good luck for the contest you'll choose to do.
Also with CSP 2nd Round, or the OI in China
When you said "I really dont wanna skip Round where McDic is tester". Was it sarcasm?
Smh smh McDic is amazing tester smh
And DeliciousFlatChest is an excellent problem setter
Round also clashes CSP in China, which is the biggest contest for teenagers in China.
Bonjour à tous — Bonne chance
baguette round :O
Me: I haven't done a CF round in ages. I should do this one!
Also me: wait I tested this?
You will not be lucky enough to see someone in No.1 spot in top rated list except tourist for long. Congratulations ! Benq.
Everyone knows I only test the best rounds
chsv
What is meant by chsv?
Feeling of one's superiority (from Russian)
Lol
Does it mean french statements? Or, does it mean problems made in France? :o
Problems made in France. Statements will be only available in english and russian, as usual.
Alright, thanks. I was afraid of french statements :o
Upvote to become green
You're OneSubmitMan you should be legendary grandmaster all problems are accepted in one submit
Guess OneSubmitMan is still true after this contest
As soon as I saw that the round would be french, I immediately thought of baguettes, berets, and french accordian music. Good luck on the round everyone!
I hope the problem statements are short and clear.
Score distribution?
what is the penalty for wrong submission in this contest ? 50 or 10 points ?
Codeforces Round 600
А на логотипе до сих пор "Beta".
A well balanced contest! Thanks hugopm
I'm not the only one who did Silly Mistakes :/ I forgot the most obvious case in B when the employee doesn't leave and as always forgot to handle long long in C
I did Silly Mistakes on both A and B =)
declare 1005 elements of array when it actually has 100000 elements
My silly mistake in finding representative for sets — par[i] = par[par[i]] instead of par[i] = root(par[i])
Segmentforces lol :D
Good round btw
Become Master =)) congratulate!
Now I'm sure in this so thank you!
Quite strange to see vovuh in orange colour (instead of purple colour)
Does d&c optimization not work for E? f[i][j] — minimum cost to cover prefix j considering first i elements. Here is the submission that works in n*m^2. The commented part and the recursion function is the d&c optimization.
Can you explain your idea a bit?
Updated.
I don't think the dp was of the form where you can do divconq.
Well it looks like a recurrence that can be optimized by d&c but i don't think that the function is monotonous so you might be right.
How to solve F?
Find distances between every two of centrals using Dijksta-like algo.
After that sort all central-to-central distances.
Construct DSU where for each component you maintain set of queries not yet answered.
Then just merge distances from (2) in increasing order. Use small to large technique: and if query from small is present in large set that means that this merge is first moment when queries vertices is reachable one from another
I was 2 minutes to slow to finish this in contest, so I'm waiting up-solving to submit. 65211806
lol, i first construct MST after dejkstra and then solve smth like max edge on tree path query problem. Didn't understood that i could have answers on constructing mst already
This might be super complex, but I think it works:
1) Find minimum distance to every vertex from a vertex that has a station (Dijkstra), denote as d[v]
2) Transform the graph, so that each edge has now cost c[u, v] = c0[u, v] + d[u] + d[v], where c0[u, v] is cost at the beginning
3) Now each query is equivalent to — what is the heaviest edge on path in this graph between a and b.
4) Find minimum spanning tree of this graph, and on that MST perform LCA to find heaviest edge from a to LCA(a, b) and b to LCA(a, b).
I got RTE13, but I think it should do okay.
I got lost on step 2. Why do we want the heaviest edge between a and b after the transformation? Also, what was the intuition behind the transformation?
EDIT: I misread your step 1. Thought you chose an arbitrary central. Nice solution!
If I pass pretests, then brilliant round!
Or else, still brilliant round!
Is E a straight-forward dp? I thought it was easy, but I keep WAing on pretest 5.
If $$$x_i < x_j$$$, you only extend $$$x_i$$$ enough to cover the uncovered left part because it's always better to cover the right part with $$$x_j$$$.
What was test case 6 in D? :(
How to solve D?
Use dsu Find min and max in every component, save these as segments, sort them If seg[i] crosses seg[i -1] then combine them and ans++
How much crosses if one (or more) segment completly inside another? And why?
I also checked whether these two segments are connected now or not using dsu
In problem D, I tried this approach: instead of finding the union-set of each element, store each disconnected component's max and min in a vector using dfs, sort the vector by min elements, then no. of segments (found using the above sorted vector by normal traversal) which are intersecting is the answer.
how do we find intersecting segments.?
considering you have above vector<pair<int, int>> x, and:
The problem is much simpler, see https://codeforces.net/blog/entry/71442?#comment-558320
I made the same idea, I hope this idea pass the system test
How to solve D? is it union find?
i got TLE using union find
It is somehow about counting the components and count the missing connections between them. Still not fully sure about which ones to connect to each other.
I guess each connected component must have all consecutive vertices. If not, you must connect it to another component that has that vertice. I tried this using DSU and got TLE, and then WA.
I used different approach, https://codeforces.net/blog/entry/71442?#comment-558303 .
Do DFS from 1 to N for every currently unvisited node and store the maximum visited node so far. Before doing DFS if the maximum visited node is greater than this unvisited node that means u need to connect these components, and hence increase answer by 1.
Thats by far the most nice solution to this problem I have seen, thanks.
Thanks, this is a cool idea! I missed it completely :(
Yea union find worked for me.
Edit. But now that I think about it — simple dfs or bfs would be enough for me.
Process the connected components (either bfs, dfs or union find) and identify the max element for each component. Then check for each element 1 through n what component it belongs to and the max of this component. If you see an element of a different component and you haven't reached the max, update the max and add 1 to the answer. $$$O(m+n)$$$ overall.
Отличный и сбалансированный раунд. Спасибо автору.
Sad :((((((((((
graphforces
Couldn't solve anything... feel so dumb atm... :'D
So far, there isn't any comments on B.Ummmm......Don't you want to say something about it?
I don't know what is the corner case in test 13
I shouldn't make such a comment. My B FST now......
Worst Contest i ever had. trash A,B problems
You have done only 2 contests so far. It is too early for you to get frustrated.
You even didn't submit neither A nor B. How could you have contest if you haven't participated?
in Div2-B I did the same as tutorial but instead if the office is empty start a new day I didn't start a new day and continued the solution until I found someone who is already entered, I begin new day at this time.
what makes this solution fails on test 13 ?
I'm guessing something like
would make it fail, as you end a day when 2 is still in the office.
Trying to minimize the number of days like you're doing is actually something none of the testers thought about, hence the lack of pretest designed to make this solution fail. There will most likely be a lot of systests on that problem, and we sincerely apologize for that.
agh!!!. what a (Silly Mistake)
Problem name is really describe my mistake!!
What is the answer to the test case? Is it -1 (or) 2 [2 4] ?
The latter is the correct answer.
what if we check if the ones who entered already left when somone reenters above soltions should work..But it still fails on test 13. can someone help 65220901
Lol, I did same thing((( I think smth like this: 1 -1 2 1 -1 -2
I'm sorry for the unexceptedly high number of FSTs on B. It was the last problem added in the contest (between Single Push and Sweets Eating, in order to make the round more balanced) and we didn't come up with the incorrect greedy that tries to minimize the number of days :(
what does FST means?
"Fail system test"
You really just made an account just to ask that lmao
OK MAY
Поспешишь — людей насмешишь ©задача B
Got FST in B WA 33 :/ Can anyone go through and tell what silly mistake did i do?
https://codeforces.net/contest/1253/submission/65188326
thanks
got it simple silly mistake
Fastest editorial I've ever seen
please what's wrong with my solution to B?
6
2 -2 3 2 -2 -3
try this case
Thanks hugopm !
Can someone tell me a cleaner approach for D using DSU . I did something like storing the minimum vertex in each component and if that component does not form a contiguous segment I start merging.
My submission I use dsu first and then sort And do the greedy approach
I used the same approach, but I stored maximum vertex of each component. So merge all components from
i
toi + 1 ... mx[i]
for alli
. You can see it in my 65211671 submission. Overall complexity isO((n + m) * DSU)
My explanation on the editorial blog
I can relate with B's name .
Worst Mistakes I have done in a while (just missed both B and D).
Can someone explain their idea for problem E using Segment tree?
The inner min query of DP transitions can be converted to segment tree, though it's unnecessary.
Create segtree of size m+1. You start index
0
with cost0
, and indices1...m
with costinf
. Then we iterate through each antennai
in increasing order of position. Now we iterate through all possible sizesj
for antennai
, such that it reaches interval[i-j,i+j]
. The cost, denoted bycst
, for this interval ismax(0,j-s_i)
. Now we add this interval in the following way: we find the min costx
on interval[i-j-1,i+j]
and then set indexi+j
tocst+x
. In this way, we are "extending" the configuration from[0,i-j-1]
to[0,i+j]
. Now answer is indexm
in segtree.Thanks hugopm for the round and congrats for reaching GM!
My rating before the round: 2032 Expectation: +68 (Master) Reality: -68. Expectation + Reality = 0.
I've did some Silly Mistakes in the problem B during the contest, but resolved after that. In C I can't think of a solution with complexity less than O(n^2), any tips or topics to study?
The solution to C involves dynamic programming. However, we must make some observations first.
If you want to eat exactly $$$k$$$ sweets, it is optimal to always eat the ones that will result in the least sugar penalty. So, we will sort the sweets from lowest to highest sugar penalty, and for each possible $$$k$$$, we will eat the first $$$k$$$ candies in our sorted array.
Next, we realize that the optimal way in which we eat these $$$k$$$ candies is to take as many as we can each day, starting from the largest ones. For example, if we had $$$k=5$$$ sweets from $$$(1, 2, 3, 4, 5, 6, 7)$$$ and can eat $$$m=2$$$ each day, we would eat $$$(5,4)$$$ on Day 1, $$$(3,2)$$$ on Day 2, and $$$(1)$$$ on Day 3.
So there is our $$$O(n^2)$$$ approach! For each $$$k\leq n$$$, we greedily take sweets in this manner. To improve this to $$$O(n)$$$, we make some more observations about the patterns in these calculations. Let's consider the same example as above. For $$$k=5$$$, we have a minimum sugar penalty of $$$1(5+4)+2(3+2)+3(1)=22$$$. How about for $$$k=7$$$? Then we would have $$$1(7+6)+2(5+4)+3(3+2)+4(1)=50$$$, which looks suspiciously familiar...
The expression for $$$k=7$$$ can be broken down into the result of $$$k=5$$$, plus the sum of first $$$7$$$ sweets. As a matter of fact, the result of any $$$k=i$$$ will be equal to the result of $$$k=i-m$$$ plus the sum of the first $$$k$$$ sweets in our array, as long as $$$i>m$$$. We can calculate the sum of the first $$$k$$$ sweets in constant time by using a prefix sum array. Let's store our results in an array called $$$dp$$$.
Our transition is as follows:
- for $$$i\leq m$$$, $$$dp[i]$$$ is simply the prefix sum of all elements up to and including $$$i$$$.
- otherwise, $$$dp[i]=dp[i-m]$$$ plus the prefix sum of all elements up to an including $$$i$$$.
I hope this helped! If not, the official editorial should help you get somewhere. Cheers!
Wow, it really helped me and was very didatic. Much obliged!
For D, I thought of two questions:
(a) how many components are there at the beginning?
(b) how many components must be there after the operations?
then the answer is the difference (a)-(b).
(a) is a simple union-find. (b) is a Problem B when an edge (u, v) means an employee comes at time u and goes home at time v.
Can anyone please fix the tags for problem A? It seems that somebody had been spamming every single tag available on that problem.
some people copy from ideone and pretend that they are smart.
why they didn't give ratings till now?