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

Автор vovuh, история, 6 лет назад, По-русски

<copy-pasted-part>

Привет! В Aug/24/2018 17:50 (Moscow time) начнётся Codeforces Round 506 (Div. 3) — очередной Codeforces раунд для третьего дивизиона. В этом раунде будет 6 или 7 задач, которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Наверное, участникам из первого дивизиона они будут совсем не интересны, а для 1600-1899 покажутся простыми. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов. Я постарался сделать приличные тесты — так же как и вы буду расстроен, если у многих попадают решения после окончания контеста.

Вам будет предложено 6 или 7 задач и 2 часа на их решение.

Штраф за неверную попытку в этом раунде (и последующих Div. 3 раундах) будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в двух рейтинговых раундах (и решить в каждом из них хотя бы одну задачу),
  • не иметь в рейтинге точку 1900 или выше.

Независимо от того являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.

Спасибо MikeMirzayanov за платформы, помощь с идеями для задач и координацию моей работы. Спасибо моим очень хорошим друзьям Михаилу awoo Пикляеву, Максиму Neon Мещерякову и Ивану BledDest Андросову за помощь в подготовке и тестирование раунда.

Удачи!

Также хочу сказать, что участники, намеренно отправляющие неверные решения и взламывающие их после окончания соревнования (пример), не будут показаны в таблице лидеров по взломам.

</copy-pasted-part>

UPD1:

Поздравляем победителей:

Rank Competitor Problems Solved Penalty
1 problem_destroyer420 5 209
2 syh0313 5 225
3 VinceJudge0 5 230
4 SaIah 5 234
5 EctoPlasma 5 241

Поздравляем лучших взломщиков:

Rank Competitor Hack Count
1 halyavin 506:-92
2 antguz 121:-20
3 Anguei 50:-11
4 taran_1407 41:-1
5 zdw1999 41:-2
6 applese 40

Всего было сделано 1217 успешных взломов и 926 неудачных взломов!

И. наконец, люди, отправившие первое полное решение по задаче:

Problem Competitor Penalty
A i_f_y_m 0:03
B SaIah 0:03
C SaIah 0:13
D _kawaii_neko_ 0:17
E syh0313 0:43
F iamunstoppabIe 0:19

UPD2: Разбор опубликован.

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

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

just have strong pretests because then only hacks make sense

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

Will be original cf round on September 1st?

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

How are you going to detect the people who hack solutions having some if statement to remove them from standings table? Is there some algorithm?

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

    I'll try to check all peoples, who will hack their own submissions, manually and check if in their code will appear parts like if (n == 1234) return 1; and similar.

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

      Why is it even allowed for people to hack their own submissions?

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

        Not all hacks of their own code are such as I say above. Many hacks of your code can be useful because there are can be not complete testsets in the contest. But hacks of kind if (n == "blablabla") return 1; are useless and make no sense.

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

          Few contests back, there was a comment mentioning a person hacking someone else in the same room but both the accounts probably were being used by the same person. This way it won't show up in the list of people who hack themselves but this practice needs to be curbed.

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

            We are trying to undermine all such cases but it is very hard to do that without any mistakes or omissions.

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

          Ah, so you build a tricky/big case and let codeforces check the correct answer for you. Never thought about it, makes sense!

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

      People do like this mostly for dropping their ratings purposely. That is repulsive addiction。

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

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

move contest time 3 hours later .. this time is not good

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

Well Well Well

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

Warning, this is a joke, don't feel bad if you are div 3.

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

DIV3 ROUND! It's time to challenge your coding skill together with coding speed!

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

coming expert , i wish .

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

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

Hope there will be strong pretest. Don't want the codeforces changes to the hackforces. Thank you very much.

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

Hope that I will become expert after this contest. :)

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

Why the 15 minute delay ?

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

Delay :(

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

+15 минут? Серьёзно?

Я даже страницу обновил за две минуты до начала, и переноса ещё не было! БЕСИТ!

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

The Wait!!!

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

00:00:15 -> F5 -> 00:15:00

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

Someone please make a Codeforces Delay Predictor -_-

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

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

how to solve A?

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

Before:00:00:15 before start, Now:00:08:00 before start, Will-be:This round will be unrated :)(JUST JOKING)

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

