HolkinPV's blog

By HolkinPV, 11 years ago, translation, In English

Good day)

Welcome to regular Codeforces round #199 for Div.2 participants. As always Div.1 participants can take part out of the competition.

The problems were prepared by authors Pavel Kholkin (HolkinPV) and Gerald Agapov (Gerald). Traditionally thanks to Michael Mirzayanov (MikeMirzayanov) for Codeforces and Polygon systems and Mary Belova (Delinur) for translating the problems.

UPD: Score distribution is standard500-1000-1500-2000-2500.

We wish everyone good luck, high rating and excellent mood)

UPD2: the contest is over, hope you enjoy it)

Congratulations to winners:

1) chixianglove
2) Logvinov_Leon
3) Yoshiap
4) _moonlight

UPD3: the editorial is published here

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

| Write comment?
»
11 years ago, # |
Rev. 2   Vote: I like it +22 Vote: I do not like it

Thanks for the contest!
But Why is the name of Author orange(Master) on the title and purple(Candidate Master) in the text??

Here Master↓
---------------------------------------

---------------------------------------


and here candidate master↓
---------------------------------------

---------------------------------------

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

some copy-paste) fixed

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

You may want to warn everybody about unusual contest time :)

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

Good Morning (:|

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

is this contest difficult? gonna to see the problems you prepared! and waiting for the score distribution now... hope everybody can enjoy this contest and get high rating!

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

Sorry to ask, but is this a rule that there will never be an intersection between CF & TC contests?

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

Good time for Chinese participants:)

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

most of the solutions in problem C is wrong. check it: 11 21

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

Can someone find the problem in following logic for A? There are only 3 possibilities: (1 2 4), (1 2 6) and (1 3 6). So I simply read the input find counts for numbers 1 to 7. Let say that combination 1 2 4 is there a times, 1 2 6 b times and last c times. From counts I can calculate a as number of 4s, c as number of 3s and b is number of 6s — c. At the end I calculated counts for used possibilities and checked against input, but got WA.

edit: it failed, because I didn't checked that b is non-negative :-/

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

    b is the number of 6s — number of 3s

    UPD: numer of 2s must be must be equal to 4s + (6s — 3s)

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

      and while c is number of 3s it is the same...

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

    I did the same and got AC. Maybe your checks wasn't comprehensive enought.

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

    A is much simpler than that, the point is that only 1 can be set as the first number in every sequence 5 and 7 cant be in the sequence, you can pick 2 and 3 for the second number if you pick 3 you cant only chose 6 for the third and if you pick 2 you have 2 options, 4 or 6. so you simply check if there is any 5 or 7, and if the count of 2 and 3 equal the count of 1 and the count of 4 and 6, and...(if you want more pm me) good luck ;P

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

    I got AC too.maybe you forget some conditions.The number of "1" equals to n/3; a==number of "4";a+b+c==n/3;and a>=0,b>=0,c>=0.

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

some helps with C? i dont really get it.

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

    Consider example of r=8 and h=7. That's the case most solutions failed to answer correctly. You can put two spheres inside box and one more at the center of top semisphere.

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

      pufff! how are we supposed to find that out?!

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

        why down rates? not every one here know that much of geometry!

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

          :D you down rate this as well?!! hahahaha i have 40 downrates already, i dont care!! cows rock!

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

          Geometry is really basic in this task. I used only Pythagorean theorem.

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

          That's why you should practice more problems. Following your logic, I can say any task that I didn't solve is bad because "how is anyone supposed to find that out?" even when the definition of "anyone" is not exactly everyone.

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

        It's simple , but I didn't realize that particular case during the contest.

        Imagine that you have 3 circles puted in that way: 2 down , 1 up. You have the distances between their centers equal to r. So you have an equilateral triangle.

        Let's name the height of the triangle t. So we have : t^2 + (r/2)^2 = r^2. So t = sqrt(3)/2 * r.

        Initially you put h/r*2 circles from bottom to top so you remain with h%r. Up there you will have 3 cases: the 2 ones that are obvious ( 1 or 2 circles ) and the one presented below ( with the condition: t < h%r ).

        Sorry for poor English. Hope it helped you.

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

          Simple picture:

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

            this simple picture is better than any tutorial. :)

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

            I've always wanted to know how to generate/draw such pictures.Would you mind sharing the method with us?

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

          i dont understand the condition t < h%r

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

            See the remainder height $$$h\%r$$$ part and the semicircle part. Their total height is $$$r+(h\%r)$$$. Let's say we're able to fit 3 circles in the mentioned way, in this area. Now, the total height would be radius of the upper circle+t+radius of the lower circles, that is, $$$(r/2)+t+(r/2) = r+t$$$.

            If you want the three circles to fit in the mentioned area, then their total height should be less than or equal to the height of the mentioned area. That is,

            $$$r+t \leq r+ (h\%r)\\t \leq (h\%r)$$$
