Автор awoo, история, 3 года назад, По-русски

Привет, Codeforces!

В 14.01.2021 17:35 (Московское время) состоится Educational Codeforces Round 102 (рейтинговый для Див. 2).

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Роман Roms Глазов, Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

Также от наших друзей и партнёров из Harbour.Space есть сообщение для вас:

Привет, Codeforces, и с Новым годом!

В начале 2021 года мы хотим познакомить вас с новыми возможностями!

Несомненно, в Harbor.Space всегда рады видеть участников сообщества Codeforces среди своих учеников! Наши главные приоритеты — молодые таланты, которые хотят учиться, бросать вызов самим себе и стремятся к постоянному развитию.

Вот почему мы хотим объявить о нашей ученической программе.

Наша миссия — способствовать налаживанию взаимодействия между многообещающими молодыми талантами, представителями технологической индустрии и преподавателями-новаторами. Мы постоянно работаем над поиском идеального совпадения талантов и компаний.

Узнайте об истории успеха одного из наших первых студентов, обучающихся по этой программе.

Дэвид — специалист по UX/UI из Грузии, получивший полную стипендию от венчурного фонда OneRagtime.

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

Желаем удачи и до встречи в следующий раз!

Harbour.Space University

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

Место Участник Задач решено Штраф
1 jiangly 7 201
2 hank55663 7 210
3 BigBag 7 282
4 Lawali 7 283
5 FluffyT 7 306

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

Место Участник Число взломов
1 ariloc 35:-1
2 smax 34:-9
3 mrkarlo 27:-5
4 VTifand 19
5 BlueGagosipda 21:-22
Было сделано 242 успешных и 872 неудачных взломов.

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

Задача Участник Штраф
A Geothermal 0:01
B Geothermal 0:02
C SSRS_ 0:09
D Alfalfa_w 0:09
E _FlyingColor_ 0:16
F Apsara 0:40
G tfg 0:48

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

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

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

Hope this time it will be real educational and not just "educational". Anyway good luck to everyone!

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

Don't forget to notice the usual start time!

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

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

Congratulations to David! It is cool to see internship and job opportunities on CodeForces, even though they are not directly related to competitive programming. Many people start CP to improve programming skills in general, and Educational Contests work well to tie these fields together.

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

My first contest in CF ;)

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

pikmike -> awoo

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

Hoping for a round which is educational

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

    Educational rounds have never failed to be educational bro, you don't need to worry about that :)

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

If we hack any solution, will we get any points in this contest?

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

When people find out this guy IS pikmike, they are like: awoo

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

My first contest drunk ! Less gooo !!!

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

nice C. Also i have no idea why my B, D got AC. Someone please hack them.

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

IITKWPCJ — Harder version of B by PraveenDhinwa

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

D is segment tree isn't it?

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

    Yes just keep track of the minimum and maximum prefix sum

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

    I solved it using prefix and suffix arrays.

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

    might be, but will be an overkill.

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

    yes but my code is very large and weird. Waiting for another solution (if there exist one)

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

    No segment tree, required, for both prefix and suffix store the maximum and minimum sums.

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

    I didnt manage to finsih the code but it is :

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

    I used a sparse table, though it could have been done by maintaining a minimum of prefix/suffix and a maximum of those two.

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

    The trick is to avoid all possible off-by-one errors. I did by try'n'error for about an hour.

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

This contest made me realize that I should maintain a segment tree library.

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

How to solve E? I tried using Dijkstra but it didn't pass

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

      I did something similar here But I kept getting WA on test 5 and now I check there's only 1 number that differs I don't know why

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

        it's just showing that 1 number differs but actually there are more if you look carefully

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

      Why you can choose an arbitrary edge to add or subtract? Did I misunderstand the problem?

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

        Its kind of greedy. Notice that you are looking for the shortest path between node 1 and all others. If you must take the cost of some edge twice, It is always best to take the smallest edge weight on the path. Similarly, If you are allowed to remove the cost of one edge on the path, it is always best to use the largest edge weight on the path. Dijkstra naturally takes this into account.

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

    We can convert edge {u, v, w} to three edges {u, v, w, 0}, {u, v, 0, 1}, {u, v, 2 * w, 1}. The fourth element in the edge is use as minimal or as maximal edge. Introduce Dynamic Programming d[v][flag1][flag2] — minimal answer in vertex v, where flag1 = 1, when we used maximal edge, and where flag2 = 1, when we used minimal edge. Calcing the Dijkstra. Answer for vertex v is d[v][1][1]

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

