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

Автор vfleaking, 10 лет назад, перевод, По-русски

Поздравляю всех с днем защиты детей!

Наверное, вы задаете себе вопрос: как отпраздновать этот необычный праздник? Конечно, написать очередной Codeforces Round — самый лучший выбор!

Сегодня главным героем задач будет маленький ребенок. Он столкнулся с огромным количеством алгоритмических задач, сможете ли вы помочь ему?

Приглашаем вас поучаствовать в Codeforces Round #250, который состоится в 17:00 первого июня в день защиты детей. Соревнование будет проводиться для участников обоих дивизионов.

Обратите внимание на необычное время начала раунда. Вероятно, вам интересно почему время раунда не стандартное? Все потому что это очередной раунд, подготовленный командой авторов из Китая! Мы постарались приготовить для вас много интересных задач. Вы заинтригованы? Тогда не пропускайте раунд!

Соревнование подготовлено группой авторов: delayyy, Picks и я. Это наш первый раунд Codeforces~~~~.

Большое спасибо Gerald, за помощь с подготовкой раунда; а также спасибо ftiasch, Kissshot и jqdai0815, они тестировали задачи; традиционно благодарим MikeMirzayanov за создание замечательной платформы Codeforces.

Разбалловка для первого дивизиона: 500-1000-1500-2000-3000.

Разбалловка для второго дивизиона: 500-1500-1500-2000-2500.

Не упустите шанс поднять свой рейтинг Codeforces! Желаем вам удачи и удовольствия от решения задач!

UPD: Контест завершен! Поздравляем победителей!

Top 5 участников Div. 1:

  1. Alex_2oo8

  2. Petr

  3. Dmitry_Egorov

  4. TankEngineer

  5. al13n

Top 5 участников Div. 2:

  1. tohdon

  2. KFDong

  3. function348

  4. 104325EA

  5. Boyuede1

К сожалению, никто не решил задачу E в обоих дивизионах. Очень жаль....

Разбор будет опубликован очень скоро.

UPD2: Разбор задач

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

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

cin >> A long long time ago, there is a child who is our friend.

cout << A long long time ago, there was a child who was our friend.

/* UPD: Thanks for the Round :).

Good luck and have fun all */

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

    It's my fault.I have removed the stupid "a long long time ago". Oh, my poor English……

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

So fast announcement of the score distribution!

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

"Just participate in this contest and write code fast and nicely, and you will take the high rating home!"

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

Happy to see a new template for the round announcement instead of those formal templates with the same sentences (only changing the numbers) used for the last rounds! This round seems special. Everything is new... Wish luck for everyone!

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

quite looking forward to this round.

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

Problem E 3000...I guess it must be very hard

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

Chinese Div 1 E problems with wealth 3000 are usually very hard. Let's see who will solve it..

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

Is picks a person?

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

What about Russian language?

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

    what about the russian language? nowhere in the blog is it mentioned that the problem statements will be in chinese.

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

      We would like to add Chinese language but it seems to need a big change to the website. Maybe we should advise Mike to add Chinese to codeforces? Lots of Chinese participants will be very happy for that.

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

        Such a request should probably already include one qualified translation of the page :D

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

          Yeah. So i said it needs a big change to the website. Whatever, I'm looking forward to it.

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

        CodeChef now supports both Russian and Mandarin Chinese translations of English problems (MinakoKojima and gediiiiiii are usually the Mandarin translators).
        maybe Chinese language will be added to Codeforces soon. :)

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

        Five years past, We Chinese are able to understand the English, and I like English so much!

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

Завтра весёлый день!

  • Яндекс-Алгоритм 2014 — 5:00 — 6:40;
  • Russian Code Cup 2014 — 13:00 — 15:00;
  • Codeforces Round #250 — 17:00 — 19:00.

Где-то что-то должно получиться :)

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

Unleash the child coder within

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

Today is my first Children's Day after my 18th birthday. I'm looking forward to having a memorable contest. Thank you very much. Good luck.

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

