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

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

<almost-copy-pasted-part>

Привет! В 21.04.2020 17:35 (Московское время) начнётся Codeforces Round 636 (Div. 3) — очередной Codeforces раунд для третьего дивизиона. В этом раунде будет 6 или 7 задач (или 8), которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

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

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

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

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

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

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

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

Удачи!

</almost-copy-pasted-part>

UPD: Также спасибо Sakhiya07, infinitepro и ma_da_fa_ka за тестирование раунда!

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

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

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

GL to all :D vovuh orz

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

GLHF to all, xD

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

is vovuh the only user who can make div3 contest ? i mean why every div3 contest in the past 5 or so are made by him?

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

    He is coordinator for div3 rounds .While Pikmike is coordinator for educational rounds series!

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

      what is the difference in educational rounds vs DIV rounds?

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

        THe differnce is that Educational rounds are rated for div2 (rating below 2100) and Div3 ones are rated for rating below 1600 thus their is differnce in problems and their difficulty. Educational Round is an Harbour Space University Initiative and they pick problems that are really meant for teaching new things to newbies like us and Div3 rounds are practice rounds for us for honing our skills of accuracy and implementing problems in a better way.

        Both of the rounds are similar in terms of hacking if we see as both allows hackers to hack others solution after the contests and also all problems have equal weight in both the type of rounds.

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

          Are you kidding me. It was supposed to like that. Div3 and educational div2 are fine. No doubt. But, if you think about teaching of new things, then normal div2 rounds also do this and some setters do this better like errichto.

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

            By the way the original question doesn't talk of normal rounds. Thus I didn't talk of it!

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

1

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

IMG_20200420_211652.jpg ..

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

When anyone else tries to make Div3 contests:

Vovuh:

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

I had a doubt: does 12 hour hacking phase mean that solutions can be hacked during this phase after the contest? Till now I used to think that we have to lock our problems and look at solutions in our room and hack them during the contest.

So which one is correct? Thanks in advance

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

I think 12 hours of open hacking phase is too much. It could be reduced to 4-5 hours while adding successful hacks to system testing. If it is for 12hrs for some reason, It is just a humble request to please help me know the reason.

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

    Contest timings are usually not favourable for everyone around the world. Yet, those who manage to participate might be participating at like midnight or something. Most people would prefer to sleep after the late night contest. To provide a good window and opportunity for hacking to such people, hacking phase seems to be 12 hours.

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

    What about people in other countries? For example, in China, the contests usually starts around 10 p.m. so we can only hack the next day.

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

I have started making video solutions on mostly D based problems of every codeforces round. The videos can be found here.

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

We want more contest in this quarantine :(

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

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

Pics-Art-04-21-07-20-28 ..

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

How can I make problems in a Div.3 round? I see that le.mur(he/she hadn't participated in any contests) was one of the authors of Codeforces Round 552 (Div. 3). My rating is 1591 now so can I make problems in Div.3 rounds?

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

Why are there "6 or 7 (or 8)" problems? Am I allowed to know how many problems there are?

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

Good Luck to everyone!!

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

looking forward to increasing my rating ..as always.. :)

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

![ ](img)

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

I think the problems will be more like implementation type! So, Be ready with your implementation skill @ 20.05!!

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

I wish the penalty was less(like the contests in Atcoder).

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

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

Good luck to you all and have lots of fun, coders!

As you got used to it, we will upsolve the most interesting problems of the round live at 8PM:

https://youtu.be/ppk9pXL9rR4

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

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

Thanks vovuh!We hope more Div.3 contests for our beginner )

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

I know u guys are already at it... but we need more contests in lesser time interval...upvote this comment if that's what u want too...so much hatred in this community :(why downvote???

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

    Nope. We want good quality contests.I don't mind if it takes more time because we always have the option of doing virtual contests.

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

    Always remember, we want good quality contests. A single bad contest can make people complain for a long time

    Good contests usually require more preparation.If you want to have more contests, you can do virtual ones(Since there are more than 600 rounds in the past, you will have a lot of work to do)

    See this contest for an example:AIM Tech Poorly Prepared Contest (unrated, funny, Div. 1 preferred)

    Although is a funny unrated round, do you want to have rated contest like this?

    View the past contest list, choose a contest and click "virtual participation" button to do virtual contests.

    By the way, if you want more upvotes, you can submit useful comments(for example, answer questions), but not asking for upvotes. People usually won't do things they are forcely asked to do if they don't want.

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

It would be great if you add contests more frequently like alternate days or one in 3 days. Happy Coding :)

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

