Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×
Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

vovuh's blog

By vovuh, history, 5 years ago, translation, In English

UPD: Thanks to Daria nooinenoojno Stepanova, Mikhail awoo Piklyaev and Artem Rox Plotkin for help with round preparation!

UPD2: Editorial is published!

<almost-copy-pasted-part>

Hello! Codeforces Round 595 (Div. 3) will start at Oct/22/2019 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

  • take part in at least two rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round.

Good luck!

I also would like to say that participants who will submit wrong solutions on purpose and hack them afterwards (example) will not be shown in the hacking leaders table.

</almost-copy-pasted-part>

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

| Write comment?
»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it
»
5 years ago, # |
Rev. 2   Vote: I like it -15 Vote: I do not like it

I wish you all good luck

»
5 years ago, # |
  Vote: I like it -10 Vote: I do not like it

hope this contest becomes my last official participation in DIV3.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I hope become pupil

»
5 years ago, # |
  Vote: I like it -11 Vote: I do not like it

Good luck to everyone. I hope this round will be an exciting contest without dots attacks and lots of hacks. Finally I hope the problems will be solvable and understandable.

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

Div-3 is Love... True Love... Pure Love...

»
5 years ago, # |
Rev. 3   Vote: I like it -12 Vote: I do not like it

Love Vovuh's Contest

»
5 years ago, # |
  Vote: I like it +34 Vote: I do not like it

Fitness challenge: I'll do one pull up for every rating point lost and I'll do 3 pushups for every point won. Feel free to join the challenge under your conditions.

»
5 years ago, # |
  Vote: I like it +11 Vote: I do not like it

I think you should take part in some contests to become master. It's more beautiful ^^