How to solve C ??

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

    It was too complicated for me to find and proof the solution and thus i brute forced and observed the pattern .

    from i=1 to 2*k-n-1 you need to print i itself . After that you need to start from k . For example for n=5,k=5 : 1 2 3 4 5. for n=6 , k=5 : 1 2 3 5 4 . n=7,k=5 : 1 2 5 4 3 . n=8,k=5 : 1 5 4 3 2 . n=9,k=5 : 5 4 3 2 1.

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

    It can be proved that the number of inverse of array B must be more than or equal to A regardless of any permutation. I separated array into two parts p[1],p[2],...p[k-(n-k)-1] and p[k-(n-k)],p[k-(n-k)+1],...,p[k],p[k-1],p[k-2],...,p[k-(n-k)]. If you take a look at the latter part, you can see that, for any pairs of i<j between k-(n-k) and k, there is always one p[i] appeared before p[j] and another p[i] appeared after p[j]. So the number of inverse in the latter part is always constant because any pairs of i and j have exactly 1 inverse. In the first part, the number of inverse in array A is 0 because it is arranged in ascending order and every elements of first part in array A in less than second part. So basically, we have to create any array that the first part is the same as A(or else inverse will be more than A) which is 1,2,3,...,k-(n-k)-1 and second part can be any permutation of k-(n-k),k-(n-k)+1,...,k. and lexicographically largest permutation is k,k-1,k-2,...,k-(n-k).

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

    I'll try to explain with examples

    Let's use $$$k = 5, n = 9$$$
    Initially
    $$$P$$$ = $$$1, 2, 3, 4, 5$$$
    And $$$B$$$ = $$$1, 2, 3, 4, 5, 4, 3, 2, 1$$$
    Notice when you swap $$$5$$$ with $$$4$$$ in $$$P$$$ It doesn't change the number of inversions (because of the mapping b[i] = p[a[i]])
    $$$P$$$ becomes $$$1, 2, 3, 5, 4$$$
    And $$$B$$$ becomes $$$1, 2, 3, 5, 4, 5, 3, 2, 1$$$
    So you can continue swapping the largest number to the left as far as the number you want to swap with has a duplicate value on the right-hand side of $$$B$$$

    Let me use a smaller example
    You have $$$k = 3, n = 4$$$
    $$$P$$$ = $$$1, 2, 3$$$
    $$$B$$$ = $$$1, 2, 3, 2$$$
    You can swap $$$3$$$ to the left once in $$$P$$$
    $$$P$$$ becomes $$$1, 3, 2$$$
    $$$B$$$ becomes $$$1, 3, 2, 3$$$
    And you can't swap $$$3$$$ again
    Because if you swap it left you will increase the number of inversions

    In general
    If you have a sequence $$$P$$$ = $$$1, 2, 3, 4, 6 ... k$$$ and $$$n$$$
    Reversing the last $$$n - k + 1$$$ in values in $$$P$$$ is your solution and the number of inversions remains the same.

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

      why don't we just stop after swapping the last two elements? Can you please explain that because I can't find a test case where just doing that will fail.

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

        ya exactly. i did this as well. a: 1,2,3,4,5,...k-1,k,k-1,k-2,k-3..k-(n-k) b: 1,2,3,4,5,...k,k-1,k,k-2,k-3,...k-(n-k) the only difference is the 3 numbers in middle. in A they gave 1 inversion. in B also they are giving 1 inversion. and for the rest of k-3,k-4,k-5....2k-n,the number of digits greater before them remain same. so in all cases inversions remain same and b is lexicographically greater. and when n==k just print 1,2,3,....k-1,k. pls explain if anyone sees a fault in this

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

          maybe the question wants us to create the greatest possible lexigraphic configuration and not just greater. haha! we were so close to the solution dude.

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

            oh hmmmm. b is lexicographically maximum. i thought amongst a and b, b must be greater. cool my fault then. thanks mate

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

        Maybe this will help
        Full visualization for $$$n = 7$$$, $$$k = 4$$$
        $$$P$$$ = $$$1, 2, 3, 4$$$
        $$$B$$$ = $$$1, 2, 3, 4, 3, 2, 1$$$
        Swap $$$4$$$ and $$$3$$$ in $$$P$$$
        $$$P$$$ = $$$1, 2, 4, 3$$$
        $$$B$$$ = $$$1, 2, 4, 3, 4, 2, 1$$$
        Swap $$$4$$$ and $$$2$$$ in $$$P$$$
        $$$P$$$ = $$$1, 4, 2, 3$$$
        $$$B$$$ = $$$1, 4, 2, 3, 2, 4, 1$$$
        Swap $$$4$$$ and $$$1$$$ in $$$P$$$
        $$$P$$$ = $$$4, 1, 2, 3$$$
        $$$B$$$ = $$$4, 1, 2, 3, 2, 1, 4$$$
        Swap $$$3$$$ and $$$2$$$ in $$$P$$$
        $$$P$$$ = $$$4, 1, 3, 2$$$
        $$$B$$$ = $$$4, 1, 3, 2, 3, 1, 4$$$
        Swap $$$3$$$ and $$$1$$$ in $$$P$$$
        $$$P$$$ = $$$4, 3, 1, 2$$$
        $$$B$$$ = $$$4, 3, 1, 2, 1, 3, 4$$$
        Swap $$$2$$$ and $$$1$$$ in $$$P$$$
        $$$P$$$ = $$$4, 3, 2, 1$$$
        $$$B$$$ = $$$4, 3, 2, 1, 2, 3, 4$$$
        So the final value for $$$P$$$ is $$$4, 3, 2, 1$$$
        Notice the inversion never increases or decreases

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

      I wish I could upvote you twice. No youtube videos really helped but your comment did. Thanks Sir. Now I can sleep well ;-)

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