This is vovuh's 37th Div-3 contest.

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

    In my opinion it is 36th contest. It is named "Div3 round 36" in polygon.

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

      You are right. Mike held one Div.3 contest without me (I don't remember its number)

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

this contest has become now as contest with most number of participants ...wow

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

26K+ participants. Simply WoW.

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

I hope this contest would be good unlike the previous one.

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

27k+ Registrants for this contest!!!

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

I hope this contest would be good unlike the previous one.

»
4 года назад, # |
  Проголосовать: нравится -20 Проголосовать: не нравится
Комментарий удален по причине нарушения правил Codeforces
  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится

    What was your Comment ??

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

      I had told that I think the first condition in problem D is not necessary because with the given definition of "replacement" it's impossible that we violate the first condition.

      I'd told this in a nice way and I thought it doesn't spoil anything about the problem so it doesn't violate the rules. But maybe it did. :D

      However... It wasn't such an important thing. The fun part is about downvoters who have never seen what I'd said. :))

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

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится
Комментарий удален по причине нарушения правил Codeforces
»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

 Such a difficult D.

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

    I am suprised so few people solved it, thought there would be 2-3 times more lucky solvers. I am 1300 elo and I did it! And I was even disappointed it took me so long. Seems my training worked out :D

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

    IMO it wasn't that bad.

    My solution I think is the most natural one arising from simply understanding the contribution of every index depending on the value of forced sum.

    You do some case analysis for $$$ u, v > k $$$, $$$ u, v \leq k $$$ and $$$ \mathrm{max}(u, v) > k, \mathrm{min}(u, v) \leq k $$$ and just make an interval tree, in which $$$ s $$$-th position corresponds to penalty for choosing the forced sum to be $$$ s $$$. Then a minimum query on the whole $$$ [0, 2k] $$$ gets you the answer.

    You need lazy propagation to build such a segment tree, though, but if you know that, it's pretty straightforward. The only pitfall here is debugging for an hour, like I did.

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

      Since you only have one query, isn't it much easier to only do offline prefix sums instead of the segment tree?

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

        It's not obvious to me how to do that actually. The core of my solution 77566384 is processing elements of the prefix one-by-one and adding on the interval and I don't know how to do that without segment trees or treaps.

        I think this can be unwrapped into some scanline approach to get rid of LP but again no idea how to do it in other ways. Could you elaborate?

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

          Yeah. You're somewhere close to the idea with a scanline. Though, I am a bit surprised as to how you know about segment trees but are unaware of the prefix sum approach to query.

          Let's say you have an array A of size N with elements a[i], i = 1 to N.

          You're given Q queries in each of which you need to count number of values less than(or equal) a given value Y and strictly greater than a given value X.

          So, build an array(or map), say freq. freq[X] denotes how many times X appears in array A.

          Now, create a new array(or map) pref where pref[i] is sum of freq[0] to freq[i].

          So, for each query (X,Y] your answer is pref[Y] — pref[X].

          Note: Time complexity becomes O(N + Q). This isn't recommended when there are update queries for array A too since that leads time complexity to O(N*Q) as you will have to rebuiled the pref array(or map). Note that space issues might also arise for large values if you use array.

          In the concerned question, the values don't go beyond 2*K at any point of time, and hence there won't be space issues.

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

          The scanline approach will efficiently find, for each point, the sum of values of all segments that overlap it. Consider any segment $$$[l, r]$$$ of value $$$v$$$. In the scanline, for this segment, you want all indices $$$< l$$$ to be worth $$$0$$$, all indices $$$l \leq i \leq r$$$ to be worth $$$v$$$, and all indices $$$> r$$$ to be worth $$$0$$$.

          The scanline will keep a running prefix sum of the values at each array element. To increase this prefix sum by $$$v$$$, simply increment the value at $$$l$$$ by $$$v$$$. This increments all values on $$$[l, n]$$$ by $$$v$$$. To make our range exactly $$$[l, r]$$$, add $$$-v$$$ to $$$r + 1$$$. Doing this for all segments before doing the scanline, the scanline's value at each point represents the sum over all segments overlapping that point, and you can take the minimum of the values at all points.

          An image that may be helpful
»
4 года назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

What is test 2 of D? Please.

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

What was WA29 in Problem E?

My logic was: Do a BFS from B. Find the node with max depth (say V) such that V to A and to V to C shortest paths exist — I basically conjecture that the common path will be a prefix, and once the paths bifurcate, they will never meet.

Then the answer can be calculated appropriately, by giving the smallest edge weights to the common path and the remaining smallest to others.

What's the countercase? I saw many people failing on WA29

Link to code: https://codeforces.com/contest/1343/submission/77543873

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

    Same solution here. WA on 29.

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

    Try this:

    6 6 1 4 6

    1 1 1 1 5000 5000

    1 2

    2 3

    3 4

    4 5

    5 6

    2 6

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

    for me i was just considering nodes on shortest path from a to b. when i removed that condition i.e checked for every node, I got AC.

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

    While your conjecture is correct, it is not necessary that the sum of lengths of paths ab and bc in the optimal answer is equal to the sum of lengths of shortest paths ab and bc.

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

    Issue with that approach is, the paths doesn't have to be shortest for both nodes individually, there can be a case that, individually path for A and C is not shortest from B, but because of common prefix being longer, total cost can be lesser.

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

    the first thing, ans must be long long, not int

    the second, i think you must try all v and the and is sum(1,BV) + sum(1,AV+BV+CV) (only if AV +BV +CV <= M )and get min

    because sum(1,BV) + sum(1,AV+BV+CV) not depend on p[i] or BV, it depend on both, so u want to try all

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

    You solution was wrong in a special case. You need check it can be the answer. Just BFS in the Edge 3 times,From A,From C,and the last From B To check it can be the answer.The total of V must <= M,and then to update the answer You should update the answer in every possible point. Hope it will help you.Good luck!

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

Great Round! Problems were very interesting. Just feel bad because I started around 20 mins late due to personal issues....

