By PikMike, 11 days ago, translation, In English,

Hello Codeforces!

On May/15/2019 17:35 (Moscow time) Educational Codeforces Round 65 (Rated for Div. 2) will start.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given 7 problems and 2 hours to solve them.

The problems were invented and prepared by Roman Roms Glazov, Adilbek adedalic Dalabaev, Vladimir Vovuh Petrov, Ivan BledDest Androsov, Maksim Ne0n25 Mescheryakov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.

Good luck to all participants!

Our friends at Harbour.Space also have a message for you:

Hello Codeforces!

We are collaborating with an external sponsor who is offering a unique scholarship opportunity for women who want to study Cybersecurity or Fintech, both for Bachelors and Masters level.

The scholarship includes:

  • An up to $10,000, one-time financial award, paid to the University
  • An all-expenses-paid trip to the EMEA Summit 28-30 October, 2019 in Berlin
  • A Cybersecurity professional to serve as an industry mentor

Apply before May 30th and Harbour.Space will also consider you for a scholarship from our own funds.

Don't miss this chance to study with us in Barcelona!

If you have questions about the scholarship, please contact us at hello@harbour.space!

APPLY HERE→

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 Radewoosh 7 174
2 mnbvmar 7 183
3 I_love_Tanya_Romanova 6 119
4 Farhod_Farmon 6 124
5 xiaowuc1 6 142

Congratulations to the best hackers:

Rank Competitor Hack Count
1 algmyr 57:-1
2 mnbvmar 16:-2
3 xavier_cai 11:-1
4 halyavin 10:-3
5 avm 7
291 successful hacks and 306 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A Dalgerok 0:01
B Farhod_Farmon 0:05
C DieOrBreakout 0:04
D nuip 0:10
E Farhod_Farmon 0:23
F ugly2333 0:13
G Dukkha 0:57

UPD: Editorial is out

 
 
 
 
  • Vote: I like it  
  • +97
  • Vote: I do not like it  

»
11 days ago, # |
  Vote: I like it +1 Vote: I do not like it

Will there be a scholarship for men also?

  • »
    »
    11 days ago, # ^ |
      Vote: I like it +96 Vote: I do not like it

    No, but if you tell them you identify as a female, you'll get in.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +32 Vote: I do not like it

    Hey ElegantSound ! We have scholarships for both men and women and we post about them regularly on Codeforces! If you are interested in one, you can apply on our website! Everyone applying to the university is taken into consideration for a scholarship and no separate application is required.

»
11 days ago, # |
Rev. 2   Vote: I like it +32 Vote: I do not like it

Is he considered as a woman ?

»
11 days ago, # |
  Vote: I like it +231 Vote: I do not like it

Educational round logic :D

»
10 days ago, # |
Rev. 2   Vote: I like it -12 Vote: I do not like it

Seems this round will be started before publishing division 3 rating change xD

»
10 days ago, # |
  Vote: I like it +11 Vote: I do not like it

Rmind:Educational round correspond the third category in System problem something and i hope Reconciliation to All Participants

»
10 days ago, # |
  Vote: I like it -28 Vote: I do not like it

