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

Автор Hasan0540, 8 лет назад, По-английски

Hello everyone!

I would like to invite you to participate in Codeforces Round 480 (Div. 2), it will take place tomorrow, May/08/2018 18:05 (Moscow time).

The round consists of 6 problems and you will have two hours to solve them.

The problems were prepared by me with great help from linkinu and Reem. I would like to thank KAN for his great efforts in reviewing the problems and for his suggestions, it is really amazing to see the work done behind every round. Also thanks to Tommyr7, Livace and mike_live for testing the problems, and to arsor for translating the statements into Russian.

This is my first round on Codeforces, I hope that you will find some interesting problems for you.

Note that the round is rated for everyone with rating below 2100.

Good luck and have fun!

UPD: Congratulations to the winners:

Div. 2:

  1. phongthan

  2. allllekssssa

  3. veterfrank

  4. lagin

  5. Fekete

Div. 1+2:

  1. eddy1021

  2. phongthan

  3. Andreikkaa

  4. step_by_step

  5. cerberus97

UPD1: Editorial

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

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

rated for div.3 too?

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

...

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

I am expecting some really interesting round, Hasan0540 is one of the best problem setters from the Arab region, I always enjoyed your problems in ACM contests :D

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

I hope to see a realy nice contest from our Jordanian programmer Hasan0540. ❤

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

We've implemented a special tag [contest_time:contestId]. It shows a contest start time in a correct timezone (as a link to timeanddate.com). Please, use it in announcements as Hasan0540 did.

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

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

Am I only noticed that in the russian description only thing in russian is the date :)

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

Are these problems in English or Russian?

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

любил конкурс много

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

Hope will be Short Statements

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

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

WOW!! Three Arab rounds in one month

Codeforces Round 473 (Div. 2)--Codeforces Round 478 (Div. 2) -- Codeforces Round 480 (Div. 2)

We are invading CF :D

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

Для третьего дивизиона раунд будет рейтинговым?

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

I have a question: when we'll have a div1 and a div2 contest in the same time, those under 2100 can participate in both rounds or is forbidden for them to join div2?

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

Шесть задач, я думаю сегодня будут более интересное соревнование. :-)

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

you forgot to say thanks for MikeMirzayanov for the great Codeforces and Polygon platforms.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится

I hope this contest will make me green once again

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -46 Проголосовать: не нравится

Time to use my alt account!

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

Будет ли теперь всегда div2 рейтинговым для людей с рейтингом, меньшим 2100?

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

All the best Hasan0540 for your first round! May it be interesting and great for everyone! cheers!

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

It's time to decrease my rating again....

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

Why B has no spj?

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

I positively registered for this contest but now when I am trying to submit the solution, it says I can't do it because I am not registered. Anyone has any ideas who should I contact?

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

Stupid problem selection.This problem set should be for DIV1.Not for typical div2 and div3 people.

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

Can anyone translate problem D? I really try understand... but fail.

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

Oh my rating!!! They will be in a lot of trouble after this round. A really bad contest for me.

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

so difficult to understand problem statements...

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

Really? It seems to me that C easier than B

»
8 лет назад, скрыть # |
Rev. 5  
Проголосовать: нравится +16 Проголосовать: не нравится

I can't understand the problem statement properly for problem B and problem C. Either my English skill is not good or the problem statements was poor.

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

How to solve D?

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

Hasan0540 Next time please make statements easy to understand.

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

Any idea of test 7 of E?

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

Nice problems(though harder version of D was on some round before).

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

I don't understand problem C: 5 2 0 2 1 255 254 For this test case in problem C, wouldn't lexicographically smallest array be 0 1 0 254 254 (0 and 1 are grouped for key 0) instead of what is shown as the test case 0 1 1 254 254?

Thanks for any help

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

OMG.
~~~~~
long long b = ...;
long long a = sqrt(b);
if (a * a == b)
{
//b if square
}
~~~~~

This works just fine on Codeforces but fails on my computer, so I failed my hack. Gosh. Now I know more about CF.

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

Почему В падает на 5 претесте?

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