Solved ABC. Couldn't solve D (failed Test-2). Any ideas?

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

    Fix some $$$s$$$, which will be intended common sum of all pairs.

    1) Show that you can always change the sum of any pair to $$$s$$$ in 2 changes

    2) When can you change the sum to $$$s$$$ in 0 changes?

    3) When can you change the sum to $$$s$$$ in 1 change?

    Then, use some kind of data structure so that you can answer for all $$$s$$$ in $$$1 \leq s \leq 2k$$$ and get the min over all of them as your answer.

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

    Construct intervals for each pair as follows:
    Each interval corresponds to choices of $$$x$$$ where this pair can be shifted by changing atmost one element of the pair. For example: if $$$k = 4$$$, and the pair is $$$(2, 3)$$$, the interval is $$$[3, 7]$$$. Then, sweep through all intervals by moving one step at a time, from $$$2$$$ to $$$2k$$$. At each step, you can compute the current score by seeing how many intervals overlap at this point (the depth). You will also need to consider those intervals contributing $$$0$$$ at this point, which occurs exactly when $$$x$$$ matches the sum of the pair corresponding to that interval. All those intervals not covering the current $$$x$$$ must contribute $$$2$$$ to the score.

    https://codeforces.com/contest/1343/submission/77572280

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

      Seems like a great approach. Mine was too complex that I spent too much time and ended up not being able to solve it within contest time. Haha. Nonetheless, solved it with my approach.

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

    Thank you Shisuko and ameya! Understood both your solutions.

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

what is the greedy solution of D?

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

    I think, D is DP question. For each pair, calculate the maximum and minimum value, you can get in 1 change. Also calculate the number of pairs adding up to some x.

    min=min(a,b) + 1 max=max(a,b) + k

    Then maintain segments, and iterate from 2 to 2k, counting how many need less than one change. you know the ones needing no changes, so you can calculate the numbers needing one change, and the rest need two changes. Find the minimum of that.

    https://codeforces.com/contest/1343/submission/77536701

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

    Not sure if this counts as greedy or not, but anyways:

    Calculate how many pairs exist with this or that sum using a map. Enumerate all possible target per-pair sums. From each of them, the number of steps needed is n / 2 — — <number of pairs such that you can't reach the sum by changing one number>. The former is already in the map, the later can be computed if you notice that for pair <x, y> (WLOG assume that x <= y) the minimum that you can reach with one operation is x + 1, and the maximum is y + k (two binary searches can be used here). Then just select the best target sum and output the answer for it.

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

Great round, guys!

We are going live in 5 mins:

https://youtu.be/ppk9pXL9rR4

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

Great round, guys!

We are going live now:

https://youtu.be/ppk9pXL9rR4

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

People with rank between 2300 and 11100 all solved 3 prob, so you have 9000 person solved 3 problem, bad choice of difficulty of the problems IMO.

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