Is it possible to solve D in linear time? Only issue I had was how to find minimum and maximum for suffix. For prefix it's easy.

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

    Lol! reverse the original array.

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

    if you found the solution for prefix ,why you didnt reverse the array and did the same thing?

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

    You don't need to find maximum/minimum prefix of suffix. Instead, you can calculate sum in two segments and substract minimum/maximum suffix, which can be calculated similar to minimum/maximum prefix.

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

    first traverse from front then from back, keeping track of current position and max. and min. it has reached.

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

Could someone please explain why the answer for vertex 7 in test case 3, problem E is 3?

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

How to solve D, anyone can explain?, i got run time exceed

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

    I tried square root decomposition and was expecting it to work But got TLE because I use Python RIP. Maybe it should work in CPP O(M root(N))

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

This contest made me realize that I should maintain a segment tree library.

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

how to solve D and F ? Anyone explain.

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

    D can be solved by range minimum & maximum queries in Segment tree.

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

    I did D by maintaining prefix and suffix minimums/maximums without segment trees. Just eliminate the effect of l to r by adding the cumulative sum to the min and max of the remaining suffix array. The answer is total_max — total_min + 1 Total_min and total_max are overall min and max(from prefix array and suffix array before l and after r respectively) after eliminating the effect of the segment l to r

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

      Thanks, I understood it now.

      I was thinking of Adding the cumulative sum to all elements in suffix array and then to eliminate duplicate elements (which was not even needed...)

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

      Can you explain the logic behind adding the cumulative sum to the min and max of suffix array ? I cant understand it very well.

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

        Hey, so you would add the cumulative sum to nullify the effect of the segment (l to r), instead if adding it to the whole suffix array, you can only add it to min and max because the change is uniform. You only need min and max from the prefix and suffix because all the points between them will be travelled automatically (because the step size is only 1)

        PS — you can imagine it like a continuous graph, in which you remove a segment in between and join the ends if the other 2 segments, you have to bring the right end up or down to meet the left end ( so you add the cumulative sum * -1 which can be positive or negative to negate the effect)

        Idk if this is helpful, not so good at explaining stuff

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

        We need to observe one thing that if we want to know the distinct numbers possible in some ++--+-+++... string then the no of distinct possibilities are mx — mn + 1. (mx is max no possible and mn is min no possible).

        consider 4 vectors pre_ma, pre_mi, suff_ma, suff_mi

        while calculating these vectors we consider that value of x starts from 0

        pre_mi[i] — what is the min value that we came across until index i if we started from index 1.

        pre_ma[i] — what is the max value that we came across until index i if we started from index 1.

        suff_mi[i] — what is the min value that we came across until index N if we started from index i

        suff_ma[i] — what is the max value that we came across until index N if we started from index i.

        Now for each query, we have to consider 1 to l-1 and r+1 to N as combined string and do these operations. Instead we find the max and min possible values differently for both of these prefix and suffix strings.

        So, for prefix string since the value of x starts from 0 we can directly consider pre_mi[l-1] and pre_ma[l-1], but for this suffix string the value of x doesn't start from 0, (But we have stored the vectors if the value of x starts from 0), but this suffix string starts at some value X (Here X denotes the sum of prefix string). so we have to consider (X + suff_mi[r+1] as the min value occured in this suffix string) , same goes for maximum in suffix string.

        Final answer would be max(suffix max val , prefix max val) — min(prefix min val, suffix min val) + 1.

        Link to my code

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