Hackforces, Delayforces, Memeforces, Mathforces, who's next??

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

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

Is it Div 3 contest? I think it's too difficult

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

<copy-pasted-part>

<copy-pasted-part>

.......ANNOUNCE.....

</copy-pasted-part>

</copy-pasted-part>

You may do in such way, we'll understand

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

I am getting wrong answer on test 1 problem A and can't even figure out why. :'( edit: figured

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

How to solve problem D ?

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

this is not div.3 contest

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

    i hate vovuh

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

      This is sad :(

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

        Although I found the problems harder than the last div3 contest, I still enjoyed it! At the end of the day, I'm sure I'll come out of this round knowing more than I did before(once the editorials are out of course xD)

        So a relatively difficult div 3 contest(compared to past div 3 contests) isn't necessarily a bad thing :)

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

        Vovuh why not increase the time limit to 2.5 hours because i think most probably div3 contests have a large fraction of people who always thinks that if i could have given 15 more minutes i could have definitely done one more problem(i m one of them).. i mean this just boosts up the confidence and belief.. this suggestion may be immature but i feels at least 2.5 hours should be given for 6 problems to do justice with the contest,those who solves first will have better rank whether the time is 2 hours or 3 hours.. although these contests are awesome always if one try to solve problems before or after contests .

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

I try to solve Problem B with a solution of upper_bound(a[i]*2) but fails. How to solve this?

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

    You miss read the statement.

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

    I solved it with sliding window

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

      Even I tried the same but got wrong i case 4

      int ans=1,i,j=0;
          
          for(i=1;i<n;i++)
          {
            while(a[i] > 2*a[j])  
            j++;      
            ans=max(ans,i-j+1);    
          }
      

      Could not find what is missing. Please help. Thanks

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

In problem F, what does this mean : "all tiles of at least one color would also form a rectangle." ?

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

    At least one color must form a rectangle i.e if you remove red, blue must form a rectangle or if you remove blue, red must form a rectangle

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

    I also was not able to understand the problem statement because of this. According to Firastic, the intended meaning is quite different to what they wrote.

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

What is pretest 4 for B?

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

Welcome to Codeforces Round #506(Div.2)

Edit: only A isnt a Div.3 A problem.. B is easy but the trap in reading the statement is just so unexpected

other problems are Div.3 problems

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

pretest 6 in A. I want to know that sh*t and yea, i still hate vovuh and his friends who always writes shity contests. (I'm not afraid downvotes)

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

How to handle the case in D when 2 | k or 5 | k. Is there an easy way to do this than to calculate modulus for all possible factors of k which still aren't coprime to 2 or 5

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

    Your approach seems not to be on the correct path. You may want to think it differently.

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

What's pretest 7 on C? I can't figure out where I screwed up.

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

    My guess is that it is something like this:

    300000
    1 100000000
    2 100000001
    3 100000002
    ...
    300000 100299999
    
»
6 лет назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

There should not be hard deadline time to end the contest, atleast 20-30 seconds extra should be given, given the initial load on the system. I missed the D by 1 second today.

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

What the wrong answer test 17 in the problem D ?

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

I solved C with Segment Tree, is there other topics solve this problem? because I feel that it is easier than SegTree when I saw someone solved it quickly.

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

    only the top 2 numbers matter.


    sort(l , l+n); sort(r, r+n); reverse(l, l+n); int ans = r[0] - l[0]; if(!notin(l[0], r[0])){ ans = max(ans, r[1] - l[0]); ans = max(ans, r[0] - l[1]); } else ans = max(ans, r[1] - l[1]); cout << max(0,ans) << endl;
    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thanks, I will see your submission for more details.

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

        Initial idea is that if you consider all the segments, the intersection is formed by lowest right end and highest left end.

        Now, if you want to improve your intersection, you would want to either:

        • Extend the right end of some segment
        • or Extend the left end of some segment.

        Now think about which one would you choose.

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

    Easy O(n log n) with multiset 42096347

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

can someone plz tell me what is wrong in this approach for E? A node ( > depth 2) may be reached through child or parent who has a direct edge or there is a direct edge to this. SO, a) if i want to reach this node from parent, then for each child there must be a direct edge or any of their children must have a direct edge. b) if i want to reach this node from children, any one can have a direct edge and others can have direct edge or their children can have a direct edge.
c) if i have a direct edge to this node, then i can take the min( a, b, c);