Wow, hardest problem A I have seen, I was able to solve B and C easily. But I got stuck on A. :(. Could anyone shared how they approached it? Thank you

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

    You have to find any a $$$P=2^K-1$$$, starting from $$$K = 2$$$, that divides N. Then print $$$\frac{N}{P}$$$.

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

      Can you explain why 2^k -1? I only know a(r^n -1)/r-1 to be the summation of geometric progression.

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

        Let us look at the numbers in binary form-

        $$$2^0 = 1$$$

        $$$2^1 = 10$$$

        $$$2^2 = 100$$$

        $$$2^3 = 1000$$$

        $$$2^4 = 10000$$$

        Now, $$$2^0 + 2^1 + 2^2 + 2^3 = 2^4-1$$$ (i.e. 1111 in binary from)

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

    The trick is to know that x+2x+4x+...+2^kx=x(1+2+4+...+2^k)=x(2^(k+1)-1) because it is a geometric progression. So you could precompute the first 32 numbers 2^n-1, and look if any of them divides n

    You can find out more information about that in here

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

[Deleted]

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

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

How to solve D guys ?

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
  • For D my solution is probably incorrect but approach seems fine
  • We have to do something like find range of sum of both elements such that only 1 element is changed. like for the test case of: 6 6 5 2 6 1 3 4
  • the ranges be like [5:11] for arr[0] and arr[n-1-0] and [3:9] for arr[1] and arr[n-1-1] and so on
  • Then do something like psum[left]+=1 and psum[right]+=-1 for each pair of elements as stated in the problem.
  • Then do the prefix sum across it.
  • Then add the actual sum of these pair of elements as in that case we won't need to change even one element as psum[arr[i]+arr[n-1-i]]+=1
  • Then find max value of x which satisfies most ranges.
  • The answer being n-(the above found max val)
  • But I think there is some repetition in it. Can someone explain the issue with this soln??
  • EDIT: The code is: https://ideone.com/sb6eFB
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    This is very similar to the solution I used to solve D, except that I used a Binary Indexed Tree to quickly process the psum[left] += 1 and psum[right] -= 1 updates.

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

    the range for arr[0] and arr[n-1-0] will be [5:12] , for arr[1] and arr[n-1-1] will be [4:12] and so on if value of k is 6 (seems like from the example)

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

Went for the W by skipping D and trying to solve F since I had an idea...ended up solving none of D, E, F :(

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

in D sample test case 1 :_ part 3 : 8 7 6 1 1 7 6 3 4 6 why is the answer 4 ??

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

Yay. I solved the first 5 with a penalty of 141.

If only I was in competition, and not OOC...

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

There was a mistake in Problem C in the 4th test case explanation during the contest. i.e [1,−1000000000,1,−1000000000](assume all numbers are underlined) due to this I was confused and consumed 5 minutes. but now it's fixed.

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

Do these numbers also include those participants who have rating above 1600?

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

can anyone give a strong test case for problem D?

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

i sent the answer of d in time and it not counted . can u help me in this .

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

What is the solution for F?

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

    It is basically brute force.

    First, decide what can be put at $$$p_1$$$, and brute all of them. From problem constraints, the number must be contained in a segment with length 2, and it must not appear in more than one length 2 segment. (Why?) Then, you can also decide on $$$p_2$$$ since it is just another element in the segment.

    To decide what $$$p_3$$$ is, you can pick a not-yet-used segment. There is only one valid segment, and it satisfies the following:

    1. It contains exactly 1 unused element.

    2. For the already-used elements that also exist in this segment, they must be put in valid range in the answer array. (e.g. if you are deciding on what $$$p_6$$$ is, and the current segment has length 4, the 3 used elements must be in $$$p_3$$$, $$$p_4$$$, $$$p_5$$$, but in any order)

    Then, the one unused element is $$$p_3$$$. If you cannot find a valid element, you can cut this branch. Follow this approach until $$$p_n$$$.

    I coded it in a $$$O(n^4)$$$ way but I believe $$$O(n^3)$$$ way of this exists.

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

    77550191 $$$O(n^4/32)$$$ using bitset

    77584382 $$$O(n^2)$$$ using the fact that only the last and maybe the first element appears once in the input

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

      Can you explain your O(n^2) solution.

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

        Lemma: Only the last and maybe the first element appears once in the input

        You know that one of them is the last element, fix the last element and remove its segment (it's unique), again the lemma is true, keep doing it while the last element is unique, when it is not, one of the elements is the first, then fix the first element, now the last element must always be unique and you can restore the permutation.

        So summarizing, you have two possible last element this take $$$O(2*n^2)$$$ and each one can return two possible first element, so you need $$$O(4*n^2)$$$

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

Why are the ranks of official standings (not unofficial) ambiguous? some of them,3 questions answered,penalty 100,rank 4501. some others, 3 questions answered,penalty 99, rank 4904. why is it that people with more penalty are ranked better? there are more such ambiguity as well....

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

    Sometimes when you refresh Div3 rounds during the hacking phase it removes unrated contestants, but after the hacking phase it will not be ambiguous

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

excuse me, problem E, is graph connected ?

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

    obviously, when it's stated clearly that there is a path between any two pair of nodes.

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

    Yes, this fact is mentioned in the question at least twice. The second line of the question says — It is guaranteed that there is a path between each pair of vertices (districts). The second last line of the input section says — It is guaranteed that the given graph is connected.

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

Hello! I have two submissions for problem E. The only difference between them is how I read the prices. 77571570 gives me wrong answer on test 22. 77571013 is accepted.  Can you tell me please why the 1st submission encountered a problem despite that the prefix array if declared as long long.

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

How do I give input for hacking in problem A.

I tried giving like

4

1000

10

134

234

but says invalid input. Can someone explain why?

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

Actually D is not as hard as it seems. I solved it greedy. For each pair a[i] and a[n — 1 — i] we need to count three numbrers: 1) sum of a[i] and a[n — 1 — i] without changing a[i] or a[n — 1 — i] 2) min sum of a[i] and a[n — 1 — i] if we changed a[i] or a[n — 1 — i] 3) max sum of a[i] and a[n — 1 — i] if we changed a[i] or a[n — 1 — i]. First is just a[i] + a[n — 1 — i], second is min(a[i], a[n — 1 — i]) + 1 (we take the min value and make other 1, thus we get the min sum), third is max(a[i], a[n — 1 — i]) + k. Now we need to differ each of them from others. We can do it by matching a number to each value: 0 for first, -1 for second and 1 for third. Then we put this three values in the array and sort it. Not we need to iterate over array and count the answer. Time complexy O(nlogn) because of sorting the array.Sorry for my poor English.

Code.

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

    i calculate three value as you, but i don't sort them, i use prefix for two last value ! 77542245

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

      Oh, nice idea, thanks.So we can reduce time complexy to O(n + k) with your idea. But it works in 300+ seconds, can you please add this to your code to see how fast it will be.

      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      
  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    Same idea. Just make it easier to understand. Code

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

    I calculated the three values but hadn’t sorted it, so I failed on this test case(I made it): 1 8 7 4 7 7 7 6 6 6 5 The correct answer is 2 but my answer is 3. Do anyone know why? Do I have to sort it?

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

Any DP approach for problem D?

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

very good contest ,I love it but i think it is a bit difficult as a Div.3

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

77574862 This is giving wrong answer for fourth test case if someone could help. Thanks :).

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

    My solution: BFS from A, B, C. cal d[0][u] is the shortest length from u to A, 1 for B and 2 for C

    Any move way must have some u which the path is A -> U -> B -> U -> C and then the length is AU+2BU+CU.

    So we use exactly AU+BU+CU p[] of m p[]. and because the weight from U to B is calculated twice, we'll use BU first p[] for them.

    So we can solve problem by for U from 1 to n, each U we call the weigth if we move A -> U -> B -> U -> C and get min.

    Only calculate if AU+BU+CU<=m

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

Misread "district" as "distinct" in qE :/

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

https://codeforces.com/contest/1343/submission/77576736

wrong answer 39th numbers differ - expected: '1', found: '2'

Is it any chance to see 39th test case?

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

    Sorry ; I couldn't do this in your code itself ; as I am bad at using Python.

    BUT LUCKILY YES ( Click on view to see test cases ) ; and you may also see ; the solve function ; to how I did it ( in case you get into this sort of trouble in future ! )

    I hope this helps !

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