wait this round is dedicated to women? Then I guess its a div 4 guys shit.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Good luck to everyone!

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I have no experience of rating adding in edu round :(

»
10 days ago, # |
  Vote: I like it +11 Vote: I do not like it

hope to become an expert = =

»
10 days ago, # |
  Vote: I like it -15 Vote: I do not like it

What's the difference between Div 3 Rounds and Educational Rounds besides the rating limit?

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Problem difficulty. Div. 3 problems are generally easier than Educational rounds.

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it -38 Vote: I do not like it

      I do not agree with you my friend.

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it +6 Vote: I do not like it

        I do not agree with you my friend.

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        Div 3 are full of greedys!

        • »
          »
          »
          »
          »
          10 days ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          That's accurate, no doubt about it, but it doesn't mean dificulty in Div 3 problems is lower, at least the way I perceive it.

          • »
            »
            »
            »
            »
            »
            10 days ago, # ^ |
            Rev. 2   Vote: I like it 0 Vote: I do not like it

            You have compete in so much CF rounds . If we take into account what I see is you have solve max (3) problems in Educational rounds sometimes (1) and if we look into Div 3 most of the time you solve (4) problems.I am not saying that div3 rounds are so easy but it is easier than Educational rounds and you prove most of the time by solving more problems in Div3 if we compare with educational.Rest is up to you.:P

»
10 days ago, # |
  Vote: I like it +8 Vote: I do not like it

Typo perhaps? Paid by the University not to the.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I have submitted for B around 10 times it says idleness limit exceeded please help

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    flush the print. You can read the linked page, given in problem.

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Why were you guys here during the contest, lol?

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        I stuck at C so was taking a break. Still trying to understand why it is timing out. Perhaps it would be better if I jumped to D instead of coming here :)

        • »
          »
          »
          »
          »
          10 days ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          Are you using Union Find?

          • »
            »
            »
            »
            »
            »
            10 days ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I was using DSU with weighted Union Find. Got WA though :(

          • »
            »
            »
            »
            »
            »
            10 days ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Kinda, I created disjoint sets and then calculated connected components. Worked fast with my random N=500k test. Here is the solution.

            • »
              »
              »
              »
              »
              »
              »
              10 days ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Hmm. Python :/

              • »
                »
                »
                »
                »
                »
                »
                »
                10 days ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                It looks like my solution has a problem with cycles. I created a big sample, when I set M to 20000 it returns result in 0.2 secs but when set to 30000 it loops forever. let me convert it to a proper Union Find.

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can you tell what i did wrong in this code 54197918

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        You're using flush after second cin, not sure it effects something but delete it. In you first query you're sending "? 1 1", that returning a[1]*a[1], you need to add sqrt of that value to v (first v.pb(x)). One more thing, your solution is too crowded for that problem. After finding first number you can easily find others with a simple approach.

»
10 days ago, # |
  Vote: I like it +3 Vote: I do not like it

Any hint for E and F? I think F can be solved by divide and conquer, but I don't know if my idea is correct..

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    I think E is related to finding the inversions in the array but couldn't improve the time complexity from O(n^2)

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You can use 2 pointers because it is monotonous. I used binary search and got WA on test 57 but not sure if the method is wrong or i have a bug.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For E: Fix l, starting from 1 to x. The idea is similar to 2 pointers and you will need some precomputated arrays.

  • »
    »
    10 days ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    Precalculate p[x] = are numbers <= x sorted, s[x] = are numbers >= x sorted, l[x] = max number <= x, f[x] = min number >= x, you can check if (l, r) is good in O(1), just do binary search.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +16 Vote: I do not like it

    F is just counting the coefficient of each $$$b_i$$$. You can process the $$$b_i$$$'s in sorted order and use a BIT to efficiently count how many terms smaller than your current $$$b_i$$$ are in a range, and their contribution to the coefficient.

    • »
      »
      »
      10 days ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Actually there are $$$O(n^2)$$$ range pairs, and I got stuck on this ranges. I try to consider left range and right range separately, but I cannot figure out how to count that for each i efficiently.

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it +29 Vote: I do not like it

        Say you're processing the ranges containing $$$a_i$$$. These are $$$[l, r]$$$ with $$$l \le i \le r$$$. If $$$a_j < a_i$$$ and $$$j < i$$$ then you add $$$1$$$ to the coefficient for each of the ranges that contain $$$a_j$$$. The right endpoint doesn't matter, so for each right endpoint $$$a_j$$$ is contained in $$$j$$$ ranges, and the total contribution to the coefficient is $$$j \cdot (n - r + 1)$$$, the latter being the number of right endpoints. You can get a similar expression for $$$a_j < a_i$$$ and $$$j > i$$$. To query efficiently you can build a BIT that allows you to get the sum of $$$j$$$ for $$$a_j < a_i$$$ and $$$j < i$$$, and another one for the right side. Then when you finish processing an element, you add it to the BIT.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

please anyone show his code for problem B in c++14 PLEASE...

  • »
    »
    10 days ago, # ^ |
      Vote: I like it -6 Vote: I do not like it

    Here you are: 54185189

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    code for B

    The queries are a1*a2 a3*a4 a1*a3 a5*a5,It is possible to deduce a1 a2 a3 a4 from the first three queries and we got a5 by asking a5*a5, Then the array can be determined uniquely.

»
10 days ago, # |
Rev. 2   Vote: I like it +2 Vote: I do not like it

Has someone's nlog^2n in E passed? I kept getting TLE on test 6. I binary searched the r for each l. Edit: Passed after I dropped a logn.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I was thinking on similar lines but wasn't that n^2 logn? How fast do you test if a particular l,r is valid?

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      No that is not n^2logn. What you are thinking is to check all possible (l,r) pairs whether it gives non-ascending array or not. Correct idea would be to get minimum r (using bs and some preprocessing) for each possible l (1..n) and adding n-r to the ans.

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      No, what I did was to fix a particular l. Then calculate the first 'r' such that [l, r] is valid. Then added n — r + 1 to the answer. Check my code here. I maintained the max prefix and suffix till the array is sorted for calculation.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve B?

»
10 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Hello, I tried solving problem C and I was getting runtime error on test 3. I could not find the error, can someone help me please? Here is my code: http://codeforces.com/contest/1167/submission/54204878

»
10 days ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

What is test 57 on problem E?

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Test cases visible now

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    10 1000000 404504 367531 741030 998953 180343 781888 161191 855804 689526 976695

»
10 days ago, # |
  Vote: I like it +21 Vote: I do not like it

What's with the super tight bounds in F? My O(n log n) solution takes 1996/2000ms. 54195181

Happy hacking :P

»
10 days ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

My code WA test 1???? 54208002

check the answer on CodeBlacks why this code Run on Codeforces get "WA" and this test example is test one !!!

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

The problem D inputs by "cin" will get "WA" ,replace "scanf" get "AC" ,why??

»
10 days ago, # |
Rev. 2   Vote: I like it -20 Vote: I do not like it

among 8 div2 participants eho is better than me 7 of them are fake accounts. it is unfair lol i should be the 2nd, not 9th

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

[submission:54208002]This code "WA" test 1???

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Is in problem E wrong to do binary search? Isn't it the same as 2 pointers?

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

What a pity! For E, cin/cout got a TLE while scanf/printf passed.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Input/Output speed is not a problem because I also used cin/cout in E and pased. You just need to add ios_base::sync_with_stdio(0) to make cin/cout as fast as scanf/printf.

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Thanks very much. Indeed, with sync_with_stdio(0) my solution passed. But it still has a gap with scanf/printf.

      For cin/cout with sync_with_stdio, it takes 1606 ms. While for scanf/printf, it takes 1278 ms.

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        Try using cin.tie(0); cout.tie(0) It is usually faster than scanf/printf

        • »
          »
          »
          »
          »
          9 days ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thanks!

          But for this problem, it still takes 1578 ms, not as fast as scanf/printf.

»
10 days ago, # |
  Vote: I like it -15 Vote: I do not like it

C and D were easier than B.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Why did my solution to problem D gave TLE: code

Removing stack and converting string to character array passed the pretest. Don't know why..

  • »
    »
    10 days ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    Because adding two strings is linear to their length. If you just push the char in the end is O(1). Changing it with += that equals to push_back it gives acc 54211273 (your sub with this change)

»
10 days ago, # |
  Vote: I like it -21 Vote: I do not like it

Authors should have announced that there will be interactive problems in the contest beforehand.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    Why?

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Many of Division2 participants didn't have any idea about interactive problems (I am also one of them). Because usually div2 contests doesn't contain this type of problems. To know and learn about them all on a sudden in a running contest is taught and time consuming.

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it +13 Vote: I do not like it

        There is nothing to learn, interactive problems don't differ much from usual problems. My first interactive problem was on NEERC 2010, I had green level then but I solved it without any difficulties. I don't understand why so many people are afraid of interactive problems.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Any hacks available for problem (B) ?

»
10 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Thank you creators for such cool problems. I really enjoyed it.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

why this solution(54181282) is getting wrong answer on testcase 2?

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    Wrong output

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    The line producing the error is probably this:

    for(i=s.size()-11;i>=0;i--)

    s.size() returns an unsigned int and if s.size()<11, s.size()-11 will underflow and take a value of the order 2^32.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For s with length less than 11

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Is it possible to solve C with a method other than Union Find?

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it
»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Why was problem b hacked?

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Because according to your method, the fourth and fifth Numbers can switch places

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    因为你第四个数和第五个数可以换位置拉。

»
10 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

why this https://codeforces.com/contest/1167/submission/54206553 is getting runtime error ?

I did it like the blog example :(

using same code but with cout<<flush is accepted

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

is D the simple stack implementation ?

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You can also solve it recursively, by using the fact, that all valid sequences S = (A)B, or empty.

    54212912

  • »
    »
    10 days ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Yes. Actually, you just have to invert the color before processing a '(' and after processing a ')'.

    • »
      »
      »
      10 days ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      @MMXIX can you explain your approach in detail,and how does reverting colors gives us required answer

      • »
        »
        »
        »
        10 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        You have to minimize depth, so as you encounter two same brackets in sequence invert your color . This will minimize the depth.Simple greedy approach.

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks for your comment. I did this in the same way and got accepted but I was in doubt as it 'D' problem.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Was O(N logN) supposed to pass on E? I got TLE on test 50 with such an approach. If it was intended to pass, why set the bound as high as 1e6?

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    There are O(N) solutions using 2 pointers. However, I think only simple O(NlogN) solutions passed (binary search).

    • »
      »
      »
      9 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I used bs and got WA on test 57. Still can't understand what's wrong.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I don't know what is the hacking format of interactive problems.

Somebody help me with an example,please.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

The problem B could be more interesting if the number of elements would be greater.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yeah, it would have been better if the number of permutations were too large for all of them to be checked.

»
10 days ago, # |
Rev. 2   Vote: I like it -13 Vote: I do not like it

xx

  • »
    »
    10 days ago, # ^ |
      Vote: I like it -13 Vote: I do not like it

    memset gives wrong answer and loop initialization got Accepted.

  • »
    »
    10 days ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    sizeof(vs) is a constant value, you have to multiply it by the size of the array.

    Correct command would be memset(vs, false, sizeof(bool) * (n+1)) because type of elements in the array is bool. sizeof (vs) will typically be larger (8 bytes) than sizeof(bool).

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    vs is a pointer, sizeof a pointer is generally 4 bytes (8 bytes for x64 compilation).

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone explain their approach of solving problem D?? I am not able to make up any thoughts about it

  • »
    »
    10 days ago, # ^ |
    Rev. 3   Vote: I like it +4 Vote: I do not like it

    let r0 be the nesting of string with color 0, similarly define r1.

    Initially, r0 = 0 and r1 = 0.

    now ,each time you encounter an opening bracket, if r0<r1, color this bracket 0 (also increment r0)else color this bracket 1 (also increment r1).

    Similarly, each time you encounter a closing bracket, if r0>r1, color this bracket 0 (also decrement r0)else color this bracket 1 (also decrement r1).

    This guarantees that both strings will be balanced bracket sequences because r0+r1=nesting of original string =0 and r0 or r1 can't be negative (because we ensured it in the loop above) so r0=0,r1=0.

    This also guarantees that max nesting is minimised because only the min is incremented when encountering an opening bracket (always better than incrementing max) and the max is decremented when encountering a closing bracket (always better than decrementing min).

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can you explain the proof a little briefly? , it is a nice approach.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone please explain approach to question D??

»
10 days ago, # |
  Vote: I like it +85 Vote: I do not like it

The judge doesn't judge.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Why is Codeforces so slow after every contest? My past 3 submissions in the virtual contest have not been judged.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

What is the approach for F?

  • »
    »
    10 days ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    For fixed i, find all j's with (a_i >= a_j), then answer will be the sum of min(i + 1, j + 1) * max(n — i, n — j). Go through i's in increasing order and maintain several fenwick trees.

»
10 days ago, # |
  Vote: I like it +10 Vote: I do not like it

I'm very confused. Can someone please explain how to solve E? I have been reading multiple AC solutions but still can't understand the idea behind that!!

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Save the maximum index and the minimum index of each different elements in a. Then think of how to judge a f(l,r) is valid or not in O(1)

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem C, I'm using DFS and getting a TLE in 7th test case. Can anyone help?

  • »
    »
    10 days ago, # ^ |
    Rev. 2   Vote: I like it +2 Vote: I do not like it

    Maybe you are not building the graph in an efficient way. Suppose you have 2 5 7 9 Then you don't have to do

    2->5->7->9
    5->2->7->9
    7->9->5->2
    9->2->5->7

    Instead do something like
    2->5
    5->7->2
    7->9->5

    You don't need to make exact graph as you only have to count connected components.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    you can skip visited groups

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

It would be nice, if someone please explain me the problem C using sample Case. I didnt figure out it yet for a while xD. Thanks in advance <3

  • »
    »
    10 days ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Lets take first case there are 5 groups and 7 people. Each of 5 rows starts with some number that means how many people in Ith group. For example in first group 3 people with number 2, 5, 4 and so on. And problem says if person sends news, their friend can also send info to their friends. After this if person in this group he can share news to this friends and if this friends in other groupes they can share news to other friends in that groupes. At the end we can say that we need to find every component and people in this component can share info with this size of component(including himself). First case if we take person with number 1 he is in two groupes {1, 2} and his friend 2 is in group {2, 5, 4} and if we add this two groups its {1, 2, 5, 4} everyone can share new with themselves that means 4 is the component size. You can solve this problem with dfs or dsu)

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You said: "First case if we take person with number 1 he is in two groupes {1, 2} and his friend 2 is in group {2, 5, 4} and if we add this two groups its {1, 2, 5, 4} everyone can share new with themselves that means 4 is the component size."

      But My point is it should be.. if we take person with number 1 he is in two groupes {1, 2} and his friend 2 is in group {2, 5, 4} and{2, 6, 7} and if we add this three groups its {1, 2, 5, 4, 6, 7} everyone can share new with themselves that means 6 is the component size." Can you please clear my confusion. Thanks xD <3.

      • »
        »
        »
        »
        10 days ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        2 6 7 doesnt mean fifth group contains {2, 6, 7} first number means how many people in this group, in this example 2 people in fifth group with numbers {6,7}

        • »
          »
          »
          »
          »
          10 days ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Oh hoooo. Thats clearly show how bad I am in problem statement reading. But Thanks a lot xD. Take love <3

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

could you help me check where is wrong? ID:54220798

»
10 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In E, is it okay to find the max l value and min r value such that l<=r , and f(l,r) is valid. Then we know that f(l-k1,r+k2) is also valid for all possible values of k1 and k2.

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    That is true but not enough. For example, leaving one element only inside leaves array sorted, if l != r, then we can leave l + 1

    • »
      »
      »
      9 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      couldnt understand

      • »
        »
        »
        »
        9 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I mean, what if l = n and r = 1. Which max l value and min r value do you choose? If you iterate all, then you count some segments several times.

        • »
          »
          »
          »
          »
          9 days ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          but l<=r

          • »
            »
            »
            »
            »
            »
            9 days ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            What about this case. 1 4 2 5. f(4, 4) = 1 2 5. it is valid and we cannot make l bigger or r smaller, because then l > r. So you are saying that all f (4 — k1, 4 + k2) are true for positive k1 and k2, as I can tell. Well that is right. But we also have f(1,2), for example -> 4 5. And it is not of this form, 4 + k2 = 2 so k2 is negative.

            • »
              »
              »
              »
              »
              »
              »
              9 days ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Oh, I understood. So you mean that 4-k1 and 4+k2 is correct but it leaves out other cases... because l is unable to become greater than 4 and r unable to become smaller than 4.... Is this what you meant?

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Why using Dfs to get number of nodes in each connected components gives wrong https://codeforces.com/contest/1167/submission/54223559

  • »
    »
    10 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You are assigning the value of c to val[i] while running dfs, c being the number of connected components, this doesnot ensure that the parent of all these components is 'i' and therefore the answer is coming out to be less than than the actual number of components. Just a little bit of change and there you go..!!! 54225792

    PS-- This might give you TLE in system tests as you have not used weighted dsu.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Hope that I can reach 1600, it is only 12 ratings away but it seems that I am not performing well this time... Btw I really appreciate problem B as an interactive task, as we don't get to meet them often and this is a great opportunity to train up skills related to interactive tasks.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I'm new here. Are these contests are Python friendly? Most people solved C with Union Find in C++ and passed the tests, but the same algorithm in Python gets TLE

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In div2 and div3 (and most div1) problems can be solved with Python. With medium plus problems, if there is too much list reading or query you will need Pypy3. There are lots of difficult problems looks impossible with Python but we're far away from them (I'm trying to solve some of them on Codechef and even with 5x time limit it's still a big challenge, my current problem). And here Python solution for C: link

    • »
      »
      »
      9 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks, the key was to change input() to sys.stdin.readline() https://codeforces.com/contest/1167/submission/54233244

      Anyway it's strange that the time limit for python and c++ is the same number.

      And why do you need work with stdin? In real life in 99% you need to write class of function, so why not just give a prototype of the function or class that you need to implement?

      def solution(n: int, m: int, lines: List[int]) -> List[int]:
          """
      
          :param n: number of users
          :param m: number of groups
          :param lines: number of users in group + users in group
          :return: the number of users that will know the news
          """
      

      Sorry for my questions, I'm new here.

      • »
        »
        »
        »
        9 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Actually you're right about writing a class of function, but here I most time coding what I need for current problem. I'll use libraries if I go up in rank :) For stdin, I only use it when there is lots of reading like in that problem.

        Don't worry about time limit, it's something classic CP thing but Codeforces gives extra time for problems. You'll start to need C/C++ solutions if you become a Div1.

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    See solution of @algmyr he passed the problem probably with union find

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I wonder when I can see the ratings changing...

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Easy busy contest

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Why Radewoosh's submit 54183325 didnt get TLE? In his solution (sorry for my poor English) he didnt use rank's heuristic and got AC. I tried to submit solution without rank's heuristic and got TLE 54233682 . Could someone help handle it, please?

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    And im about problem C.

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Because he used a technique called 'Path Compression'.

  • »
    »
    9 days ago, # ^ |
    Rev. 2   Vote: I like it +7 Vote: I do not like it

    In his code

    int fin(int v)
    {
      if (v!=oj[v])
        oj[v]=fin(oj[v]);
      return oj[v];
    }
    

    not

    int fin(int v)
    {
      if (v!=oj[v])
        return fin(oj[v]);
      return oj[v];
    }
    

    So after a fin(v) operation, the nodes on the path from v to the root will all directly connect to the root.Therefore, when you perform fin(i) (i is a node on the path from v to root) will just return oj[i]