Can someone plz tell me what is wrong here, here is the link, https://ide.geeksforgeeks.org/Nn0MdojmeD

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

Will an O(10 * n * logn) solution pass systests for problem D? Link

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

Can someone tell me about solution for problem E ?

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

    DP d(i, j): i represent the index of the nodes, j represent the depth of node i; http://codeforces.com/contest/1029/submission/42054107

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

    The complexity is O(n)

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

    Root the tree at 1. Sort the nodes by their depth in descending order (so we start with leaves). Make an array to store if we can reach a node in <= 2 steps. Loop through the nodes by depth and if not marked create a connection to the parent of that node and mark all the neighbors of the parent in the array.

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

    I was trying it with dp, though couldn't complete the code within contest. My idea was to consider states if there is an edge from 1 to v or not. if there is an edge from 1 to v, then there can be edge from 1 to childrens of v or not. if there is no edge from 1 to v, then there must be an edge from 1 to atleast one of child of v

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

Seems like problemsetters have been missing how problem A should be :D for the last few contests.

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

Am I the only one who misread the problem statement of B? I guess no.

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

problem F, finished in 10 mins after contest :((

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

    during the contest I coded it in 8 minutes but I got WA37 did you get the problem in this test?

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

      the same problem, in the last 5 minutes of the contest, I knew my mistake but i did not have enough time to code :|

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

How to Solve C ?

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

    The intersection length of n segments is min R - max L (invalid if it's negative), so just ignore each segment and evaluate length, i used multiset to insert/remove in O(log n). I'm doing this for n segments, so the total complexity is O(n log n).

    Code: 42096347

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

what's wrong with 37'th in problem F ?

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

    Small infinity(got wa on 37 too).

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

    2 large prime numbers, so only rectangle with side 2 will pass

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

    the area (a + b) can only be divided by 2, some people have the answer 6179835302 because they devide it by 64728, but we can't color the rectangle like this because " all tiles of at least one color would also form a rectangle ". The solution is check that are there any divisor of a (or b) (called i) that i <= (divisor of S (called div)) and a/i <= (S / div) so we can have a rectangle with size div * (S / div).
    my code : https://ideone.com/3bFclD

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

Nice contest : )

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

for me the statement on b,c are very confused after explanation b become clear and I'm solve it, c after contest solve it its easy but not clear with this statements.

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

Is it possible to share ideas of hacks with other people before the end of the hack phase? Does it violate the rules?

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

Honestly, when I saw problem A, I thought for a second if it is really Div 3 (and I haven't passed A). It was quite good, except they were a bit too hard for newbies (like me), and frankly some problems were more suitable for Div 2, or even Div 1 instead. Still, I appreciate the hard work of today's contributors for thinking up the problems!

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

is it a rated contest or not ? also i can't understand the General announcement, which say (We will publish separate standings for trusted participants after the contest.)

:) :) :)

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

 I wish I could code this fast XD. Parallel Programming :P

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

seems like another halyavin day , nearly 450 hacks . wow again .

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

    I can't comprehend how do you even hack. There are too many solutions and most of them are fully correct.

    Can somebody explain, please?

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

    It seems he is the one brought done the submissions of D for ~640 to ~150

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

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

    lol,halyavin is really good at hacking,I have been hacked by him for many times. But I maintain it also help me develop my skills,because the probability I will be hacked decreased more now at least.

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

      can you please explain your code for E?

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

        Firstly, we get a tree rooted by 1. We get dep[i] to express the depth of i in the initial tree, and let's call a vertex is right if the distance to 1 equal or less than 2. Obviously, if a vertex i with dep[i] <= 2, then the vertex is right. Our goal is to make all the vertex right. Consider we link 1 and a vertex i, it makes all the vertexs which are adjcent to i right. So in my solution, we first sort all the vertex in the decreasing order of dep[], and consider them one by one. If we find a vertex i is not right yet, then we link 1 and fa[i], which fa[i] is the father of i in the initial tree, and it will make all the vertexs which are adjacent to fa[i] right. It can be proof that in this way we use the least steps. XD

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

          why do we choose the vertex with largest depth first?

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

            Because we have to deal with it, if we don't solve it this time, we must solve it next time. And solve it from down to up do not influent others, because all the vertex in this subtree are right.

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

    Can I have the original picture plz?

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