can anyone explain the approach for problem E??

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

    Note that a possible shortest path follows the form of A -> k -> B -> k -> C, where k is any vertex in the graph. Define A[k] as the shortest distance from node A to node k (similar definitions for B[k] and C[k]). Note that we can further break this down into two parts: there should be a total of A[k]+B[k]+C[k] distinct edges visited, with B[k] of those edges being visited twice. We want to take the smallest edges to be repeated, so we sort our prices array and generate prefix sums for fast queries. Now, you can do BFS to calculate the minimum distances for A,B,C and iterate over k. It'll look something like min(psums[B[k]]+psums[A[k]+B[k]+C[k]]) for all k such that A[k]+B[k]+C[k] <= M.

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

      How would you guarantee that paths A[k], B[k],C[k] do not intersect to claim that there are A[k]+B[k]+C[k] distinct edges?

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

        There is no problem if they intersect, it still works. Vertex k can be same as B or C.

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

    I need to go from vertex A to B and then B to C minimizing the cost of travel. I have the flexibility to assign a weight to an edge from given weights.

    Obs 1: If I have to travel Q edges, I will always want to make them the Q smallest edges.

    Obs2: Let's say path from A to B has P edges and path from B to C has Q edges. The max edges I need to traverse is P+Q, but if somehow, I can find overlap between P edges and Q edges, that would be best since, this means, I am reusing smaller edges leading to a lesser sum. This tells us we need to go from A -> V -> B -> V -> C. so that V to B and B to V is reused.

    Let's say A — V is P edges, V to B is Q edges and V to C is R edges. I will assign V to B smallest Q edges. Then assign next P edges to A to V path and then rest R edges to V to C path.

    So iterate for all X from 1 to N and your ans is min of all.

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

Any Suggestion , what can be wrong in my logic for question D .

Mycode D

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

    This will TLE since you're doing T*200000. Note that T*N is passing the TL and not T*20000.

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

    You spend too much time in the memset! In editorial complexity is O(T*n*logn) ,it still passes,Because the totN<=200000 But you memset 200000 in every Case, So it TLE So you can fill the array to zero in every N just like this for(int i=1;i<=N;i++) Ins[i]=In[i]=0 But not memset(Ins,0,sizeof(Ins))

    Hope it can help you.Good luck!

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

Sir vovuh Can you please explain why I am getting WA on test 2 I think my submission does not have use of unitialised variable but I am getting Wrong Answer and the judge says it uses uninitialised variable Please explain where I am wrong in problem D . Sorry for my poor english and thanks in advance. I hope you will reply This is the submission link
77560252

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

How to solve problem F ????

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

Can anyone explain the solution of D?

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

    Call L=a[i] R=a[n-i+1] (because of my lazy xD)

    So if x=L+R, we use 0 replace, in range[min(L,R)+1,max(L,R)+k] we use 1 and 2 for other

    Call E[i] is the number pair have sum exacly i

    Call Up[i] is the number pair have max(L,R)+k=i (it means if x is more than i, we must use two replace)

    Call Down[i] is the number pair have min(L,R)+1=i

    we can see, if x in range [i,2*k] must use 2 then x in range [j,2*k] j<i also use 2

    And if x in range [2,i] use 2 so x in [2,j] j>i also use 2

    We call prefix for up and down Up[i]=Up[i]+Up[i-1], Down[i]=Down[i]+Down[i+1];

    In fact, we always use most n/2 replace for x=k+1 so the answer<=n/2

    Which x we have n/2 pair, E[x] pair have exactly value, so there is n/2 — E[x] pair wrong which use at less 1, have Down[x-1] + Up[x+1] pair must use two replace, so we must add Down[x-1] and Up[x+1]

    -> ans=min(n/2, n/2-E[x]+Down[x-1]+Up[x+1]) 2<=x<=2*k

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

      Hey I used exactly the same approach but using upper bound and lower bound 77581160 can you see what Ive done wrong

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

        I think upper and lower on X is wrong

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

          Upper Bound will give me index of that element greater than R and if its index is X i can say there are (N-X) elements greater than R

          For Lower Bound Will give me Index of element Greater than equal to L and So this Index-1 will be the index of Number Smaller than L and so this +1 will be Number of Elements Smaller than L

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

            with a[i]+a[n-i+1] you can't know with 1 replace it can be x or not

            example a[i]+a[n-i+1]=12 (k=9)

            with 6 6 you can change to [7,15]

            with 3 9 you can change to [4,18]

            so with only 12 you can't know how much replace to get 6 or 18

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

              With [6,6] I will be stroing (1,15) and for [3,9] I will be storing [1,18] I am assuming initially Answer to be N Then substracting for Exactly similar elements and then Adding 1 for those who will bcome equal (After Changing both of their elements)

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

              Ok Done I got the error and got Accepted though after the contest

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

Can anyone explain the solution of D without the use of fenwick tree?

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

    /*THIS IS ONLY IMPLEMENTATION PART AS LOGIC IS ALREADY DISCUSSED ABOVE*/

    we can obtain the 3 values for every index i 1) min possible min(a[I],a[n-i-1])+1; ==> left most (l) 2) max possible max(a[I],a[n-i-1])+k; ==> right most (r) 3) there sum a[I]+a[n-i-1] ==> its sum (s)

    now create 2 arrays 1) enter array => it will look after range l-s (including both) 2) exit array => it will look after range s-r (including both)

    now we can iterate over all cases by loop like int ans=n;int curr_savings=0; rep(i,1,2*k+1) { curr_savings+=enter[i]; ans=min(ans,n-curr_savings); curr_savings-=exite[i]; }

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

    For each i from 1 to n/2 consider this: L=min(arr[i],arr[n-i+1]) and R=max(arr[i],arr[n-i+1]) .

    -If we make 0 changes we can get sum equal to arr[i]+arr[n-i+1]

    -If we make 1 change we can make the pair sum equal to all the values from L+1 to R+k (except L+R which needs 0 changes).

    -To get all other values as sum you need to change both arr[i] and arr[n-i+1](2 changes).

    Now using this create a partial sum array.Read from here

    Iterate from i=2 to i=2*k on the array and take the minimum value.

    Link to my code: https://codeforces.com/contest/1343/submission/77568588

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