»
9 days ago, # |
  Vote: I like it +12 Vote: I do not like it

Wait for tutorial

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I have passed problem G, but I have no idea whether my solution has a right complexity.

My solution is 54235792. It uses a method similar to two-pointer to find the nearest pair that is the same far from point x.

Could someone please tell why it's correct or construct a data that will lead to a TLE?

»
9 days ago, # |
  Vote: I like it +15 Vote: I do not like it

I got compilation error on problem D during system test after it passed during the contest? How is that? :D

54189857

»
9 days ago, # |
Rev. 2   Vote: I like it +15 Vote: I do not like it

Here is my $$$O(N)$$$ solution for problem E: 54241182

The general idea is to maintain, first of all, a global rightmost $$$L$$$ and a global leftmost $$$R$$$ such that ranges $$$[1,L]$$$ and $$$[R,X]$$$ are valid, then for each $$$r$$$ the rightmost $$$l$$$ such that the union $$$[1,l] \cup [r,X]$$$ is valid too.

»
9 days ago, # |
Rev. 2   Vote: I like it +2 Vote: I do not like it

Used DSU for problem C, got WA test 3 and I cant find the mistake, can anyone help? 54184178 Edit: Found the error, I was not checking if nodes are already connected before connecting them.

  • »
    »
    9 days ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    same for me.
    then I used dfs and it got ac.
    I don't know what is the mistake.

  • »
    »
    9 days ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    I also got WA test 3. You should check in your connect function that you don't connect the same element.

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Hello, I tried solving problem C and I was getting TLE error on test 3. Somebody please help in optimizing my code. I didn't get the editorial properly. Here is my code: https://codeforces.com/contest/1167/submission/54269390

  • »
    »
    7 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The answer is the same for vertices in same connectivity component. You dont need to clean the array.

»
8 days ago, # |
  Vote: I like it +4 Vote: I do not like it

How to solve problem G?

»
7 days ago, # |
  Vote: I like it 0 Vote: I do not like it

can any one explain E problem please ?

»
6 days ago, # |
  Vote: I like it 0 Vote: I do not like it

problem D, solution1 got accepted whereas solution2 gave TLE. The only difference between the two is in line number 21. In solution1 we append 0 in string by res+='0'. In solution2 we append by res=res+'0'. I thought these two operated the same way. Can someone give insight to the reason?

»
2 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Someone please help me with problem C. I am getting MLE. Any help would be appreciated. https://codeforces.com/contest/1167/submission/54526141