Блог пользователя hugopm

Автор hugopm, 4 года назад, По-английски

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:

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

  1. Um_nik (solved all problems in 38 minutes!)
  2. dreamoon_love_AA
  3. mango_lassi
  4. imeimi
  5. cerberus97

Div.2 participants

  1. Son
  2. root_power_6
  3. Do-Kwon
  4. AlineSH
  5. Hezx

First solve

  • Проголосовать: нравится
  • +794
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится -105 Проголосовать: не нравится

This is the first french round on CF, I hope that there won't be any DDOS attacks.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +153 Проголосовать: не нравится

I wish this will not happened

y3mqxi9bulm11.jpg

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится

Unfortunately, right in the middle of the two contest days of CSP-S 2019

»
4 года назад, # |
  Проголосовать: нравится +84 Проголосовать: не нравится

How to learn the culture of other countries?

Google (×) Codeforeces (√)

"Bonne chance et bonne note!"

It is correct?

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +24 Проголосовать: не нравится

Good luck to everyone in this round! Hope it will be unique and interesting (because it is anniversary).

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Martin&Frederick instead of Alice&Bob :think:

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I hope your first contest will be my best ;) Good Luck to everyone

»
4 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

Round clashes with COCI #2. Please do smth. I really don't want to skip either COCI or Round, where McDic is tester

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +26 Проголосовать: не нравится

Bonjour à tous — Bonne chance

»
4 года назад, # |
  Проголосовать: нравится +36 Проголосовать: не нравится

baguette round :O

»
4 года назад, # |
  Проголосовать: нравится +167 Проголосовать: не нравится

Me: I haven't done a CF round in ages. I should do this one!

Also me: wait I tested this?

»
4 года назад, # |
  Проголосовать: нравится -13 Проголосовать: не нравится

You will not be lucky enough to see someone in No.1 spot in top rated list except tourist for long. Congratulations ! Benq.

»
4 года назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

Everyone knows I only test the best rounds

»
4 года назад, # |
  Проголосовать: нравится +39 Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

Does it mean french statements? Or, does it mean problems made in France? :o

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +89 Проголосовать: не нравится

    Problems made in France. Statements will be only available in english and russian, as usual.

»
4 года назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

Upvote to become green

»
4 года назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

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!

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I hope the problem statements are short and clear.

»
4 года назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

Score distribution?

»
4 года назад, # |
  Проголосовать: нравится -14 Проголосовать: не нравится

what is the penalty for wrong submission in this contest ? 50 or 10 points ?

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

Codeforces Round 600

А на логотипе до сих пор "Beta".

»
4 года назад, # |
  Проголосовать: нравится +29 Проголосовать: не нравится

A well balanced contest! Thanks hugopm

»
4 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

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

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I did Silly Mistakes on both A and B =)

    declare 1005 elements of array when it actually has 100000 elements

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    My silly mistake in finding representative for sets — par[i] = par[par[i]] instead of par[i] = root(par[i])

»
4 года назад, # |
  Проголосовать: нравится +78 Проголосовать: не нравится

Segmentforces lol :D

Good round btw

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +2 Проголосовать: не нравится

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.

»
4 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

How to solve F?

  • »
    »
    4 года назад, # ^ |
    Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится
    1. Find distances between every two of centrals using Dijksta-like algo.

    2. After that sort all central-to-central distances.

    3. Construct DSU where for each component you maintain set of queries not yet answered.

    4. 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

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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

  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +14 Проголосовать: не нравится

    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.

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится

      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!

»
4 года назад, # |
  Проголосовать: нравится -15 Проголосовать: не нравится

If I pass pretests, then brilliant round!

Or else, still brilliant round!

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is E a straight-forward dp? I thought it was easy, but I keep WAing on pretest 5.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    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$$$.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What was test case 6 in D? :(

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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++

»
4 года назад, # |
Rev. 4   Проголосовать: нравится +1 Проголосовать: не нравится

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.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D? is it union find?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    i got TLE using union find

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +14 Проголосовать: не нравится

    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.

    Spoiler
  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Yea union find worked for me.

    Edit. But now that I think about it — simple dfs or bfs would be enough for me.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Отличный и сбалансированный раунд. Спасибо автору.

»
4 года назад, # |
  Проголосовать: нравится +30 Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

graphforces

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Couldn't solve anything... feel so dumb atm... :'D

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

So far, there isn't any comments on B.Ummmm......Don't you want to say something about it?

»
4 года назад, # |
  Проголосовать: нравится -30 Проголосовать: не нравится

Worst Contest i ever had. trash A,B problems

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +22 Проголосовать: не нравится

    You have done only 2 contests so far. It is too early for you to get frustrated.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    You even didn't submit neither A nor B. How could you have contest if you haven't participated?

»
4 года назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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 ?

  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +19 Проголосовать: не нравится

    I'm guessing something like

    6
    1 -1 2 1 -1 -2
    

    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.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Lol, I did same thing((( I think smth like this: 1 -1 2 1 -1 -2

»
4 года назад, # |
  Проголосовать: нравится +37 Проголосовать: не нравится

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 :(

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +33 Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Поспешишь — людей насмешишь ©задача B

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

Got FST in B WA 33 :/ Can anyone go through and tell what silly mistake did i do?

https://codeforces.com/contest/1253/submission/65188326

thanks

got it simple silly mistake

»
4 года назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

Fastest editorial I've ever seen

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

please what's wrong with my solution to B?

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Thanks hugopm !

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

I can relate with B's name .

Worst Mistakes I have done in a while (just missed both B and D).

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain their idea for problem E using Segment tree?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    The inner min query of DP transitions can be converted to segment tree, though it's unnecessary.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Create segtree of size m+1. You start index 0 with cost 0, and indices 1...m with cost inf. Then we iterate through each antenna i in increasing order of position. Now we iterate through all possible sizes j for antenna i, such that it reaches interval [i-j,i+j]. The cost, denoted by cst, for this interval is max(0,j-s_i). Now we add this interval in the following way: we find the min cost x on interval [i-j-1,i+j] and then set index i+j to cst+x. In this way, we are "extending" the configuration from [0,i-j-1] to [0,i+j]. Now answer is index m in segtree.

»
4 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

Thanks hugopm for the round and congrats for reaching GM!

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +18 Проголосовать: не нравится

My rating before the round: 2032 Expectation: +68 (Master) Reality: -68. Expectation + Reality = 0.

»
4 года назад, # |
  Проголосовать: нравится 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?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    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!

»
4 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

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.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone please fix the tags for problem A? It seems that somebody had been spamming every single tag available on that problem.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

some people copy from ideone and pretend that they are smart.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

why they didn't give ratings till now?