where is editorial

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

One more case of cheating by using forged hacks. See: hack details

MikeMirzayanov vovuh Please check. A particular value of n is hardcoded to print wrong answer intentionally. The hacker and hacked user have similar user name as well.

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

77581160 Can someone tell me what Ive done wrong in Problem D getting WA on tc 461 of test 2

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

The server was amazingly smooth today!

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

Hi Codeforcers,

Can anybody give me a hint to solve div 3 candies A problem? I know that it forms a GP of sum of n series but couldn't get my way around to solve the problem?

Help if anybody can. Thanks in advance.

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

    For some valid x and k, n = x*((2^k)-1).

    Hence, check for all k's such that 2<=k<=30, if for some k, n is divisible by (2^k — 1), you got the answer, x = n/(2^k — 1)

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

    n is sum of a geometrical series. Use formula for geometrical series apply the conditions. Hope you will get an idea what to do

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

    Yeah. It is a G.P.

    You need to find (X,K) such that X * (power(2,K-1) — 1) = N

    Start from K = 2 to 50 (why 50 suffices? since N <= 10^9, hence 2^50 will exceed 10^9) and check for value of K, (power(2,K-1) — 1) divides N, whenever it divides, you can print that corresponding X.

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

My Approach for D:

Since array has n elements so there is n/2 pair(a[i],a[n-i+1]) and sum of pair will be x.

Minimum possible sum for a pair is 2 and maximum possible sum for a pair is 2*k. Then x must be between 2 and 2*k

I calculate no of replacement for each x between 2 and 2*K and finally take minimum of all x[i]

Now the challenge is to calculate each x[i] in O(1) complexity

For each x[i] there will be 3 types of pair according to sum of pair

  1. For some pair sum of pair will be exactly x[i], for such pair no replacement is needed.

  2. If x[i] is range (min of pair + 1 , max of pair + k) then this x[i] can be achieved changing one element of the pair.

  3. If value is out of that range then two value of pair will be changed to achieve x[i] as sum of pair.

I calculate range for 1 change for each pair, then i take an array ar and ar[i] indicate how many pair can reach i changing one element.

Finally for each x[i] I check how many pair reach x[i] making 0 change(t), 1 change(y) and 2 change(z)

minimum of all y+2*z is answer.

MY Submission

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

[Deleted]

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

    you have pairs:

    1+6 = 7
    3+1 = 4
    8+7 = 15
    5+6 = 11
    

    let x=11 then:

    5+6 = 11 (replace 1 with 5)
    3+8 = 11 (replace 1 with 8)
    8+3 = 11 (replace 7 with 3)
    5+6 = 11 (stays same)
    

    result is 3 because there are only 3 replaces

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

    5 3 8 5 6 3 8 6

    3 changes and sum of all pairs is 11

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

    Yes 5 3 8 5 6 3 8 6 One of the example with 3 changes.

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

Solution for D

Reference

Problem recap

Given an array with n elements (where n is even), find the least number of operations such that the sum of each number with its mirror element is the same (i.e. a[i] + a[n-1-i] = x for all i)

Observations

  • The key observation here is to realize that there are 3 options for any pair a[i] and a[n-1-i]. These are: make no changes, make 1 change (only one of the element changes) and make 2 changes (both elements change).
  • Consider two mirror elements, a[i] (lets call this x) and a[n-1-i) (lets call this y)
  • If (x > y) then swap them such that x is always smaller or equal to y
  • If you were to make zero changes to either element, their sum would be exactly one number (i.e. x + y)
  • With one change, their sum could range from (x + 1) to (k + y). This is because you could make y=1 (set y to the smallest possible positive number per the problem constraints), or you could make x=k (set x to the largest possible number per the problem constraints)
  • With two changes, you could cover the entire range of possible sums (i.e. 2 through 2*k — since you could make both x and y either equal to 1 or to k, or anything in between)