Wow, a typical Chinese style announcement. LOL

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

I think this announcement is very nice :) It seems it will be a funny round.

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

A contest on my birthday :D Thank you very much. Good luck.

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

No Chinese Discription.....Sad....

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

вопрос снят)

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

a 3000 E …… no one can solve Chinese's E until……

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

I hope i do something better this time...All the best to everyone :)

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

Obviously, the problem E is going to be a good surprise :D

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

vfleaking is good at I think problem E can't be solved by Ordinary people 。。

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

i thing it does not connect!

"Happy Children's Day everyone. What should you do to celebrate the special holiday?

Of course, another Codeforces Round is your best choice!"

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

Problem E 3000 again... just can't imagine how hard it can be :p The same as last chinese round

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

My previous contest was good bye 2013. After a long time I registered today again. Then what do I see? Chinese problem setter with 3000 pointer E!! Perhaps I should postpone my first contest of 2014 till "Good Bye 2014" :p

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

Естественно, зоопарк связанный

Кто взял зоопарк в заложники?!

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

Задача A на внимательность :)

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

    по-моему только на реализацию...

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

    а чем же там так взламывают?

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

      Когда два замечательных ответа. У многих, даже если два, выводится не C.

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

      A.abcdefgh B.abcd C.abcd D.ab

      ответ в таком случае С. 11 взломов только на этом

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

    Нужно просто было аккуратно и коротко реализовать.

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

Как решать DIV1-B?

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

    Как решать нормально Div1-D? Я заслал какое то говно, которое пройти не должно.

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

      Не знаю про DIV1-D, т.к. заслал тупой брутфорс.

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

    СНМ. Добавлять вершину по уменьшению веса.

    UPD. СНМ — Система непересекающихся множеств. Не подумал, что аббревиатура неоднозначна. Кстати, сегодня на RCC Qual 4 была задача, в условии которой было реализовано СНМ :)

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

      Что такое СНМ? (гугл выдает "Стрессовое недержание мочи")

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

      А можно чуть-чуть подробнее, как использовать здесь СНМ?

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

        Будем обрабатывать вершины по одной в порядке уменьшения веса.

        Для каждой вершины добавляем ребра, соединяющие ее с какой-то вершиной, которую уже обработали.

        Если при добавлении ребра объединяются две компоненты связности, то нужно добавить к ответу Wi * C1 * C2, где Wi -- вес текущей вершины, C1 и C2 -- размеры этих компонент. Так как при объединении компонент у нас появилось C1  *  C2,2014-06-01 пар вершин, между которыми появился путь веса Wi.

        P.S. ",2014-06-01" вставляется само собой после отправки комментария %)

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

Can I upvote twice? Or thrice? Please?

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

Чувствую, очередной слив =D

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

Смотрим задачу J отсюда http://olympiads.ru/zaoch/2012-13/problems/problems-5.6.pdf

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

    Какая жалость. Формально я бы мог взять своё авторское решение к этой задаче и сдать его... Но я не писал контест. Сейчас ради интереса сдам в дорешку.

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

I'm probably going to kill the problemsetter if in Div1 250C the 6th pretest (the one almost everyone has failed in their first submission) has multiple copies of the same vertex.

I do really hope that there is another reason for my solution failing it... :D

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

    Come on, that test wasn't so bad... pretests 5 and 9 were equally [sarcasm]user-friendly[/sarcasm]

    I'm guessing more like tricky situations with diagonals inside/outside the polygon with multiple collinear vertices — the standard geometric axe

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

      Oops I gave you -1. [truth] I wanted to give +. Liked that [sarcasm] [/sarcasm] [/truth]

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

    Maybe collinear segments? It took me more than one hour to find this... So bad that I didn't have it in my library ; d.

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