Did anyone solve B using dp and implicit segment tree? I guess it's an overkill, but to me it seemed better than to guess that the solution is always a continuous segment.

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

    I guess that this solution would be the best if the sequence was not in increasing order.

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

    You can try to prove it during the contest. Just imagine you have already some subset, with the last element at index i (the array is sorted, and all of the elements with indexes > i are bigger). Now you want to try to add another element to this subset, suppose you added element j (j > i+1). Now you can see, that if element a_[j] <= a_[i]*2, the same applies to other elements in an interval [i+1, j-1] and it's always worth it to take smaller element. But why? Consider x as the smallest integer in the subset we consider at the moment. It's easy to see we want to minimize the largest integer in our subset (lets name it y), so 2*x >= y. This strategy applies to every element we consider in our subset — concluding — our subset will always be contiguous (if the array is sorted). Please correct me if I made some logical mistakes.

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

in problem B 2 1 2

how is the answer 2 ?

i knew that the statement contained <= but i thought that it is <

how isn't there any pretest to check this ?

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

Just curious, how could someone (or to be precise, antguz) confidently hack my O(10 * n * log(n)) solution of problem D to successfully give a TLE verdict?

My hacked solution: 42049909

My re-submitted one (with some slight optimizations, still TLE on other similar tests, which gave the conclusion that my solution ran at somewhere around 2.5-3s): 42071241

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

    I had the very same issue as you so I thought of helping. TLE will go if you use unordered_map. Link to your submitted solution.

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

      sigh Ah yes, unordered_map... Thanks! :D

      P/s: Still seeing that got TLE is insanely weird :-P

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

    I think the issue is not in usage of map instead of unordered_map, but it is in that you used the operator [] when you wanted to add values to the result.

    Instead, you should check if a key you want to add its value was already existed in the map by the member function count(), and if yes, then add the value of that key to the result.

    Because when you use [], if the key in [] is not existed yet, this operator will create it, so the size of the map will increase by one, and so on. So, the time needed to access the map will also increase with the increasing of its size, thus you will get TLE.

    Check my submission for more details.

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

      Well, just as I was discussing with one of my friends about this exact issue.

      Yeah, I was critically careless in that, thinking O(10 * N * log(10 * N)) will do no harm. I was stupid :-P

      Guess this should be a huge lesson for me from now on. Thanks! :D

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

      Thank you very much!

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

Can anyone please point out why my code is giving TLE for problem D? I have tried all the optimisations I could think of at my level. It would be really helpful if someone can help me out here. Thanks in advance !!

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

Are there any better solution in problem B? I use dp and RMQ to solve this problem, but I think it's too complex for the problem B in div 3 contest :((

I use F[] with the meaning that F[i] is the answer ending at i. I use lower_bound to find the minimum value that more or equal A[i] / 2 (called j), than find the maximum value of F from j to i — 1.

P/s : If the array isn't in increasing order, what should we do?

Edit: If the problem like this : find the maximum length of a subsequence ( by delete some elements ) (like LIS) but a[i] <= a[i-1] * 2 in this subsequen. what will we do?

eg:

Input n = 3 array[] = {2, 1, 4}

Output 2 ( 1 and 4 )

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

    You can traverse greedily in O(n): find the longest increasing subset that the criterion aij + 1 ≤ aij * 2 holds true.

    So, of course, if the array isn't sorted yet, we can just sort it beforehand — nothing special.

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

      Thank you.

      If the problem like this : find the maximum length of a subsequence ( by delete some elements ) (like LIS) but a[i] <= a[i-1] * 2 in this subsequen. what will we do?

      eg:

      Input n = 3 array[] = {2, 1, 4}

      Output 2 ( 1 and 4 )

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

    Excluding the last element (i.e., the biggest), you can just calculate the length of the largest interval I = [L,R) such that I[R-1] <= 2 * I[R-2] holds.

    So L starts at 0, R at L+1, keep increasing R until the property I[R] <= 2 * I[R-1] is false. Then reset L = R, and repeat the process until R >= N. After doing that, the answer is the max R-L difference you've found in this process. There is one corner case: N = 1.

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

Freakin' A Again >(

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