»
5 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Why Div3 get so little upvotes :(

Are we just used to them?

»
5 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Which problem has two subtasks? @vovuh

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +40 Vote: I do not like it

    Look, I really don't think it is important information before a round. I prefer vovuh will spend time improving problem statements and tests.

»
5 years ago, # |
  Vote: I like it -45 Vote: I do not like it

Why do Vovuh conducts only Div.3? I don't like him.

»
5 years ago, # |
  Vote: I like it +22 Vote: I do not like it

Hi! I decided to simplify one of the problems and divided it into easy and hard versions. That's why I increased the round duration to 2:15. Don't afraid of formally too many problems in the round. You shouldn't think about easy/hard versions as about two independent problems. And good luck!

  • »
    »
    5 years ago, # ^ |
      Vote: I like it -11 Vote: I do not like it

    Very good idea to divide problems into parts. Sometimes, even after solving the problem, it requires additional data structures or optimizations. This way even partially correct solutions that are slower than intended get partial points.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Another idea is creating one problem with different types of tests. Solutions can first get tested on small tests, and then on bigger numbers. And if it passes small tests, contestant can get partial verdict. This has been done in several rounds, to it is possible. It is just easier to navigate this way, instead of solving 2 same problems

»
5 years ago, # |
  Vote: I like it +18 Vote: I do not like it

I will AK this contest !

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Vovuh, the half-quarter!

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Good luck!

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

I want to improve myself~

»
5 years ago, # |
  Vote: I like it +23 Vote: I do not like it

There's an expert participant in the trusted participants rankings, by the way.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +22 Vote: I do not like it

    That's probably because he registered to the contest before he became Expert, so he was marked as an official participant.

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

    His rating was updated too.

»
5 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Contest is over. It was a good contest.

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

I solved 7 problems for the first time. Feel amazing >__< !!

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

    I solved 6 but still. Which 6 did you solve?

    I didn't solve D1, D2 and F. Is D1 just straight bruteforce? I didn't try because it seems like it'll be something like O(n^4) :(

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I believe you can see his submissions

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Oh ye. Problem E is awesome, I tried a dp-greedy method and it worked. I can't even convince myself that it is true, but complexity-wise it passed.

        dp[i][elevator?(bool)] = Minimum total time to reach ith floor, with last move taking the elevator (or not, depending on the bool)

        dp[1][false] = 0, dp[1][true] = c

        dp[i][false] = min(dp[i — 1][false], dp[i — 1][true]) + a_(i — 1)

        dp[i][true] = min(dp[i — 1][false] + c, dp[i — 1][true]) + b_(i — 1)

        output *(min(dp[i]) for i in range(1, n + 1))

        Can someone prove this .-.

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 7   Vote: I like it 0 Vote: I do not like it

      Ummm I used Segment Tree with Lazy Propagation for D1 & D2. (Segment Tree is really useful >__<!!

      But I think there will be more easy way (maybe)

      I thought adding Persistent Segment Tree for D2 at first, but I'm so scared to coding it, fortunately it was solved by priority_queue.

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

    I solved 7 problems too. I wish this contest is rated.

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

      I hope we can all be Blue-coder Kkkk

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yes.I'm looking forward to rating update.

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

Can somebody explain test case 2 in F?

Thanks

»
5 years ago, # |
  Vote: I like it +2 Vote: I do not like it

How to solve C2 ?

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

    It's just ternary numeral system.

    My solution:

    precalculate all values 3^n (0..38 powers), it's 100..000 preseentation of number

    next I check first X that 3^0 + 3^1 + ... + 3^X (presentation of 111..11) >= n, if yes subtract from n 3^X, and add to result same number

    do while n > 0

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      What about n = 10^18? In the first test the answer is 1350851717672992089, but 3^38 > 10^18 and less than test's answer

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

        You are correct (10^18 — 3^38) < 0 and loop stopped.

        But first I compare with (3^39-1) and subtract (3^(39-1))

        upd: sorry, not 3^X-1, but 3^0+3^1+..+3^X and if this value greater or equals than n I subtract 3^X from n and add to result

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

How to solve D2?

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

    I solved it using line sweep algorithm. Iterate through the points [1,2e5]. Keep a set that includes current line segments. Whenever you find a condition where the number of line segments exceeds k in the current set, remove the line segments which have higher ending point.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

What was test case 14 of D1?

Also, how where you supposed to solve D2? I thought using a BinaryIndexedTree, but I wasn't sure how to implement.

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

What is Test 11 for Problem E?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Isn't Meet in the Middle expected solution for C2. My solution got TLE on test 7

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    while (q--) {

    } isn't a good idea when q can be 10^18

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

    I have greedy solution with prefix sums

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

    Hey !

    This is not a Meet In The Middle problem. In fact the intended solution doesn’t require bitmasks at all.

    Here’s what should be done

    • Write the number in ternary base
    • Look for the leftmost $$$2$$$
    • Look for the nearest $$$0$$$ to the left of the $$$2$$$
    • Set the $$$0$$$ to $$$1$$$ and change all positions to its right to $$$0$$$
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I solved only 2 problems. Will my rating will increase or decrease? The problems were easy but I couldn't cope up with the constraints leading TLE

»
5 years ago, # |
  Vote: I like it +17 Vote: I do not like it

How to solve F?

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

    dp on tree

    dp[i][j] is the max sum can be obtained from the subtree of vertex i

    with the nearest picked vertex from this subtree is at distance j from vertex i

»
5 years ago, # |
  Vote: I like it +13 Vote: I do not like it

I think this round is easier usual Div 3 round.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Any Penalties on Unsuccessful Hacking Attempts?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Don't know because there was no points table shown like other Div.1 and Div.2 contests. Even which problem contains how many points is also unknown.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      There is no any fixed scoring distribution in Div3 rounds.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    no

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The moment I realized that the comparator used by me is wrong in D1/D2 after printing all the values for an hour...........

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone tell me why this code gives TLE? 63189145

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    this is fixed code. 63190824 when you call functions, vector<vector > v would be copy. it makes tle.

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

What's wrong with this solution for F — dp[node][level] = answer for subtree rooted at 'node' such that among all selected nodes the smallest depth is at 'level'? This recieved WA-3

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

After seeing constraint I thought greedy won't work for C2 so wasted one hour to implement Bit Mask+ Meet in the middle.Lesson learned. -_-

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My Meet in the Middle got TLE on test 7

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can you describe better, what was your Idea behind meet in the middle algorithm?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Divide the powers of three into two vectors. Then each vector contains all possible numbers which contain distinct powers of three. Iterate through the first vector and binary search on the second vector for number >= (n — number in first vector ).

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Don't divide power of three into two vectors of almost equal size, try keeping powers from 0-15 in first one, and 16-38 in second one (i.e one you use in binary search).

»
5 years ago, # |
Rev. 3   Vote: I like it +16 Vote: I do not like it

My solution for $$$F$$$:

Root the tree at node $$$1$$$. Let $$$dp[i][j]$$$ be the maximum subset weight for the sub-tree rooted at node $$$i$$$ if the nearest node in the subset to $$$i$$$ is at distance $$$j$$$ from it. Let $$$mxdp[i][j]$$$ be $$$max(dp[i][k])$$$ for $$$k$$$ from $$$j$$$ to $$$n$$$.

How to fill $$$dp$$$?

$$$dp[i][0]=a[i]+\sum_{c}mxdp[c][k]$$$ where $$$c$$$ is every child of $$$i$$$.

$$$dp[i][j]$$$ (for $$$j$$$ from $$$1$$$ to $$$n$$$) $$$=max(dp[c_1][j-1]+\sum_{c_2!=c_1}mxdp[c_2][max(k-j,j-1)])$$$ where $$$c_1$$$ is every child of $$$i$$$, and $$$c_2$$$ is every other child of $$$i$$$.

The answer is $$$mxdp[1][0]$$$.

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

In D why remove segments from longest to shortest length is wrong?

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

    Imagine three segments [1, 1000] [1001, 2000] and [1000, 1001] and k = 1. There are two points that have k = 2 : 1000 and 1001. If you remove longest segments, then you will need to remove both of the big ones. In another case, you can just remove the third one and m = 1

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

how to solve B2?

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

    use dfs, to travel continuously until u get end point of cycle.then update all the travelled value to max distance you have travelled until now.see my code.submission

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You could use disjoint sets too... Just put i and arr[i] in same set (union) and like size find size of each set, the answer is same for all the elements in the same set, ie, size of the set.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it
 ll n;cin>>n;ll temp=n;
        int idx=0;ll mn_diff=LONG_MAX;
        while(psm[idx]<n)idx++;
        // dbg(pt[idx]);
        for(int cnt=idx;cnt>=0;cnt--,idx--){
            mn_diff=min(mn_diff,pt[idx+1]-n);
            if(n>psm[idx])break;
            if(n>=pt[idx])n-=pt[idx];
            if(n==0)mn_diff=0;
        }
        cout<<temp+mn_diff;nl;

i was getting wrong answer using mn_diff=LONG_MAX, is it wrong to use LONG_MAX for std::min function in c++, but also it gave correct answer on my compiler.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    LONG_MAX gives you a "long long" value, but you are storing it in an "int".

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      no when i used mn_diff=1e18 it gives AC

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

        1e18 is different that LONG_MAX. Both will give you different values, and if you don't store that values in a "long long", LONG_MAX can give you a negative value and 1e18 can give you a positive value (depends on the compiler).
        Sorry for my poor english xd
        ex:Codeforces submission
        Ideone submission

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          but i never used int, u could see above its long long.

          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Sorry, I didn't see the "ll" :c Your code on my compiler prints the correct answer too.

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

    UPDATE :: never use LONG_MAX on codeforces as LONG_MAX is same as INT_MAX on Windows, and codeforces uses 32 bit windows, so always use LLONG_MAX it is universal (2^63-1).

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

For problem E, could anybody tell me why PyPy 2 TLEs but PyPy 3 ACs?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    because Python 3 is much faster than Python 2 (especially more recent versions)

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Python 3 is still slower than Python 2 on most counts, especially in competitive programming.

      It seems like it's only PyPy 2 that's slow. Even Python 2 ACs.

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

    Just added my fast io got accepted in PYPY2 . Do check my submission

    https://mirror.codeforces.com/contest/1249/submission/63196194

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Had it helped you ?

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks for making my submission work. I've never seen output buffering in Python like this before, will have to look more into it.

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

My approach for problem D1 is keep removing the segments intersecting with maximum number of bad points .Is this approach correct ? My submission is giving wrong answer though My Submission

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I got WA on 9. Switched to iterate from left to right on bad points and keep removing segment with largest end point, and that passed.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Your approach is also nice.Still wondering what is wrong with our first approach .

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

        I found out whats wrong.

        Take the following case

        5 1
        1 2
        2 5
        3 10
        7 14
        14 15

        Here if we try deleting segments with most bad points, we will first delete 3 10, then 2 5, then 7 14. But the correct approach is to delete 2 5, and 7 14.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hack case for B?

»
5 years ago, # |
  Vote: I like it +14 Vote: I do not like it

The problem-set contained better stories than all of my films combined.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it
How to prove this solution ?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem C2

	// Wrong Answer 
	/*
	for(int i = 0 ; i < 40 ; i++){
		my[i] = (int)pow(3LL,i) ;
	}
	*/
	// Accepted Solution 
	my[0] = 1 ;
	for(int i = 1 ; i < 40 ; i++){
		my[i] = my[i-1] * 3LL ;
	}
	//

This is my AC Code 63196491

what is wrong with this line my[i] = (int)pow(3LL,i) ;

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

    Overflow, my[i] can be greater than INT_MAX

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +4 Vote: I do not like it

    pow returns double, which can't represent all values of a long long (think about it: both are 64 bit types, therefore pigeonhole principle etc etc)

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    I could suggest you one thing, if I may.... Don't use inbuilt pow function, it's very deceptive sometimes..... Just to be on the safe side, you could make your own pow function using fast exponentiation....

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

    pow(x) returns double, which is not enough for 1e18. Try using powl(x), which returns long double instead.

    P.S. Both pow and powl are inaccurate, try to avoid using them

»
5 years ago, # |
  Vote: I like it +2 Vote: I do not like it

thanks for this amazing contest :)

»
5 years ago, # |
  Vote: I like it -8 Vote: I do not like it

Sorry for my bad english, but the user named AHR9N has cheated, he asked me for the code of the problem B2, but I did not send. I think he needs to be severely punished

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

Oh,I can't get problem c2,problem c2 and problem e by using m2.codeforces in this contest. It told me that the statement is available.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone give me the solution of Problem B2 using DSU?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In question https://mirror.codeforces.com/contest/1249/problem/A A. Yet Another Dividing into Teams from equation it means that difference should not be 1. Statement says difference should be strictly greater than 1. And test cases are aiming just for difference not equal to 1. There is a bit ambiguity . As for input 1 1 1 1 1 1 Answer should be 5. In test cases answer is either 1 or 2.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    All students have distinct programming skills!

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

    The second line of the query contains n integers $$$a_1,a_2,…,a_n$$$ ($$$1≤a_i≤100$$$, all $$$a_i$$$ are distinct), where $$$a_i$$$ is the programming skill of the i-th student.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Is the round unrated? Why the ratings are not updated ?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Cause you are not rated in this round. You have to participate at least 3 contest in div2.

    and your solution was skipped-- probably you have break any Terms of agreement of codeforces.

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

Problem F is basically the same as BOI 2017 day 2 "Cat in a tree"

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

Edit: I was mistaken, please ignore.

Original message
  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No, distance between any pair of selected vertices should be greater than k

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Oh right, I misread the prose in the problem description and thought there was a contradiction.

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

If I modify problem A to..like find minimum number of teams you can form if no two students i and j such that |Ai-Aj|<=k may belong to the same team (i.e. skills of each pair of students in the same team has the difference strictly greater than k).
So if N be the no of students then I can solve it in O(NlogN + Nk^2). is there ant faster approach if any one can suggest???

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

    Maintain a sorted array. Pick the first element(lets say a), then find the upper bound of a+k. Keep on doing the same thing for this new element until you reach end of array and also maintain the elements which have been allocated a team. Pick the next element in the sorted array which has not been allocated a team yet and repeat the above steps and increment the number of teams. This approach should be O(NlogN).

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      No worst case complexity of your idea is O(N^2) Consider the case of N consecutive numbers with k=N;

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        How?

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

          just apply your idea and see... pick your a(first element of sorted array) in search of a+k (i.e. a+N here) you will traverse the whole array(end of array) but you will not find it.. Note1 you have picked just 1 element in 1 traversal do same for 2nd, 3rd and so on... so N(N+1)/2... O(N^2)complexity……. also Note2 you can't say here for this very case to use binary search(however here may work) bcz in general solution binary search will not work.

          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I won't traverse the whole array. I would just binary search and why would it not work in general?

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

              not work means complexity will become even worst bcz at every such a+k you need to do binary search prev=a; curr=a+k; next a+k+k;..... so on and every time cost is logarithmic time. Also there might be case that a+k doesnot exist but a+k+2 or a+k+5 exist here these will be included in the same partition but then how you will handle those cases using binary search.... Just think once what is your complete idea and check the complexity... once done I will be thankful and love to know that.

              • »
                »
                »
                »
                »
                »
                »
                »
                5 years ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                I think Brute_Forced approach is O(NlogN)

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Why have the rating changes been temporarily rolled back ?

»
5 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Stop naming test cases as "queries", ffs.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This is not the first time you are saying this. But I don't think it makes any difference. It is okay until and unless it is not creating any confusion in the problem statement. Isn't it?

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it -8 Vote: I do not like it

      And it does create confusion because queries usually mean something else.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

So when on earth can our rating be back?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I got plagiarism mail for the following solution coincided https://mirror.codeforces.com/contest/1249/submission/63187125 with another guy solution. However my first accepted solution for this problem was https://mirror.codeforces.com/contest/1249/submission/63184980. So the thing of plagiarism, I guess is completely irrelevant.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Don't use IDEOne for coding.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Is there any way to restore my credits for this round, I was unaware regarding Ideone thing.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Try appealing to the problemsetters and the organizers. I tried a few contests back, didn't help. Now I only use my personal IDE.

»
5 years ago, # |
Rev. 2   Vote: I like it +20 Vote: I do not like it

Is it ok, what a few participants 1600+ rating got it updated after contest?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

i try to solve D1 by using activity selection problem but it gives me WA on test case 14.

so i would do activity selection for K times and of course for each activity selection it will gives you as many as segments which not intersect with each other.

if you do it for K times then you will get points which covered at most K times, i couldn't think the corner case for my solution.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please check my F code. Its failing on the 38th case. https://mirror.codeforces.com/contest/1249/submission/73195435