How to solve E?

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

    Am i correct that this is greedy? First we take vertex n, than try to take n — 1. If we can take number of vertex between n and n — 1 we take it else try to take n — 2 and same algorithm next.

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

      Yes, because 2^x=2^(x-1)+2^(x-2)+...+2^0 + 1.

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

      I solved it like that. I had to optimize lca to O(1) to prevent tle ...

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

        Can you tell me your solution?

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

        You can think of it as "keeping" vertices. So first you keep vertex n, then you try to keep vertex n-1, then n-2 etc. (To keep a vertex i, you need to keep every vertex on the path from n to i)

        We realize that we keep at most n vertices. Thus, every time we keep a vertex, we can mark it as kept. Now we want to know the first ancestor of vertex i that is already kept (this tells us how many more vertices we need to keep along the way in order to keep vertex i).

        We can use parent doubling to check this in O(lg N), so I don't see why we need O(1) LCA here.

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

          I solved it as follows: given a tree T and a vertex u, we have to find the vertex v in T that maximizes the depth of lca(u,v). Note that a solution for v is one of the leafs that is next to u (left or right) in dfs-order. Mine is also Nlog(N), so I was surprised when I got TLE

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

          meeeep Can u give any link to learn about the "parent doubling" that u used? One more thing why cant we proceed in this way:- remove the smallest weight leaf from the tree and repeat the same on the new tree until we remove k nodes which could be seen as minimizing the number of fans that we lose by removing a node?

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

            why cant we proceed in this way

            Consider this tree:

            3 — 1 — 4 — 2

            where k = 2. If we do it your way, we'll remove 2 (our leaves are 2 and 3) and then 3 (leaves are 3 and 4). But the correct answer should be removing 3 and 1

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

            I don't know a link, but it should be pretty simple to explain (hopefully).

            For each node, you store your 2^i-th parent for each integer i. (A convenient initialization for this question is that the parent of the root is itself).

            We initialize the 2^0-th (i.e. direct parent) manually. For each i>1, we notice that the 2^i-th parent is just the 2^(i-1)-th parent of the 2^(i-1)-th parent, so we may find this is constant time... assuming we have already computed the parents of its 2^(i-1)-th parent. This means that we want to compute parents in some kind of pre-order DFS, which can be written together with the DFS that roots the tree.

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

    Because

    2i > (2(i - 1) + 2(i - 2) + ...)

    , process the cities from greatest to least and greedily take them. First, root the tree at the largest value (you always take it). Then to see if you can take city $x$, see how many cities you haven't taken that are on the path from x to the root. If you can take all of them, do so, otherwise ignore this city.

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

hacks for D?

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

I lost a time because in problem E k supposed to be less than n. When I added if n == k print(all) it passed.

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

Trying to do the C problem...

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

Please guarantee there are at least one perl on A...

I heard the announce after my first submit, so I lost 50pts...

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

Statement for C is hard to understand, and B is a bit hard for a Div2-B. But overall, today's problemset is nice (especially E).

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

Problem A pretest is wayyyyy to soft

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

I realized that in the D is necessary to consider the cases where there is a 0 in the range, but didn't corrected my code correctly, wasted a big chance :(

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

Seemed like Problem D's time limit a little bit too strict?

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

I didn't lock my solution and I got hacked HOW!!!!! here

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

Can you make the number of links between every two adjacent pearls equal? And there is some test for only 1 pearl and even "No" pearl ???

»
8 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится -39 Проголосовать: не нравится

Hasan0540 why you are so strict at dataset for problem F!!!

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

I could not make out D. Can someone make me understand what the problem statement meant?

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

any on got WA test 5 in the problem B then got AC ?

any test case ?

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

rip my rate

oh wait it's already bad

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

it is rated or yes?)))

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

How to do B? I thought to create symmetric parts on the innner matrix. Any suggestion?

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

    Yeah symmetric inner matrix.You have 3 cases to consider. Let me assume n=7.

    if k is even say 4:
    .......
    .##....
    .##....
    .......

    if k is odd and <=(n-2) say 3:
    .......
    ..###..
    .......
    .......

    if k is odd and >=(n-2) say 7:
    .......
    .#####.
    .#...#.
    .......

    How did i come up with this? Well i had made a checker that gives no of ways to reach in shortest path from 1,1 and 4,1 for a given grid and used a bit of symmetry and observations to conclude this.

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

      2nd and 3rd cases can be understood as inversions of each other. Look at antipr000's examples: inner matrix of 2nd case is inverse of inner matrix of the 3rd case. So if we have k ≥ n - 2, then we can assign k to (n - 2) * 2 - k and make inversion after (perl code — 38050716).

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

My first hack on problem A (38026095)

Seriously I don't know how that passed the pretests...

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

I think the problems are really nice.But I spent some time hacking ,and have no time to write out problem E.So sad.

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

I could not make out D. Can someone make me understand what the problem statement meant?

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

How to solve problem C?

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

Stupid cases of 0's in D. These puzzling cases aren't fair :/

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

За 90 секунд я успел:

  • Понять где ошибка
  • Исправить ошибку
  • Заслать решение
  • Получить ML на 12 тесте
  • Изменить long long на int
  • Еще раз заслать решение

Думаю codeforces работает достаточно стабильно и быстро (по крайней мере под конец раунда).

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