Мне кажется, для задачи D ограничение по времени стоило бы немного увеличить, потому что те люди, которые решали эту задачу за O(10 * n * logn) получили взломы в виде ограничения по времени. Несправедливо, ибо это же не лобовое решение, и оно, как мне кажется, имеет место быть в ряду АС.

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

In problem D, using unordered_map gives TLE while submission with map gets accepted. I can't figure out why.

http://codeforces.com/contest/1029/submission/42051858 (AC code)

http://codeforces.com/contest/1029/submission/42063201 (same code with unoedered map)

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

    Some special data can make the complexity of unordered_map become O(n).(like test 64. I used pb_ds and got accepted after the contest. :P

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

    42061028 this got hacked(map) -> tle verdict on hacking 42073938 this got tle at test 66 unoredered map

    any reasons?

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

    Unordered_map is implemented using hash table. So due to collisions in the worst case it can be O(n) for accessing an element. But map guarantees O(logn) for access.

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

CodeForces is the worst. Solution 1 Solution 2 Both solutions are the same. So during system testing, my correct solution fails only because of the load on CF server, which is basically CF's fault. So now I've to pay for it to settle for a worse rank.

And I know even tagging MikeMirzayanov won't do anything because these kinds of crap has happened before and nothing was done.

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

    Your solution was already borderline. Also, time is actually calculated by the no of clock cycles your solution takes to finish execution, and not wall time, so I don't think it has anything to do with server load. +-100ms in similar code execution can be expected

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

      Yes I know it was borderline. It had passed test 7 in 2.8 s during the contest. But I think it's the server load only because I've read more such cases in a few contests held earlier and my solution to D also took more time to execute than it took during the contest.

      In general I have observed that borderline solutions fail only during system testing leading me to believe that load during system testing is the only reason, because otherwise they still pass.

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

When will ratings get updated?

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

I don't know why this submission for problem C 42040684 got hacked and then I again made the submission 42076792 with the same code and it passes all the tests, this seems to be a serious issue, as its the fault of the system which gives different execution time for the same solutions and unexpected time penalties. I think the hacked test case is the last one #71 ..Plz have a look at it.....

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

Was the time limit too strict for problem D?

42055423 Uses unordered_map and gets a TLE; 42076582 Uses cc_hash_table and gets an AC.

Time complexity of both solutions is O(11*N).

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

Problem D makes me very sad.

I write a O(n * logn * 11) then get a TLE on test 28.

I make some optimization to O(n * logn * 10) then AC.

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

When will ratings change?

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

How to solve problem D?

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

when will the editorials be out??

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

The same code for Problem D running on G++11 gives TLE on test 50, and with G++14 gets Accepted. I don't think such stiff time limits give fair assessment.

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

How to solve D? just an idea will be helpful

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

    Assume you are at a point ai and assume ai is l digits long. Then ai gives a solution when there exists aj in the array with the property 10l × aj + ai. has a remainder 0 when divided by k. With a bunch of precomputing you can find how many ajs have this property. However you have to be careful to remove the case when i = j. Also for the precomputing using 10 maps or unordered_maps for each of the powers of 10 you need seems to lead to TLE. You can avoid this issue by instead sorting and using a binary search.

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

UPD: Sorry I got it, the answer of my idea is 2 + 2 * (a + b). So, never mind.

In F, is there any statement in the statement denys us from coloring the tiles as a rectangle with dimensions (1 * (a + b)), so the answer will be a + b + 2?

Because in the given samples (and all testcases I guess), the answer with my idea is always less than or equal to the answer from these samples.

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

For Problem D — TLE issue

People here find the Time limit strict ( even I did ) , but actually it isn't that strict. The only issue while using map which almost everyone is facing is :

If u simply do ans += mark[digits][requiredmod]; then even though that required mod doesn't exist in the map, then also it will be added to that map and now the size of the map = (actualsize+1), and if you do this n*10 times the size of the map would increase and therefore the time to search as well

So what u need to do is first search whether that element is present in the map and then add it to the answer, as shown below :

if ( mark[digits].find(requiredmod)!=mark[digits].end() ) ans += mark[digits][requiredmod];

This is the only difference in my accepted and TLE solution.

Accepted Solution : http://codeforces.com/contest/1029/submission/42081763 TLE Solution : http://codeforces.com/contest/1029/submission/42082128

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

    "then even though that required mod doesn't exist in the map, then also it will be added to that map and now the size of the map = (actualsize+1)". It is your assumption or document that says so ?

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

      No it is not my assumption. Very simply, you can compare the memory of both of my solutions. Why open the documentation when you can code... LOL.

      map < int,int > mark;
      mark[1] = 2;
      cout << mark.size() << endl;
      int val = mark[0];
      cout << mark.size() << endl;
      

      Output :

      1

      2

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

      Tried everything and still got TLE on different tests. After that, I read your comment, changed that line, and got AC with 342 ms. Incredible :P

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

      It is true, whenever you wanna create a new element x in a map you can just do

      M[x];

      This is the same case, doing

      ans += M[ x ][ y ];

      Will always create a new element [x][y] if it didn't exist.

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

    For me, changing unordered_map to map helped me solve the TLE issue.

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

DP Solution for Problem E

DP state : (node, cur, par)

node -> The index of the node

cur ( 0 or 1 ) -> Whether the given node either has or is supplied with an extra edge connecting it to the root

par ( 0 or 1 ) -> Whether the parent of the given node either has or is supplied with an extra edge connecting it to the root

Now 3 cases arise :

cur:1 -> sum over all children {min(solve(child,1,1) + 1, solve(child,0,1))}

cur:0 par:1 -> In this case the current node has a path of length 2 to the root by going to its parent and then from parent to the root. sum over all children {min(solve(child,1,0) + 1, solve(child,0,0))}

cur:0 par:0 -> This is the most important case. Main Point : This node doesn't have a path of length atmost 2 to the root, so it has to make use of ATLEAST 1 of its children*

Case 1: Leaf node -> You need to make an edge straight from here to the root. ans =1

Case 2: Internal node -> Select atleast one child from which you will make a direct edge to the root. Code for this :

vector < pii > vec;
int sum = 0,idx = 0;
for ( auto child : adj[node] )
{
    vec.pb({solve(solve(child,1,0)+1,solve(child,0,0)});
    sum += min(vec[idx].first,vec[idx].second);idx++;
}
int ans = INT_MAX;
for ( auto child : vec )
    ans = min(ans,sum+child.first-min(child.first,child.second);
»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For E does greedy approach like this work? Take any leave. If its distance to root in the input tree is <=2 we are done for this leave. Else connect parent of this leave with the root and delete this parrent and all his sons and his father from the tree.

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

Could you please publish a tutorial for the contest !

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

Can I get a tutorial for this contest?

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

Could you please publish the results, the best hackers and the tutorial?

And we know, the best hacker is halyavin as usual.

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

It's sad having problem E with all tests except samples n = 200000. Have WA8 and don't know how to debug)

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

    Why don't you attach your code? I think you were wrong while not interested if addition edge from 1 -> v then we could go from 1 -> v -> parent (v).

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

      You're absolutely right. It's just about "aaarrrgghhh why I can't just copy failed test?"

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

I think the ranklist has something wrong.

Such as the participants VinceJudge0's solution for D was failed during the system test, but the ranklist shows that he/she solved 6 problems. Is this a bug?

vovuh Please check it. :D

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

42038360 He use “for(int i=1;i<=floor(sqrt(a)+0.5);i++)” .He got TLE on my computer because calculate sqrt() many times is much slower than calculate it at first. But codeforces maybe use -O2 -O3 or something and he Accepted. :(

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

Can someone tell me why I'm getting TLE in D? my submission

I read all the comments but can't figure it out.. :(

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

    Honestly i don't know, i tried playing with your code for a bit but i still got TLE. If it helps, my TLE on-contest submission used about 80k memory, and then it went down to about 10k with the Map.count(). Yours is still ~80k for some reason

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

      Thanks. I think my code structure is the problem. Compare to editorial and accepted codes, I insert ten times more nodes.

      That might slow down map operations and maybe larger memory consumption itself can be a problem.

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

Why does this TLE?

Can't find the reason.....

The time complexity should be O(n*log(10n)) (Correct me if I'm wrong) http://codeforces.com/contest/1029/submission/42107686

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

you should probably change the time limit of Problem D.

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

Hope that the contest page doesn't show "starting in 15 minutes" after 3 minutes