Implementation

  • We need a way to mark these possible sums and ranges for each mirror pair of numbers. Use prefix sums.
  • Create an array for tracking frequency of zero changes.
  • Create an array that tracks ranges for one change (this will be a prefix array).
  • For each pair, zero changes are needed when sum = x + y. Increment zeros[x + y].
  • For each pair, mark the range that they can go to with exactly one change. This is the range (x + 1) to (y + k) described above. To do this, increment ones[x + 1] by 1, and decrement ones[y + k + 1] by 1.
  • Compute the prefix sum of ones. Essentially, ones[sum] = number of pairs that can add up to sum with just one change.
  • Then iterate through each possible sum (from 1 through 2*k) and see how many changes are needed to get to that sum. Cost = 1 * (ones[sum] - zeros[sum]) + 2 * (n/2 - ones[sum]). You need to subtract zeros[sum] from ones[sum] to avoid over-counting (as ones[sum] includes zero[sum]). Similarly, you need to subtract ones[sum] from twos[sum] (there's n/2 pairs in total and to find pairs where both elements need to be changed, remove ones[sum] which excludes the pairs that can get to this sum with either one or zero changes)
  • Find the sum with the lowest cost and that's your answer
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Great explanation, Thank you :D

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

    in the cost formula why it is not 1*(ones[sum]-zeros[sum])+ 2*(n/2-(ones[sum]+zeros[sum]))as ones[sum] holds the value of sum we can get with one change but we also need to exlude the sum we got with zero changes,right? Can you please clarify it?

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

      Say you have just two elements: {1, 5} with k=5. So zeros[6] = 1. And ones[2...10]=1. Notice that we have added one to both zeros[6] and ones[6]. So ones[x] is cumulative and includes zeros[x]. The actual definition of ones[x] = exactly_ones[x] + zeros[x]. Hence if you just want to get the twos[x], it's sufficient to just remove ones[x].

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

    Great solution, thanks for sharing!!

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

    seriously thanks broo...greatest explaination so far

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

Can someone please see and tell why my code(attached below) was shown the wrong answer for the second question when submitted, Highly appreciated

import java.util.Scanner;

public class Prob2 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner s=new Scanner(System.in);
    int t=s.nextInt();
    for(int i=0;i<t;i++){
       int n=s.nextInt();
       ans(n);
    }
}
public static void ans(int n) {
    int odd=n/2;
    int six=6;
    int eight=8;

    int ans[]=new int[n];
    if(odd%2!=0) {
       //System.out.println("NO");

    }else {

       for(int i=0;i<n/2;i++) {
         if(i%2==0) {
          ans[i]=six;
          ans[i+n/2]=six-3;
          six=six+4;

         }else {
          ans[i]=eight;
          ans[i+n/2]=eight+3;
          eight=eight+4;
         }

       }


    }
    if(n%4==0) {
       System.out.println("YES");
       for(int i=0;i<n;i++) {
         System.out.print(ans[i]+" ");

       }
       System.out.println();
    }else {
       System.out.println("NO");
    }


}

}

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

    For n=12 it will generate 6 8 10 12 14 16 3 11 7 15 11 19 where 11 is repeated. all the value must be distinct.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
Is there someway to extract complete test case as I'm getting this in Problem E
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Try printing out the input when current case = 320, add few ifs so that the solution does not fail on cases 1,2 and 3

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

IMO D was difficult for a normal Div #3 contest, wasted a lot of time on D :(

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

Can someone tell whats the issue with my approach to Problem E? Wrong answer on Test Case 4 1. Get the shortest path from a to b then b to c. And store all the edges of the route. 2.sort the edges based on the frequencies in descending order. And then allocate the prices from smallest to largest. The edge repeating the most will have the minimum price and so on.. I am getting wrong answer in test case 4 on 320 line which is not visible and hence don't know what edge case am I missing. Any help would be appreciated

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

    I think shortest path is not optimal always.

    Let a to b has 3 edges

    Shortest path from b to c has 3 edges which is different from a to b

    Total edge 6

    Now consider there is another path from b to c which has 4 edges(not shortest) but two two of them common with a to b

    Then total edge 3+1=4

    So second one will be optimal although shortest path not taken.

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

Here as the virtual Moss for Codeforces, busting cheaters and getting them out of their bills. I hereby present to you the Inter-College Cheat Group(including NITs and HIET). restfulCoder pawangeek ankitkh6842 Yatin_Kwatra saranshgupta1999 sreejit_007 sachinganguly69 bit.ly_cfdiv23boostlive inductor harry_india vknjwnjc rustic_coder

Not to mention their ranks are (18-19-20-21-22) in today's DIV3 If this comment doesn't serve the purpose of un-rating or banning them. I don't what will. here goes the solutions

77562772

77564410

77556321

77565949

77562595

77563089

77564679

77549578

77565649 He thought adding comments will save him

77564027

77558019

77557813

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

Can somebody prove the intuition of problem E? I had the same idea during the contest but i don't have an actual proof why the case when the sum of the distances is greater than m can be excluded.

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

    The sum of the Distances, greater than "m" will always be excluded, because, you don't have a Prefix Sum, for prefix[i], where i>m.

    Since, we are getting only "m" values, we have "m+1" Prefix sums, so, there is no meaning to include the case, where the sum of distances > m.

    I hope, it helps. Thank you!

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

      Yes, i understand this, but why a case when we repeat some edge, and the total number of edges exceeds m is excluded? For example, in the path from node to c, there are some edges identical to the edges from b to node. Isn't this case possible?

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

         We're breaking down the road from A -> N -> B -> N -> C.

        We're also assuming that the number of repeated edges are those from B -> N(Green Edges)

        So Here A -> N = 4

        N -> B = 1

        B -> N = 1

        N -> C = 5

        So total different numbers used = 4(A->N) + 1(N->B) + 5(N->C) = 10

        But the number of different edges are 6, so we should exclude this? Why? Because there's always a path that minimizes the answer and uses less than m edges, And that happens here if we chose A as our N.

        So In our case We're always looking for a node $$$X$$$. Such that There's no repeated edges from A -> N and from N -> C, So only repeated edges happen at B -> N.

        Consider the following 4 cases,

        1-C lies before A, as in the photo, So the best node to choose would be A itself.

        2-C lies between A-B, then the best node to choose would be C

        3-C lies after B, then the best node to choose would be B

        4-C lies on an path that is connected to a node between A-B, then the best node to choose would be that node that connects us to C.

        I guess that explains why it's fine to ignore if the edges > m, Because there's always a path with edges <= m and will produce better answers.

        Forgive the paint skills.

        Edit

        You can also consider if the AN+NB+BC > m, then just keep using the greatest price. It'll produce a correct answer.

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