Is it just Me who think that problem B became harder than C just because of the statement? XD just want to know everyone's views!

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

Clarification on A was so unfair, for people, who already failed on this case, and got minus points

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

D in a nutshell.

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

tfw when you forgot to handle negative numbers in d.

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

I think, 2 hours are too few for this contest (a lot of cases, a lot of thinking, a lot of text understanding). It would be better to have 2.5 or 3 hours of solving time.

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

I didn't really like this contest

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

D is really hell. I've spent a lot of time to read and understand it. There is no any example explanation like in other problems.

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

A could really use some constraints on perl/links numbers and D's statement was so bad.

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

Whats test 20 in D?

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

When writing code for problem A, I know that I have to wait for the statement update to handle the case of 0 pearls. I took me few more minutes. I don't know how 1500 solvers before me manage this case.

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

Can anyone please give me the proof for problem B's solution?

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

Write winners, write winners, I want to see my name :D

For me contest was really nice with cool tasks :) I thought that I will never say this sentence, but maybe texts could be a little longer.

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

Can someone explain the problem statement for D ?

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

PROBLEM B: for input 9 5 why YES

.........

.##.#....

..#.#....

.........

isn't an answer?

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

Problem B

Based on intuition : easy

Based on Proof : hard

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

    If the matrix is perfectly symmetric you don't need to count the number of paths to know they are they same number. They are literally the same paths, no need for more proof.

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

    ways (1,1) -> (4,n) is equal to ways (4,n) -> (1,1)

    If answer table is symmetry, number of ways from (4,n) -> (1,1) equals (4,1) -> (1,n) (because of symmetry)

    (symmetry through (n+1)/2 like this

    00000!00000

    00#00#00#00

    0#00#!#00#0

    00000!00000 )

    proof doesn't look hard

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

Wow, exactly 50 users became Master according to new rules!

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

Wow, I've become so numb orange, but now it is not so cool

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

while I had a very bad contest but the problems was so beautiful. thanks for that Hasan0540.

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

What is case 18 in problem D. I keep getting WA.

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

Can anyone explain me problem C ? I read at least 10 times, still find hard to understand.

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

Could someone please explain the symmetric approach used to solve B? I can't understand how to think in the correct direction.

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

For those who are curious how the color distributions are changed due to the update of upper bound of the rating on "Div.2 Only" rounds. Please be informed that this describes top 2000 contestants for each round:

»
8 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится
  • Pretest passed on D at 01:47
  • Immediately locked all problems and started hacking
  • 3 minutes later found silly mistake in my submission of D (before looking at other people's solutions)
  • Shouted "fxxk"
  • Turned out that SO MANY people FSTed on D that I still got +17 rating (should have got about +60 if I made D right)
»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I came up with a solution for D that is something like this:

We add bidirectional edges between pair of nodes i to j if ai·aj is a perfect square. My first observation was, every connected component is a complete graph. Let, bi be the binary string consisting the parity of powers of primes of ai. Then if i and j are connected and j and k are connected, then i and k are also connected. Because, i and j connected means (1), again, j and k connected means (2). Combining (1) and (2), we get , means i and k have an edge. This gives us enough material to prove that all connected components are complete graph.

Now, the problem reduces to finding the number of connected component of the sub-graph consisting only edges in a range, i.e. in [l;r] (1 ≤ l ≤ r ≤ n).

To do this, I implemented this using the following way:

We first select sub-array's starting point, let's say i(actually we also iterate this from left to right), then iterate on the ending point from left to right (denote it also with j). When extending one node to the right (means, we are going from j to j + 1) we need to only know if j + 1 connects to any of the node in range [i, j]. If it does, then number of connected component remains same, increases by 1 otherwise. As we don't care about the edges connecting with a node left to i, we may delete them on the go i.e. when we move the left end point one step right, i to i + 1, we delete all the edges that are connecting node i and another node with index greater than i. Another observation is that, when we are trying to find if the new node j + 1 can be connected with any component, we need not to check all the edges as all the edges lead to the same component. Instead of keeping all the edges we will keep the edge which connects j + 1 with the closest node left to j + 1. More formally-

For each i (1 ≤ i ≤ n), maximum j < i such that there is an edge between i and j, if there is none then it's simply  - 1. Again a set for each i, .

Now, the pseudo code seems something like this-

for i in range 1 to n :
    c := 0
    for j in range i to n :
        if back[j] = -1 then :
            c := c + 1
        cnt[c] := cnt[c] + 1
    for j in to(i) :
        back[j] := -1

Where is the answer array.

But I got Wrong Answer on test 18. Submission

Can anyone check and tell what's wrong here?