»
11 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Any ideas for solving E?

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

    I have no idea whether there exists a nice solution which is both easy to code and fast enough. But as far as I can see now, you could use data structures like heavy-light decomposition or use brute force BFS/DFS with some tricky optimization ^_^

    UPD: You could cut the whole tree into blocks of size sqrt(n) by choosing sqrt(n) key vertexs. For coloring, use BFS in its block and use LCA for each key vertex. And that'll be enough to deal with queries in O(sqrt(n)) each. So you get a O(nsqrt(n)) algorithm overall.

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

    I used centroid decomposition and reconstruct "centroid tree". This has O(log n) max-height and has all nodes of original tree. Every node of centroid tree has minimum distances to red node. Query Type 2, i can get minimum distance exploring nodes on the path from queried node to centroid tree's root. Query Type 1, update nodes on the path from queried node to centroid tree's root. Overall, using LCA, O(Qlog^2 N).

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

      Very nice idea. Do you know any similar problems ? ( that use centroid in solution )

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

        problems like dealing with distances on the tree. TMK, SPOJ/QTREEn series(as above), POJ 1987 and Croc Champ Round 2E[problem:293E].

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

          Thank you !

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

          Thank u! I know Qtree,poj and Croc Champ Round 2E,but what's TMK? Can you say it in details or give me a link? Thank U again!!

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

            To My Knowledge :)

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

              ..ok.. I know it.. orz..

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

              uwi Can you explain the approach to solve the same problem but to answer max queries(farthest distance to a red node) instead of min using centroid decomposition? Thanks.!

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

      could you explain how you reconstruct "centroid tree" ??

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

My code gave TLE with cin for T,L,R and gave Accepted in practise when I used scanf for the same.. :-/ Isnt it a bit harsh..??

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

    what is you algorithm?

  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    Res=Res+'X';
    

    This takes O(length), use Res+='X';

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

      But the solution which passed actually just used scanf instead of cin.. Dont u think in an algorithmic contest it is better if such things which are language based should be avoided..??

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

        Runtime with scanf = 1746 ms (your solution), I got Accepted in 404 ms using cin.

        Runtime with scanf and += operator = 92 ms (your solution).

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

      what's the complexity of Res+='X'; ?

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

        It depends on the capacity of the string, if s.size()<s.capacity() then it's O(1).

        http://ideone.com/p0UzsL

        If you are appending n = 131043 characters, it's O(2n); string will change the capacity 17 times, sum of capacities = 257902, 257902 / 131043 = ~2

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

my silly mistake in B : could not realise that f could be smaller than s. so stuck with wrong answers on pretests even.

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

Spent 2 hours only on problem D and finally got accepted...just 1 min before the contest ended.

I think the problems are harder than usual div.2 contests.

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

i had advanced to Div-1 in the last contest, but i would still have liked to take part in this one unofficially. unfortunately missed it due to the unusual time and because Codeforces decided not to send a mail to its users! :/ please make sure this doesn't happen again! :)

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

    You don't receive any notification about Div 2 only contests if you're Div 1.

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

    There's virtual participation for that. I, for one, miss many contests, since I'm often in regions without solid internet connection, but I always participate virtually later.

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

Very weak pretests for task C.

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

The test data for task E is too weak. Many solutions only used brute force BFS which would fail on most tests where the tree's height is big ( e.g. form a string ).. but the system test didn't include any of these cases. What's more many O(n^2) brute force even ran faster than my O(n\log^2 n) solution, while some O(n\sqrt n) solution got TLE or MLE.. Just a remind to the task setter.. Don't just use complete random data when designing test cases.. Think about possible "strange optimization" for brute force and designing test cases against them is very necessary, since passing system test with brute force is unfair to the ones who wrote complicated correct solution and to those who didn't write brute force.

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

    however, i think the test data of this problem is really hard to designed.

    p.s. your solution may be improved to ? the usage of priority_queue is redundant.

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

      I didn't use priority_queue.. I think if we solve it by the original heavy-light weight decompisition, it's hard to achieve time complexity better than n\log^2n.. Maybe this solution can be improved to O(n\log n) by Yang Zhe's 'global balanced binary tree' technique ( link: http://wenku.baidu.com/view/75906f160b4e767f5acfcedb.html ).. But I'm not sure..

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

        It seems that task E can be solved by tree's divide and conquer algorithm in O(nlogn) instead of "the original heavy-light weight decompisition". I just solved it by which.

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

          I read your code, it's really a nice solution. Thank you very much :)

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

        sorry for my mistake. I hadn't seen your code yet. as Sunayuki pointer out, an O(qlogn) exists indead.

        additionally, "global balance tree" isn't invented by Zhe Yang. some papers have been published before that.

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

    It's not an exact true. Look at the 19th test. By the first several numbers you can guess its structure. There are a lot of tests with a huge hight of the tree.

    The another thing is that some of bfs' use strange unexpected optimizations. Please, post your generators against such ones, if you see such solutions. We will add the tests to the testset. As ftiasch say, the test data of the problem is really hard to design. We've break a lot of solutions, but some of them passed. We are sorry for that.

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

      this test would make the first several solutions with shortest code length fail.. ( i thought at first these solutions used some proof to ensure the time complexity but soon found out they are just brute force.. )

      100000 100000
      1 2
      2 3
      ...
      99999 100000
      1 2
      2 100000
      1 3
      2 100000
      1 4
      2 100000
      ....
      1 50001
      2 100000
      
    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      is it true that the problem-setter can perform hack during the contest?

      if it is true, i guess the author should do it to prevent this kind of solutions from accepted.

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

Can someone please explain problem D 's solution to me ? I am not able to understand the solution from the editorial.

Thanks

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

can anyone explain more the idea of the problem E (other ideas than heavy light decomposition)