Damn vovuh this may very well be the best round I ever took part in!!! The problems were extremly cool, especially problem E. Idk but the round just felt very good. Congratulations on doing such a good job!

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

I have made a video which explains the approach used in D along with the code explanation. The link is here.

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

Can anyone give a another solution of F? Here have a O(N^4/32),But it need bitset. I want to get a O(N^3) solution if anyone know. Thanks very much. I think a solution can be check for i from 1 to N and for each ans is a number is can be. At last it got the answer? but I can't prove it! Does anyone have a O(N^3) solution? thanks.

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

My submission does not fail in any of the test cases I made.. Plz check if you could find one https://codeforces.com/contest/1343/submission/77567195

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

I don't understand when the ranking settlement will be completed. It seems that sometimes it will be settled immediately after the hack stage, sometimes it will take longer

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

why my submission is not showing and also final standing not showing I have solved first 4 qus

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

Oh my goodness, D was easy man. We just missed that during contest. Now, I tried to sketch and finally found it was just a basic prefix sum. Thanks, vovuh. This round was great and educative like the previous one.

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

When do the ratings get published?

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

are the servers down or what?? My submission is in queue for like 15 minutes

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

When will the rating changes be calculated?

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

when the rankings will be updated??

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

It was a great contest. I really enjoyed the problems. Though, I have some suggestions for future Div. 3 rounds:

  • Although I understand that multiple test case problems make tests stronger, they become quite bothering when it requires careful initialization of several arrays. Problem D and E are the examples, where we need to initialize multiple arrays until certain points (or dynamically allocate them), and things like memset(arr, 0, sizeof arr); have possibility to get TL. Of course, one can argue that being careful about these things is also a part of the problem, but this distracts participants from the core idea of the problem greatly and makes them waste a lot of time getting TL over and over again, not even realizing what went wrong with their code. Also, we can see that a lot of participants got AC with running time very close to the limit because of the initialization, and I'm sure that many others have failed to fit in time with very similar logic, possibly because of bad luck or just a little less optimization. My argue is that it will be better to either decrease the max number of TC, or decrease the max of $$$n$$$ when the time complexity isn't super important (like what I've done in one of my problems), especially when the contest is for beginners.
  • I see problems like A in many 2A's and 3A's, where the implementation is super easy if you know how to simplify the mathematical expressions. But that 'simplification' is not very easy for beginners, as we can see that more people have solved B than A. I'd like to expect more straightforward problems for 3A instead of requiring mathematical knowledge or observation, because it's not the easiest subject for people who want to participate in a programming contest.
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I second this. Ideally, I think the easiest problem of Div2 or Div3 should not use concept higher (or harder to come up) than multiplication and division, let alone powers or GCD/LCM's.

    They are 8th/6th grade subject in Korean curriculum respectively. Not everyone who codes know that (believe me). As long as we are targeting them, it's encouraged to help them solve at least one problems in a contest, so they can figure out how things go on.

    I think this discussion is more relevant to be in here, but anyway.

    OTOH I'm not trying to blame the setter for anything: This is just my suggestion!

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

    In the past few contests, after system testing, I often saw some programmes gotTime limit exceededorRuntime erroron the last test cases(for example,Time limit exceeded on test 84). Here are some examples:

    In Codeforces Round 635 (Div. 1):

    Hazyknight(who got 15th place) gotRuntime error on test 84.

    Rewinding(who got 17th place) gotTime limit exceeded on test 33.

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

    Global variables are bad habit in programming, so it's totally fine when people fail because of them.

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

Hidden.

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

    What is the point of submitting from two accounts anyways? The score you get is time based. Faster the submission, greater the score.

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

      But he can check if his solution will receive WA or Accepted if he uses two accounts

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

    You are not allowed to use multiple accounts in a contest.

    Read the rules and pay more attention next time.

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

    Logging in parallel of one person with two accounts should result in ban of both accounts. Then submitting the same solution twice, on both accounts within a contest does not happen without intention.

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

very easy D solution in linear time using prefix sums https://codeforces.com/contest/1343/submission/77524012

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

what does "trusted participants" in standings page mean?

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

    "trusted participants" means users who will be rated after contest(if contest is rated), I think.

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

I have registered for this course and solved 3 problems but even after final standing i did not get any rating. Profile still shows UNRATED before my name.

This was my first codeforces contest. Please help me. How i will get rating and where to see my ratings.

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

Waiting for Ratings  Waiting for Ratings

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

[user:blee][submission:blee/77566304][problem:1343D]My solution to the problem seems to, unintentionally coincide with another.This might be because a major part of my code has been copied from a GeeksForGeeks code (on how to find if a particular number lies within given ranges): https://www.geeksforgeeks.org/count-the-number-of-intervals-in-which-a-given-value-lies/ This was published before the competetion.My points for this round are now 0. I request you to please look into it.Please don't penalise me, the code is entirely mine. Thanks

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

I was not careful for the submission.

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

Hello codeforces,

I have a question about your giving rank algorithm. I solved three questions in this contest which is 2nd, 3rd and 4th. And other people who also solved three questions but 1st , 2nd and 3rd. So I solved a question with high difficulty so I should have high ranking but it is not the case. Those people have high ranking. This is not fair. Why is your algorithm to give rank doing that? A person who solve high difficulty question, you should give them priority.

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

    I think it should be like the contests in AtCoder. it has both score and penalty. The scores of different problems are different.