Hi, I encountered some strange errors while submitting a solution in Java for Problem D in the Codeforces Educational Round 102,

The code works perfectly in my local system, it even works correctly in an online Java Compiler(OnlineGDB). However, it was unable to read strings correctly in the Problem D.

My Submission: 104337369

Could someone please guide why this is happening..

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

can i know the aproach for problem div2A

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

    traverse the input array, if there is no number greater than d, print yes. Now sort the array. If the sum of first two numbers is less than or equal to d, then it means that any number which is bigger than d can be replaced by the sum of these two numbers. But if their sum is not less than or equal to d, then we can be sure that no other sum in this array will be smaller than this. therefore, after sorting

    if(a[0]+a[1]<=d) print yes else print no

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

Editorial, please

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

$$$D$$$ was easier than $$$C$$$ at least to me.

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

    Same for me, I find it hard to beleave that so much people solved C. It looks kind of unsolvable to me, I still did not read any near-to-understandable explanation.

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

      The only thing you need to notice is that in the segment $$$[k - (n - k), ..., k, ..., k - (n - k)]$$$ no matter what permutation you choose the number of inversions in this segment will not change (and will equal $$$(n - k)^2$$$ but that's extra info irrelevant here).

      So you can't afford any other inversion hence the head of your list must be $$$[1, 2, 3, ..., k - (n - k) - 1]$$$. Now to get the maximum lexicographical sequence you should transform $$$[k - (n - k), ..., k, ..., k - (n - k)]$$$ to $$$[k, k - 1 ..., k - (n - k), ..., k - 1, k]$$$ and to do so we use the permutation $$$[1, 2, 3, ... k - (n - k ) - 1, k, k - 1, k - 2, ..., k - (n - k)]$$$

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

        How do you prove that no matter what permutation you choose the number of inversions in this segment will not change and will equal $$$(n−k)^2$$$ ?

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

          Thats the part I did understand. This is, because if you change two (or more) numbers to each other, you allways change two of such pairs.

          As an example, that part of the list looks like:

          3 4 5 4 3 So, no matter which digits are exchanged to each other, it allways happend twice in respect to the positions, and hence number of inversions.

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

        So if $$$b = [k - (n - k), ..., k, ..., k - (n - k)]$$$ and $$$p = n - k$$$, $$$size(b) = 2p+1$$$.
        By symmetry,

        $$$inv(b) = \# \left\{ i<j | b_i>b_j \right\} = \# \left\{ i<j | b_i<b_j \right\}$$$

        Then,

        $$$ 2 inv(b) = \# \left\{ i<j \right\} - \# \left\{ i<j | b_i=b_j \right\} = (size(b)-1)size(b)/2 - p = 2p^2 $$$

        Finally,

        $$$inv(b) = p^2 = (n-k)^2$$$
    • »
      »
      »
      3 года назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      might be because of massive cheating again . From coding perspective it was only 2-3 line solution and thus it was easy to spread and fool the moss .

      To be honest it was way difficult than D and very incomprehensible.

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

        Well, now, like 12 hours later, I think I understood the problem. Maybe I just needed a bit longer than other people.

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

          seeing your current and maximum rating it's hard to digest you couldn't solve it and lot of people did . Something fishy going on these days.

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

            Not so sure, it's easy to guess the solution to the problem. In contest, you don't have to understand why it works.

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

              In contest, you don't have to understand why it work

              Then i would get WA on pretest 2

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

                I guessed the solution at the beginning, tested on some small test cases, gained some intuition to why it works, and YOLOed. In contest, many people don't do the second part, much less the third. When you have no other ideas, sometimes its fine.

                I'm not saying there was no cheating or anything, just saying that I don't think the solve count is too suspicious — you kinda see the pattern when you look at enough test cases.

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

      It was quite easy to analyze some cases with backtracking and then observe the pattern. Maybe this was the reason of so many AC's.

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

    Can you explain how did you do D?

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

How to solve problem F ?

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

    Build a flow network as follows: let's create a source $$$s$$$, a sink $$$t$$$, and a vertex for each element. We will try to model the problem as the minimum cut in this network.

    For every element $$$i$$$, there are several elements $$$j$$$ to the left of it that should be taken if we take it. Let's add a directed edge with infinite capacity from $$$i$$$ to all such elements. For elements will positive $$$b_i$$$, add a directed edge from $$$s$$$ to them with capacity equal to $$$b_i$$$. For elements will negative $$$b_i$$$, add a directed edge from $$$i$$$ to $$$t$$$ with capacity $$$|b_i|$$$.

    What does an $$$s$$$-$$$t$$$ cut in this network represent? Let's say that all elements in the same part with $$$s$$$ are taken into the answer, and all other elements are ignored. Let's say that we have some $$$i$$$ that is taken into answer and depends on some element $$$j$$$ that is not taken. Then there is an infinite-capacity edge from $$$j$$$ to $$$i$$$, and it goes through the cut, so the value of the cut is infinite (and we are searching for a minimum cut, so this cannot happen). For each positive $$$b_i$$$, if $$$i$$$ is not taken, the value of the cut increases by $$$b_i$$$ (since the edge from $$$s$$$ belongs to the cut), and for each negative $$$b_i$$$, if $$$i$$$ is taken, the edge from $$$i$$$ to $$$t$$$ belongs to the cut, so $$$|b_i|$$$ is added to the value of the cut. So, the minimum cut actually minimizes the sum of positive $$$b_i$$$ that are not taken, minus the sum of negative $$$b_i$$$ that are taken, so it gives us the optimal answer.

    There's one issue though. This network can easily reach $$$O(n^2)$$$ edges, and that's too much. To reduce the number of edges to something like $$$9n$$$, for each $$$i$$$, consider all divisors of $$$a_i$$$ (including $$$a_i$$$ itself) to the left of it. If there are several equal divisors, then taking the closest of them ensures that we take all other divisors into the answer, so actually, for each divisor of $$$a_i$$$, we need to consider only the closest occurrence of this divisor to the left of $$$i$$$, and add an infinite edge from it to $$$i$$$.

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

      This might be a dumb question (I'm pretty new to flows), but what would be the complexity of this algorithm? Using Dinic's, wouldn't this be $$$\mathcal O(V^2E)$$$, and with $$$V = 3000$$$ and $$$E \approx 9 \cdot 3000$$$, shouldn't this TLE? Or there also just might be some property about this flow graph that makes Dinic faster that I'm not aware of.

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

        The distinctive feature of many flow problems is that it is either very hard or even impossible to construct a testcase on which an algorithm performs anywhere near its worst-case complexity.

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

          Ah, that makes sense. I guess if a flow solution exists, it's always worth to try it and see if it passes. Thanks for the reply!

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

        Yes, I've also considered this problem. In fact, the model solution is written with the implementation of maxflow in $$$O(VE \log F)$$$ (Dinic with scaling), so asymptotically it should be fine. But my implementation of regular Dinic also passes all of my test cases, I haven't found a test case which it gets TL on.

        So, actually, we have a 100% working solution, but we guess that some asymptotically bad solutions might pass.

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

        In this problem a path saturates a source edge or a sink edge always because the other edges have infinite capacity so the actual complexity is O(V paths) * O(E for finding a path) for any max flow algorithm.

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

Suspicious submission for hacks I think the hacker made an alternate account for hacking this.

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

Screenshot-320

It hurts!

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

Whoever concocted this is genius. They've practically lined themselves up to be caught.

https://codeforces.com/contest/1473/status/A?order=BY_CONSUMED_TIME_DESC

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

VIDEOTUTORIAL FOR PROBLEM A AND B WITH DETAILED EXPLANATION . I ALSO TRIED TO EXPLAIN LINE BY LINE CODE . I HOPE YOU GUYS WILL ENJOY THE VIDEO LINK PROBLEM B :https://www.youtube.com/watch?v=H3qBEDYwwX4 LINK PROBLEM A :https://www.youtube.com/watch?v=YjC6CcxYxo8

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

In problem $$$C$$$, It's never said that $$$b$$$ has to be the sequence with the least number of inversions. It can be found that number of inversions of $$$a$$$ is $$$(n - k)^2$$$ and the sequence $$$b$$$ builds off the permutation $$$1,2,..,k,k-1$$$ also has the equal number of inversions as $$$a$$$ and it should suffice to be the solution when $$$n > k$$$.

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

    It's never said that $$$b$$$ has to be the sequence with the least number of inversions

    True, but it is said that

    [...] and $$$b$$$ is lexicographically maximum.

    Also note that

    It can be proven that $$$p$$$ exists and is unique.

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

    I think you missed the requirement where B must be lexicographically maximum.

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

Screenshot-320

It hurts!

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

    roz adhoc problems karke man nahi bharta kya patang udao gilli danda khelo! come out of this artificial life.

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

Problem C and D video solutions — solution

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

Unable to understand C even after looking the to the test cases that didn't passed. Anyone here could you please help me with proper understanding of C.

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

Hey, I have a doubt regarding problem C.Is the number of inversions in 1 2 3 2 1 is same as that in 3 2 1 2 3?

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

hey someone please help me to debugging my code i got WA in test case 8 of problem E;

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

    Your bfs solution is incorrect because edges in this task are weighted and that's why bfs won't work in this case. Try to use Dijkstra algorithm.

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

https://codeforces.com/contest/1473/submission/104345925 can someone explain what's happening here?

while time.time() &mdash; cur < 1.7:
    pass
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +9 Проголосовать: не нравится

    I think this violates Rule #6 by destabilizing the checking system (trying to increase the queue size by increasing the running time)

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

I have a big question could anyone tell me in Problem E how in the third sample the minimum weight to vertex 5 is 7? I can't find a path with lower than 8

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

Hey all, if you missed the post-contest stream that I did on https://www.twitch.tv/stevenkplus, here is the youtube recording: https://youtu.be/3o1Na9Qnaio.

Will edit this comment with links to my submissions (containing solution notes) once I perform the submission process :)

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

Problem E is really cool! I don't know why I didn't consider traversing an edge twice.

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

For anyone stuck in D, https://youtu.be/mMFkvyeRFQY

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

People using Segment tree and MO's algo in problem D

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

    Nah, seg tree is really close to the linear solution anyway.

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

Does anyone have any idea what's the mistake in all the solns of E that were hacked?

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

    if(no.a>dist[no.b.a][no.b.b])continue;

    it the pair in the priority_queue has more distance than the shortest
    path found till now then don't iterate further.Codes which didn't
    add this condition got hacked(TLE).weak pretests

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

I got lucky for problem C. I somehow looked at the testcases and figured out what to do. This has happened to me in previous contest too . xd

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

can someone instead of flexing that it can be solved by prefix/suffix sum explain how to solve D . I know prefix,suffix but i don't know how to use that in this problem.

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

    create the following arrays :

    MaxTillHere[] -> stores the max value upto a particular index MinTillHere[] -> stores the min value upto a particular index

    then, using backward traversal create the following array :

    MaxFromHere[] -> stores the max increase we'll get after a particular index MinFromHere[] -> stores the max decrease we'll get after a particular index

    now the answer is simple, for each query (l, r) : int max = MaxTillHere[l — 1] + val[i] + MaxFromHere[r] int min = MinTillHere[l — 1] + val[i] + MinFromHere[r]

    ans = max — min + 1

    I hope my answer was clear. Some index value might be wrong here, but i hope you've got the gyst of the solution!

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

      you haven't solved this problem and telling wrong/incomplete solution .From next time solve it first. It's sad i can't take my upvote back.

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

        Here. I solved it just for you. Problem D solution

        Well you can downvote this one, if it makes you feel any better. Next time, either solve it yourself or don't bitch about people who try to help you.

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

When will the rating be updated for this round.

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

    Educational contest take too much time for ratings updation and editorial normally

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

То самое чувство, когда написал D, но профейлил с дп и не хватило 3 минут на отправку(

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

Video Tutorial for problem A,B and D link of problem D : https://www.youtube.com/watch?v=botAQ-AZNOQ

link of problem B : https://www.youtube.com/watch?v=H3qBEDYwwX4

link of problem A : https://www.youtube.com/watch?v=YjC6CcxYxo8&t=263s

Hope you guys will enjoy and understand the intution behind the solutions !!!

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

why did they temporarily roll the rating changes back ??

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

why i am getting negative points? i thought in 10 min solved no penalty

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

    Points are counted depending on other participants, most likely someone solved more or as many problems as you, but at the same time was the lowest rating

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

is it rated for the participants with rating greater or equal to 2100? i fount some people who geater than 2100 is rated

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

My rating was above 2100 before taking this contest, but it was changed because of it. Could anyone tell me why?

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

    I think it was applied as a rating when "Codeforces Round #695 (Div. 2)" is temporarily rolled back. At that time, our rating was lower than 2100.

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

Hello Codeforces!

I basically got a message that I cheated in this round, and that my rating won't change.

The message I got

I am writing this comment to inform to the codeforces headquaters that the plagarism check system has made a misjudgement.

I was pretty shocked to see this message and other people's codes.

They were similar, and some were even the exact same.

I found no code that was exactly the same to my code, but some were astonishingly similar.

Problem A in this contest was a very simple problem, that had a very simple solution, so there could be some coincidences in people's code.

Also, I confirm that I don't even have a telegram account and have never used Ideone or other online judjes in this contest.

I understand codeforces' work to catch cheaters to make codeforces a better community.

However, for the reasons I stated above, I want to get my rating back.

Thank you! :)

+) I am curious about when, and how I will get my rating back. Will the headquaters contact me via email or codeforces talk?

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

I took part in this unrated contest (for Div. 1) and found my rating changed afterwards. Why? Mistake?

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

Where is Editorial? Also Can you make problem statement clear? Problem C was so much confusing. I understood it only after reading examples.

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

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

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

I dont usually comment because of my low rating which gathers me downvotes...but the broad range of topics tested in this round, be it the use of data structures or algorithms in this round is appreciated. It didn't seem too adhoc like other rounds involved some known concepts to a perfect extent and again the breadth of topics of the questions- just amazing! Kudos to the authors of the contest. Well done! Editorial was fast, question statement lengths and test strengths were optimal. In short, one of the best contests I have ever participated on Codeforces.