A Google search on mysterious number 998244353 leads to integer FFT, maybe that's a hint to problem E, but I can't got any idea.

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

    That'd be finally one nice modulo that allows it. It's annoying that you can't do FFT with the most common ones, 109 + 7 and 109 + 9...

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

    That's quite possible. Note that if we were to count number of directed paths (let's say, there can be no left children), our answer would be the coefficients of the following polynomial:

    (it's easy to see if you know anything about generating functions). However, at the moment I have no idea how to generalize it to count number of trees... ;)

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

      Okay, so let's define the generating function as follows: there are ci good binary trees of weight i. Then P(x) satisfies

      P(x) = 1 + (xc1 + xc2 + ... + xcn)P(x)2

      Explanation: every tree is either a "dead end" ("empty set"); this is this 'one' in the equation or a vertex having one of the weights: c1, ..., cn and two subtrees (maybe non-existent). Of course, each of the subtrees can be described by the same generating function P(x). That's why we have the second addend.

      However, I have no idea how to compute P(x) fast (even the m lowest coefficients)...

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

        Square root of polynomials is the solutiin. However, to let it easier, we let divide and conquer + FFT pass it, even though the only person who do this got TLE with some reason...

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

      In problem E answer is the same row, but with catalanian numbers as a coefficients

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

how to solve Div-1 B?

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

    i used maximum spanning tree and disjoint set.

    cost for each edge between U and V is min(animal[U], animal[v]) .

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

      Then...How to get the answer in this way? I'm afraid I still don't know what to do next.

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

        while you build maximum spanning tree you can calculate the answer. when you add edge U-V the number of ways use this edge is ( number of nodes are reachable nodes from U in spanning tree before adding U-V) * (number of reachable nodes from V in spanning tree before adding U-V) so ans+=(cnt[U]*cnt[V])*Cost[U-V], and then you add U-V to the maximum spanning tree with updating disjoint set (like Kruskal algorithm).

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

    I used a Union-Find approach, where you add the nodes from largest value to smallest value. Then think about what happens when you add a new node — all nodes that are not yet connected must use a node that is at least this low. It then comes down to combining multiple adjacent components of already added nodes, think about this and you will figure it out (it`s simply multiplying the sizes together with the current node value).

    Not sure if this is intendend solution or even passes systest, but it worked on pretests.

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

(•_•) I guess

( •_•)>⌐■-■ in this contest

(⌐■_■) we were troll'D

YEEEEAAAHHH!

Srsly, D... I wonder how many people had the same trololo solution as me: keep an interval tree that allows operation 3 and is able to find the largest number in a given interval along with its position; when performing operation 2, just keep taking out the largest number and moduling it until there are no numbers  ≥ x; sums are then handled by a Fenwick tree.

I have a nice proof of why it works: consider a number a and applying a = an = a%x on it for various x. If such an operation had any effect, then either or the next modulo that has any effect is , or it's . In the second case, , and in the third, . We can see that after 2 modulos do something, a must decrease at least 2 times, which can only repeat times. Therefore, the total number of actions for all operations of type 2 is and with lookup and related updates, plus the cost of processing the other queries, gives total time complexity . WIN!

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

    It's quite right. You can think about how to solve it when operation 3 is segment modify.

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

      i don't know way My Solution got TLE, for operation of type 2 i update an interval if maximum number in this interval is >mod.

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

        Updates all numbers in the interval or just the ones that are actually larger? It's a huge difference in complexity.

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

          it's a segment tree, if int an interval C , node[C].max<=mod then i return other wise i process this interval with calling upd(i*2), upd(i*2+1), i think this should update only bigger number ans skip the other ones.

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

            Sounds like it should work, maybe it's just a problem with constant factors.

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

              maybe, that's disappointing :(

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

                Looking at your code's times: or maybe an unlucky infinite loop. Or I'm wrong and it's really too slow, maybe by little and there's an evil test. Who knows...

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

        There is bug in function updmod: nd[i].m=x;

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

    Same as your solution, but I used a division into sqrt(N) blocks instead of a segment tree (and for each block I maintained a multiset with the sorted elements, in order to easily update only the needed numbers at each modulo operation). I was very reluctant to implement this and I thought quite a long time about how I could "compose" two modulo operations, but after not finding any way of efficiently composing them, I implemented this just in case :) Still, it could have TLE'ed, because of the sqrt(N) factor (compared to only a log(N) factor in the segment tree solution), but it didn't.

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

I guess it would me more correct to put Div2 C problem worth 1000 points.

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

I am really surprised by the elegant solution for Div 1 A ( min of each end of an edge ). It's like instead of removing the nodes, we were just cutting the ropes.

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

At the start I opened Div1 problems instead of Div2 and thought the problems look much tougher than the usual rounds. So I checked the dashboard and found 230 people had already solved A(Div2 C) so I decidded to manage it somehow and started working on it. I got the idea in a few minutes and thanks to my poor internet connection after reconnecting 2-3 times when I finally tried to submit it showed "You must be registered to submit" error. Only then did realize my mistake and finally solved my first problem C in contest time. :D Earlier I did not even read problems beyond B because I thought they are too hard for me. But after this I think I will atleast read all problems after solving A and B.

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

3 минут не хватило, чтобы сдать Е. I am sad panda

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

    а почему в дорешку до сих пор не засабмитил?

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

      Засабмитил. Оказалось, что с ошибкой ;)

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

        Логично :-) А я не увидел AC в архиве и решил, что не засабмитил.

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

          Ну вот теперь есть. Была неприятная бага в том, какие массивы перемножать во второй раз

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

Prob C Div2 which is Prob A div 1 is it a greedy or DP problem ?

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

    It's a "don't think hard, think smart" problem. Read the comments above before asking.

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

    As I thought (it might be wrong), we can add to sum minimal cost of line from a to b or from b to a for every line.

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

    Greedy.

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

      do u mean remove the nodes in decreasing order of ? if so, can u give a proof for this?
      i couldn't prove it during contest, so i just checked that it worked for all sample cases (and 2 more of my own), and implemented it!

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

        Yup, remove the vertices in decreasing order of vi. It's obvious that you can do it, and that this way, each edge will be removed exactly once, adding cost vi to the total. Also, when an edge is removed, it adds to the total cost v of one of its endpoints, so this greedy gives the total cost equal to this lower bound.

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

          will, can you please explain this case

          5 4
          10 20 20 20 20
          1 2
          1 3
          1 4
          1 5
          
          • »
            »
            »
            »
            »
            »
            10 лет назад, # ^ |
              Проголосовать: нравится +27 Проголосовать: не нравится

            My name isn't Will :D

            We have 4 parts connected to a central one. Removing each of those 4 parts costs us 10, and that's what we get when taking min(v1,vx) for x=2,3,4,5.

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

        When we remove vertex i, we get a cost from vertex j (namely vj). Assign this cost to the edge ij. Then the total cost required is the sum of costs of all edges.

        Note that each edge is only counted once (when removing one of its endpoints; removing any other vertex doesn't affect this, and removing the second endpoint has no effect as the first endpoint has gone), and its value is the cost of one of its two endpoints. Thus we minimize the total cost by minimizing the costs of all edges, namely by choosing the smaller cost for each edge.

        When we remove the nodes in decreasing order of vi, we always assign the smaller cost to each edge. Suppose for edge ij, we assign the value vj, but vi < vj. Then we should have removed vertex j first and assigned the value vi to the edge, contradiction. Thus we have assigned the smaller cost to every edge, and thus we have obtained the smallest total cost.

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

          Nice explanation. I also couldn't proof it during contest.

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

          nice proof. thanks a lot! :)

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

          I tried to find the i-th node having the minimum sum of energy of its connected j-nodes and removed the i-th node iteratively. I was wrong hoping that greedy approach would work here :( I did not think that removing minimum sum cost of connected node can have its own energy values too high and thus increasing the total cost. Still I understood my mistake and i hope i don't commit this mistake again

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

            The solution is actually greedy, but in a different greedy way (take the vertex with the largest cost every time).

            Your solution fails for the following:

            3 2
            3 2 2
            1 2
            1 3
            

            A vertex with cost 3 is connected to two vertices with cost 2.

            Your solution dictates that as both of the cost-2 vertices have lower minimum sum of costs (namely 3) as opposed to the cost-3 one (namely 2 + 2 = 4), you remove one of them first. This way you get an answer of 5, while the optimal solution is 4 (remove the cost-3 vertex first).

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

Как нужно было решать Div2 C?)

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

    Надо понять, что в результате мы по одному разу возьмём каждое ребро, а к ответу прибавим одно из значений на конце каждого ребра. Тогда, чтобы минимизировать сумму, нужно всегда брать ребро за конец с максимальным значением. Что приводит нас к решению, где нужно просто на каждом шагу брать вершину с максимальным значением.

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

      Спасибо)

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

      Можно просто для каждого ребра прибавить минимум из вершин, с которыми оно инцидентно.

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

        Ну, это если хочется сдать за пять минут. А вот если хочется за десять-одиннадцать, то надо ещё всякой бесполезной фигни поделать.

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

Hi setters, I really like at least those problems I had a chance to read — A, B, C, D in DIV2, thanks ;-)

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

Поздравляю Alex_2oo8 с первым местом o_O

Так держать!

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

    Спасибо о_О

    Просто повезло, что уже решал задачу C раньше...

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

Any hint for task D div2?

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

At first, I didn't know how to solve A and got WA twice. Then, I checked Status and noticed that the memory usage of those who passed pretests was too low. I realized that I didn't have to make an adjacency matrix XD

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

Nice round. It seems that the ones who predicted there won't be any accepted solution to E where right. I want to ask what are some good materials on FFT (because Wikipedia gives a lot of probably interesting stuff, but they seem too mathy to apply in any programming contest task). Thanks in advance.

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

hacking at DIV2 was like hell :D pretty contest,thanks vfleaking

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

I think that the test cases for Div1D are weak because many users get accepted solutions using O(NlogN) for operations type 2. For example Petr solution: 6770456

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

    It's in average, because each number X can be decreased with operation Mod only times.

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

    I explain it here

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

      consider this test case

      N = M = 10^5

      all elements a[i]=10^9

      all querys of type 2

      1st — [1 N] x=10^9 — 1

      2st — [1 N] x=10^9 — 2

      3st — [1 N] x=10^9 — 3

      ..

      what is the complexity for this test case?

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

        LOL, after the first query all numbers will become 1's, so other ones will be processed in O(1) time.

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

    the time limit is 4 secs. And it is not O(nlogn) for operations type 2. When the maximum of an interval is smaller than the mod number, this interval can be skipped, because x%m=x, when x<m. Then if x>=m,we can get x%m<m, so the number decrease very fast.

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

    That's because a number won't be done modulo operation efficaciously too many times.

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

    Solution of 1D works in O(MlogNlogMAX) , we can use potential method to prove it. Let's assign the potential of number P be logP, then if that number is changed by operation 2 its potential decreases at least 1. And then build an interval tree which supports dynamic RMQ problem, and while working on operation type 2 first check if the maximum element in range(l,r) >= M, then process it on that number, until such number doesn't exist in asked range.

    We can see that:

    Initially: the potential of the sequence <= NlogMAX

    Operation 1: costs O(logN) time, and potential doesn't change. Amortized complexity = O(logN).

    Operation 3: costs O(logN) time, and potential increases at most logMAX, as we need O(logN) time to clear 1 unit of potential, amortized complexity is O(logN + logNlogMAX).

    Operation 2: We need O(logN) time to check the maximum <= M, and because the time to clear potential is included in operation 3, this is not counted in total time.

    Summing up all these cases gives us O(MlogNlogMAX) total time complexity

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

Мне неясно почему в задаче A DIV.2 в 28 тесте ответ С, а не A?

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

    Два хороших ответа: A и D. Значит, мальчик выберет ответ C

    1 по крайней мере в 2 раза меньше и 2, и 4, и 8

    А 8 по крайней мере в 2 раза больше и 1, и 2, и 4

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

      could both write in english for everyone understand? or translate in google like me

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

        It's because hball1st forgot to check Russian language when writing the comment.

        hball1st: Why in Div2 A "C" is answer to 28-th test, but not "A"?

        me: Two good answers A and D. So, boy will choose answer C

        1 is at least 2 times less than 2, 4, 8

        And 8 is at least 2 times greater than 1, 2, 4

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

        Google translation is convenient...but the result may be strange for understand....

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

    Потому что D длиннее всех остальных вариантов как минимум в два раза, а значит у нас есть два хороших варианта, в таком случае мы должны выбрать С. upd: не заметил ответ выше :)

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

    answer D and A satisfy the conditions

    in this case you should print C

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

BOOOOOOOP!

I just found out what my WA in div1 B was about. I forgot to add 1LL* once...

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

    Perhaps you won't forget it any more~ XD~

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

      I doubt it. It isn't really forgetting, just that I don't write it even if I realize that it should be there, and don't notice it. I don't really have time to check my code line by line and compare it with my idea of the algorithm.

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

        when it comes to this kind of problem, especially in the problem there is a sentence like "please use 64-bit....." I always declare all the variable as long long.....

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

          It can still fail. Suppose that you're actually multiplying vector/string sizes — you'd still need to cast them, and if you're used to thinking "if I declare all as long long, then it's fine", you can fail in that case.

          Everything can fail, especially if you just unexplainably don't write something.

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

I finish my div1D code at 1:59:59, and submit it...then unfortunately,out of time,just a second.... then after system test....I submit it again, accepted.what a sad story...

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

Problem Div1 C is similar to this problem Ears Cutting

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

I used a DP solution for DIV2 B to collect the sum which gave TLE at system test

and i thought of DIV2 C as a graph problem

I wasn't pretty sure about disconnecting the node which has a minimum-cost neighbors, maximum neighbors or the node which has maximum cost and none of them gave me optimal solution.

i'm going really down today but Great contest!.

Lesson learned, Never overestimate the problem!

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

    Honestly speaking, I solved DIV2 C using greedy algorithm, which was really out of my expectation.

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

    How is your dp then? Actually using dp and simple backtrack can run in linear time, should be fast enough

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

      Hi icalFikr, could you please explain the dp method? Thanks

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

        I'm not pretty sure if its called DP or else

        Suppose we have range [0..X], we can make every number from 0 to X with lowbit of some elements from set S.

        If we add one more element from S, supposed to be M. We can update range become [0 .. X + lowbit(M)], the proof is really easy. So, range [X + 1 .. X + lowbit(M)] can be arranged by M as last component.

        After we precalc last component for each X <= sum, we can backtrack the query and find all of components of sum.

        Sorry for my bad english ^^

        Here is my solution if you want to know more

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

please update the ratings soon

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

Very nice contest in this special day. Problems was very interesnting to solve, and the div 2 A problem was like a bomb for hacking. I want more contest from you vfleaking

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

подскажите почему в задаче А вот такой тест дает ответ А

сам тест

A.aaaa

B.aa

C.a

D.a

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

    "Why the answer is A and not C?" -- Google Translate

    C and D aren't great, because the 1-character C is not twice shorter than the 1-character D. However, if we modify the case:

    A.aaaa
    B.aa
    C.aa
    D.a
    

    Then yes, A and D are both great, and so the answer is C.

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

What is the complexity of optimal solution for Div2B?

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

why have you added test case on div 2 B problem after the contest

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

the sad thing is that the only one who submit E problem got WR in testcase 15 :(

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

im not convinced with the solution of problem C Div2 does any one has any proof for it ??

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

my rating was not changed :D

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

Wow, kids from China. such a great round!