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

Привет, Codeforces!

В 28.05.2020 17:35 (Московское время) состоится Educational Codeforces Round 88 (рейтинговый для Див. 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 and Harbour.Space

Привет, Codeforces!

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

Присоединяйтесь к нам завтра, в четверг, 28 мая, в 12 ч. (BCN) / 17 ч. (BKK), чтобы посмотреть, как Сергей Гордейчик, директор по информационным технологиям Inception Institute of Artificial Intelligence, поделится своим анализом и инсайтами о том, как положительно и отрицательно искусственный интеллект используется во время глобальной пандемии COVID-19, в своем вебинаре “Digital Lockdown: AI against COVID-19”. Настройтесь узнать некоторые практические примеры того, как компании используют ИИ для различных целей во время кризиса, исследуя такие темы как медицинская визуализация для КТ-анализа, диагностики и массового наблюдения.

Принимая участие в этом вебинаре, вы получите сертификат участника, специальный цифровой подарок от Сергея и получите шанс выиграть БЕСПЛАТНЫЙ 3-недельный модуль в Harbour.Space University, в зависимости от наличия мест и условий участия в курсе.

До завтра и удачи вам в раунде!

Забронируйте свое место сейчас!

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

Место Участник Задач решено Штраф
1 244mhq 6 174
2 bmerry 6 219
3 dlalswp25 6 233
4 hepth 6 238
5 Volkov_Ivan 6 251

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

Место Участник Число взломов
1 Hideki_Ryuga_L 37
2 KonaeAkira 19:-1
3 ujjwalsingh30 18:-1
4 veteran_ 14
5 ashwinginoria 13
Было сделано 318 успешных и 469 неудачных взломов.

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

Задача Участник Штраф
A andryusha_na_knopke 0:01
B thech0sen1 0:03
C IAKWF 0:11
D Kerim.K 0:06
E HeHere 0:06
F user202729_ 0:44

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

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

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

First comment! Thank you Codeforces and Harbour.Space University for these rounds in this tough time!

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

    Don't know the reason of such hatred shown by the community here. I just thanked the organizing panel for their efforts, that's it, as a good gesture. No wonder why the community hated it so much. Maybe because I am a specialist and not a red, not really sure about it.

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

      Don't worry about downvotes too much.

      Your positivity will reach the people no matter what.

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

      This is one big problem with cf. On one side, there is Mike who is bringing out new div4 contests for not so high rated participants and on other side are these guys who boast a lot about their ratings.

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

      If everyone showed thanked the organizer in the comments, then we'd just have a thread of 19,000 people saying thank you. No one wants that, if you want to thank them give them an upvote.

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

        Almost everyone is sad about this lock down (including me), and if these contests give hope to people or put a smile on their face or excite them, there's no harm in saying a "thank you" as a good gesture. And I think that it's nearly impossible for such a large number of people to post it in an announcement. It's just a few, which doesn't flood these announcements. In my case, I just got excited seeing the announcement and that there isn't any comment yet, so I thought why not write a good thing for the organizers, there's nothing bad in it. It gives hope (or just puts a smile) to some, if not all.

        I don't want to hurt anyone with my comments, and if I did, I am sorry about it.

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

          Hey, don't worry both of the groups supporting/disagreeing with your comment are right in their point of view. The first group that supported you was for your pleasant thanksgiving and the other group that disagreed on you was because they want that more important messages/helpful messages are to be shown so that it would give way to more important messages in a bunch of good messages. That thanksgiving gesture was very pleasant hope it will spread positivity in this environment.

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

      I guess you've been downvoted for your 'First comment'. That's totally useless.

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

Where's the unusual time ??

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

Where's the unusual time ??

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

Googleforces

Let's goooo!

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

Hope this educational round will be much better than previous one^_^

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

Looking forward to more geometry problems! Especially, ones with subtasks <3

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

Lets hope we get to see problems involving both math and graph theory. It was long back when we had problems involving math as well as graph theory.

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

Thanks for having back to back contests! Giving something to cheer for.

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

Looking for a data structures problem ..

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

I rarely see a Div2C or Div2D a graph theory problem I think in a while i have seen two only one livonia and kingdom and one from ehab and bla bla .... I am looking for good Problems rather than standard ones with unusual time limit and memory limit.

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

I hope to see Tree , Data structure , Math Problem But i don't want to see geometry .... i am very weak of that

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

    everything is fair until it's not one click away on google. specially when it's prob A/B/C/D. because that makes contest unfair for 80% rated participants.

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

      How did you calculate the percentage of the unfairness? Why not 0.4% or 5% or 15% or 146%? Please, provide some proof or stop speculating.

      Anyway, if you deserve your rating you'll gain it in no time. Otherwise, if you need to google A/B/C/D in ER you probably don't have the rating you can be proud of.

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

        Btw how did you generate such numbers .4%,5%,15%,146%. Any formulas for that or random. He is saying correct those who wasted time in solving that suffered. Googlers got Ac instantly. At least it should be not present on google

»
4 года назад, # |
Rev. 2   Проголосовать: нравится -35 Проголосовать: не нравится
  • Educational codeforces round exists *
    No one :
    Literally no one :
    People who get negative delta after the contest :
    Educational codeforces rounds should be unrated.
  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +37 Проголосовать: не нравится

    I enjoy every contest even if I get negative delta. I don't know why people complain a lot with the rating! Everyone should enjoy contest even if you get negative or possitive delta! I think that's the authors purpose and what really matters!

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

      Yes, even if there would be no rating system i would have given same or more number of contests. Its the number of questions i do make me feel good than positive or negative delta .

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

Why score distribution is not given in any educational round announcements?

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

RUSH RUSH!!

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

[deleted]

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

Who else is trying to solve their first div2 c problem

»
4 года назад, # |
Rev. 2   Проголосовать: нравится -47 Проголосовать: не нравится
  • Problem C : This Problem Can be Solved Mathematically using inequalities.
Idea
Solution

Link to my solution : 81821029

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

Woohooo Vovuh is back!

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

Hope there are no geometry problems!

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

sry, I LOVE MATH!

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

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

why has no one yet asked whether the round is rated or not!!

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

I give up Codeforces and leave this site because of problem C. I am 100% sure that my code is correct but I got 7 WA. I give up. Bye.

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

    If you got WA then maybe, just maybe, it is not 100% correct..

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

    You could instead try E which is easier than C

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

    I passed pretests on second attempt. Its a pen and paper problem. Looked like binary search first, but its O(1) solution with some messy algebra, theory of increasing/decreasing functions, case work, simplifying fractions.

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

      Actually, C can be solved using binary search, I used it during the contest.

      You can see my solution for the same -> https://codeforces.com/contest/1359/submission/81760272

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

      Yes.. Very nice observation that it can be solved in O(1) using some mathematics. I just solved it after looking at your comment and turns out, we don't need any fancy mathematics. Just simple algebra works.

      C After that just check at values (x-1), x, and (x+1)

      https://codeforces.com/contest/1359/submission/81874188

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

        thank's , but letters not understand

        please explain more

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

        can you tell why it's only (n*H + (n-1)*C) and not (n*C + (n-1)*H)

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

    I figured out that expected precision = 1e-15, I got it accepted when i incurred that change

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

    I tried to read your code and saw this: 81775456. No pity you leave, since you would be banned for intentional code disguise anyway.

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

    what with your weird way of writing code. it's like cancer, you write code using define.

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

    I've never laughed so much looking at code (except maybe ArnoldC). Now I have.

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

1937 : There will be flying cars in 2020

Meanwhile in 2020 : brainless pupils and Newbies exist.

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

Speedforces!

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

Last time I was lucky to notice the pattern in C task which resulted in formula answer, this time C revenged! :D

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

A great contest with beautiful problems and short statements for which Educational rounds are generally known.

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

Can C be solved with the help of binary search ? If yes, how ??

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

    For even number of cups, the resulting temperature is always the same.

    For odd number of cups, the resulting temperature decreases as we add new cups, but never becomes less than or equal to $$$\frac{h + c}{2}$$$. So if $$$t > \frac{h + c}{2}$$$, we can use binary search to find the first moment it becomes less than $$$t$$$, and check this moment and the moment $$$2$$$ cups before.

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

      Okay so i was doing everything right but failed to realize that i need to use binary search only for t>(h+c)/2. Changed that and accepted. Thanks !

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

      I suppose I have a constant time solution.

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

      Please correct me if I'm wrong, but consider $$$h=10$$$ and $$$c=1000000$$$

      Wouldn't the average temperature for odd cups be strictly increasing in this case?

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

      Considering the case 999977 17 499998, where hot temperature is 999977 and cold temperature is 17, target being 499998. Using 499979 pours, and, while using 499981 pours, we get the same difference with the target.

      So shouldn't the answer be 499979. While in the solution, the answer is 499981. Can anyone let me know what I am missing here?

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

    If we consider the case where we have $$$X + 1$$$ hot and $$$X$$$ cold, the temperature is a decreasing function, so binary search could work here. However you can also directly calculate the value of $$$X$$$ for which the intersection occurs and then check $$$\lfloor X \rfloor$$$ and $$$\lceil X \rceil $$$ for whichever gives a closer temperature.

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

      Yes I did the same way by directly calculating the intersection value.

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

      Can $$$ \lfloor X \rfloor $$$ and $$$ \lceil X \rceil $$$ and then temperatures at these points be calculated with good precision ?

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

        You do not need to calculate them as double, you can calculate as integers directly: either [t / (h + c + 1 — 2 * t)] or 1 + [t / (h + c + 1 — 2 * t)] where / is integer division. even if X is an integer, it would not hurt to calculate temperature difference at X + 1

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

        I used double division followed by floor and passed fine. However you can calculate it exactly using integer division.

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

      I did the same but still got WA in the third case can somebody tell why? My submission for C- 81790933

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

        same problem subcase 66 (getting 2 instead of 1).

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

        You have most probably missed out on cases where the the difference between h and t is the smallest possible difference and therefore 1 should be the output.
        Tc:
        1
        7 1 6
        Your code fails for this and other similar test cases the answer should be 1 and not 3.

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

        here expected 1 found 3.

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

          Seems I forgot to exclude equal case here 1 and 3 both have difference 1 but minimum was to be considered. Thanks

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

    Yes. Notice that the more cups you take (assuming it's an odd number), the closer you will be to the average of hot and cold temperatures. Use this fact to binary-search for the smallest number of cups such that the temperature is not more than the target. To deal with any precision issues, check 2-3 numbers above and below what you found and select the best one.

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

    Yes. I solved it with Binary Search.

    However, my first few submissions for C got WA because of Double precision issues! If this hadn't happened, I would have reached master. :(

    Check out my submission here: 81789311

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

What is the testcase #4 of problem C ?

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

How to solve D?

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

    for each element in array .. assume the current element as maximum for segment under consideration.

    then find max_left_sum[i] and max_right_sum[i] (crucial part).

    ans will be max(all(max_left_sum[i] + max_right_sum[i]))

    can be done in O(N). once try for yourself, anything more i explained will be a spoiler.

    Spoiler

    this is another question which can be solved using similar technique — Largest Rectangle from Hackerrank

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

      I overkilled D using 3 Segment Trees, that ultimately did exactly what you said...

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

      Are you using Kandanes algorithm both side ? Can you please tell your solution since what you left is the hardest part . Your can put it as a spoiler .

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

        I have updated the comment with spoiler section(with explanation and code) and a bonus similar problem.

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

      Is the complexicity of for loop is n*m where m is no of different value that array element can take m=60 in this case..

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

        Note that there is no need to check the negative values, since if the biggest value of the subarray is negative, it is better to use a single element subarray which results in sum of 0.

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

      Yupp, that largest rectangle problem uses stack to get the next and previous greatest elements. I find stacks tricky hence used segment tree + binary search to find the next, prev greatest element

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

      for a decreasing array, the complexity is O(n^2) in the first loop itself. This code will get TLE. right?? Or, please explain why the complexity should be O(n).

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

        there is the condition for input -30<=ai<=30.

        this is useful to maintain O(N) if the diversity increases this algorithm reached O(N^2) as you said.

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

    Can we use stacks to solve this problem??

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

    You can also use DP with dp[i][j] := "maximum sum of subarray a[?:i] with max value j" which has pretty trivial transitions, and then maximize dp[i][j]-j, looks like this: 81795283

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

How to solve F?

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

    My idea:

    Forget about starting at any time for a moment. Let all cars start moving at $$$t = 0$$$. For any $$$t$$$, Consider the line segments of each car whose endpoints are starting position of that car and position of that car at time $$$t$$$. Find the least $$$t$$$ for which there is an intersection of any two line segments. Then the answer is $$$t$$$, because if line segments corresponding to cars $$$A$$$ and $$$B$$$ intersect, then I can start one of them late and make them crash exactly at $$$t$$$. So binary search on $$$t$$$ and use line sweep to check if there is any intersection.

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

I solved C using ternary search . can some one please proof how the shape will be similar to parabola (I just assumed) .

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

    You can use just Binary Search in the odd number of movements.

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

      Can you plz tell me how? . I am able to find out that we need to search only in odd position but didnt find the how to solve it as brute gives tle and you said binary search . But I didnt get it how??

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится
        1. take one cup of the hot water and pour it into an infinitely deep barrel;
        2. take one cup of the cold water and pour it into an infinitely deep barrel;
        3. take one cup of the hot water and pour it into an infinitely deep barrel;
        4. take one cup of the cold water and pour it into an infinitely deep barrel;
        5. and so on...

        Here for every cup of cold water you have already poured a cup of hot water already. So whenever the even number of cups poured, the temperature will be constant which is the avg(h, c).

        After you pour the 1st cup of hot water. The temperature will be h. After you pour the 2nd cup of hot water. The temperature will be slightly low since you have poured one cup of cold water before.

        Therefore, the temperature will be decreasing monotonically towards the avg(h, c) when ever you pour a cup of hot water. So you can use this property to binary search the appropriate value.

        Link to my submission : 81771518 . Hope you find this useful

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

    No the shape would not be parabolic.

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

    Assume you put x hot cups and x — 1 cold cups. Then middle temperature is (xh + (x-1)c) / (2x-1) If you put x + 1 hot cups and x cold cups then middle temperature is ((x+1)h + xc) / (2x + 1).

    Subtract second from first and you get (h-c)/(4x^2 — 1) which is always positive. So temperature is strictly descending function from number of hot cups.

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

    I can be proved that $$$ \frac {x} {2 * x - 1} $$$ (x = 1, 2, ...) is decreasiong.

    Proof:

    $$$ 2x^2 + x > 2x^2 + x - 1 $$$

    $$$ x *(2x + 1) > (2x - 1) * (x + 1) $$$

    $$$ \frac{x}{2x-1} > \frac{x + 1}{2(x + 1)-1} $$$

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

    1

    2

    3

    stock svg images

    I just plotted the graph, and you can see it is a decreasing function for odd number of cups.

    and you can see it is constant for even number of cups.

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

The ordering of problems was very bad E was even easy from C

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

    I think it was easy to guess but not easy to prove .

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

      A somewhat loose proof for the solution to E is that if you consider a list of numbers [2,2x,2y,2z,...] such that every term divides the smallest number (for example, 2), no matter how you re-arrange the numbers, eventually, you will have to take it modulo the minimum number in the array, which will cause the result to become 0. Then, it is zero all the way to the end.

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

        How to prove that if there is more than one number not the multiple of $$$k$$$ then the final modulo is different?

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

          Suppose that there is a number $$$a_i$$$ that is not divisible by $$$a_1$$$.

          Let $$$x$$$ be equal to $$$a_i$$$, and let's take two following orders: $$$[a_1, a_2, a_3, \dots, a_k]$$$ and $$$[a_i, a_1, a_2, \dots, a_{i-1}, a_{i+1}, \dots, a_k]$$$. Then in the first case, $$$x \bmod a_1$$$ is non-zero (but less than all $$$a_i$$$, so it is the resulting value), and in the second case, $$$x \bmod a_i = 0$$$.

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

          If the property isn't true, then there is some number (call it m), which isn't a multiple of k.

          Now, feed in X=k to the machine. If the permutation of A is [k,m,kx,ky,kz,...] then our answer is clearly 0.

          However, if our permutation of A is [m,k,kx,ky,kz,...] then clearly since m is not divisible by k (by definition), then the value will be (k%m), and the value after the second step will also be non-zero. The value of the result won't change after the second step, because kx,ky,kz > k. Therefore, the final result in this state is non-zero.

          So our array that included m was therefore unstable.

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

        We can prove using mathematical induction. As BledDest showed that only those sequences may work which contain multiples of smallest number .

        Notation : $$$x$$$ mod $$$(a_1,a_2,a_3)$$$ = $$$((x$$$ mod $$$a_1)$$$ mod $$$a_2)$$$ mod $$$a_3$$$

        Base case : $$$size=2$$$ , consider $$$[a_i,v.a_i]$$$ where $$$v>1$$$ . Take any number $$$x$$$. Then $$$x = p.(v.a_i) + r$$$ , where $$$r<v.a_i$$$. Then $$$(x$$$ mod $$$v.a_i)$$$ mod $$$a_i$$$ = $$$r$$$ mod $$$a_i$$$ ,$$$(x$$$ mod $$$a_i )$$$ mod $$$(v.a_i)$$$ = $$$(r$$$ mod $$$a_i)$$$ mod $$$(v.a_i)$$$ = r mod $$$a_i$$$ .

        Assumption : Suppose above is true for size $$$k$$$ i.e $$$[a_1,a_2 ... a_k]$$$. Note that all all elements are multiple of $$$a_1$$$.

        Let us prove for size $$$k+1$$$ i.e $$$[a_1,a_2 ... a_{k+1}]$$$. consider $$$x$$$ mod $$$(a_i,...a_{k+1} ..a_j)$$$ (type 1) and $$$i$$$ not equal to $$$k+1$$$.It will make no difference since $$$a_{k+1}$$$ is not at first position.consider $$$x$$$ mod $$$(a_{k+1} ....a_j)$$$ (type 2) i.e $$$a_{k+1}$$$ is at first position. Then by assumption it will be same for all permutation where $$$a_{k+1}$$$ is at first position. Now we only need to prove that answer for any particular permutation of type 1 and type 2 are same. Let us choose $$$x$$$ mod $$$(a_{k+1},a_1,a_2,a_3.....a_k)$$$ and $$$x$$$ mod $$$(a_1,a_{k+1},a_2,a_3....a_k)$$$. Since $$$x$$$ mod $$$(a_{k+1},a_1)$$$ = $$$x$$$ mod $$$(a_1,a_{k+1})$$$ (from base case proof) hence both are equal . Thus answer is same for all permutation of length $$$k+1$$$.

        I will be thankful if some one points out mistake in above proof.

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

      suppose the gcd you'll take is g, then x=g*q+r, where r is x%g. now if you take x%(n*g) then x%(n*g)=g*(q%n)+r which is some g*q'+r. after repeated divisions when you finally do %g the answer will be q.

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

    couldn't agree more

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

    The round was very similar to AtCoder Beginner Contest, except for F (which I don't dare to even read lol)

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

Why D gets WA on testcase 7.
my submission : 81782286

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

    use kadane from left and then again right taking sum-max...i was stuck there as well

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

      Why?

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

      Whaaat??? What the hell?? I just did the left and got struck. But, well. Why we need to do again from the right??

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

        pointless...its wrong..my submission is hacked

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

        Because the largest number taken at each step (subtracted from the sum) maybe different when taking from the right.

        Example:

        11
        3 0 1 -2 5 -5 -1 0 3 2 2
        

        When taken only from left, the answer is 3 but when taken from right, the answer is 4 (3 2 2).

        However, even this solution doesn't work for cases like,

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

    Couldn't solve it, but i changed my code for this testcase

    n = 6

    [9, 1, -9, 2, 2, 2]

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

C was really interesting...

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

Solotion of C!!! Please!

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

    I used two ternary-search (one for hot == cold + 1 and one for hot == cold) and compared two final results from each ternary search, but I think there are easier solutions

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

    For all the odd pouring, the temperature at ith pour would be ((i+1)*h/2+(i-1)*c/2) and this has to be equal to t. Now on finding i, the answer would be 2*i-1.

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

    C can be solved in O(1) time.

    This is my submission: 81757911

    If h == t, clearly the answer is 1. If h + c >= 2 * t, the answer is 2 as the most you can lower the average to the target is via the first cold cup.

    Now we consider the case where the average of h and c is less than t.

    We make an observation that now there will be one more hot cup than cold cup, so let the number of cold cups poured in be k. Inclusive of the latest hot cup, the average temperature would now be ((h+c)k + h) / (2k + 1). We would like to find the value of k such that the fraction is closest to t.

    We first solve the equation where ((h+c)k + h) / (2k + 1) == t. We can then obtain h-t = k(2t-h-c) and k = (h-t)/(2t-h-c). We can see that either floor(k) or ceil(k) will give us the closest value to the target, hence we check the difference between ((h+c)k + h) / (2k + 1) and t for floor(k) and ceil(k), thus solving the problem.

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

      Hi, I am unable to understand why when h+c>=2t, answer will be 2. Can you please explain?

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

        When the average is greater than t, the smallest average is obtained by pouring 1 hot and 1 cold cup. The average is the same if there is an equal number of hot and cold cups, and it will increase when there is one more hot cup. Thus, 2 is the minimum number of cups for the average to be closest to t.

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

In problem D, I used Kadane's algorithm and got WA on test 7. Can this algorithm be applied on D?

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

One of the best contests ever. Got to know for the first time(or maybe noticed for the first time) about the modulus property that had to be applied in problem E. Thanks again !!

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

Task C took soul out of me but never showed Accepted

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

Please tell me what is wrong with this solouton for C 81802932 I know I've been silly there but please help me

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

    Even if $$$\frac{h+c}{2}\neq t$$$, $$$2$$$ may still be an answer. Since $$$\frac{h+c}{2}$$$ may be closer to $$$t$$$ than the answer you use binary search to get.

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

Can D be solved with the DP?

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

    Yes, I solved with DP.

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

    Idk about dp, but i'd like to say it can be solved in nlogn independent of ai's values. Sort a list of indices based where indices with higher ai values come first, and hold a segment tree of the prefix sum values. Now just iterate through your list of indices and add them as boundaries for querying in a set as you go, and for each index find the largest prefix sum greater than and index and the least prefix sum less than an index such that the range is within all the boundaries in your set, then update ret with subtracting those prefix sums minus the current indices value.

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

      It can be solved in O(n) as well independent of ai's value. You can maintain a stack to do so, https://codeforces.com/contest/1359/submission/81806616 .

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

        Wow, very cool!

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

        can you please explain your solution ?

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

          Basically for each index 'i' of array (1-based indexing), I found out what is the rightmost j for which a[j] > a[i] and j < i. Now Assuming this element has to be removed, I maintained a mxl array to maintain max. subarray sum that is ending at [i — 1] for a given 'i'. Note this includes a[i — 1], (no matter if its positive/negative). Now as per the implementation using stack, for left ('L') part, for a given 'i', s.top has 'i — 1' index, so I keep on removing indices from stack for which a[s.top()] <= a[i], but also kept on maintaining the max sum ending at 'i — 1', which includes a[i — 1]. If you observe mxl[s.top()] does not necessary means max sum goes up to indices 2nd topmost element of stack. So to find the mxl[i], you have to make the continuous sum starting from 'i — 1' to the current s.top(), and update the mlx[i] if valid.

          Similar goes for right part.

          And then for each element just assume you are removing it from its range, find what is the max left and right sum within the range.

          Also if you are still having difficulty in understanding this, I would suggest first try solving easy part of this question — Imbalanced Array. The editorial of it have a similar idea.

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

      I solved it in O(n) . I first used Kadane algorithm and then i consider all subsegment which do not contain negative number .submission Edit : now hacked .

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

    Yeah, dp[i][j] = max value you can get with a segment ending at i, with maximum equal to j. The transitions are pretty straightforward (just need to offset negative values).

    Submission: here

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

      Can you explain the transitions? I don't quite get it

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

        Initially, you can start a new segment at some index, but it will be the maximum, so dp[i][a[i]] = 0 to start. But also, you could have extended some segment ending at i-1, so there are 2 cases to consider.

        1. j, the old maximum was smaller than a[i]. Then you get dp[i-1][j] + j, because a[i] becomes the new max (you already "paid" for j in dp[i-1][j], so add it back in to compensate).

        2. j is greater than a[i]. The maximum doesn't change, so you get dp[i-1][j] + a[i]

        I hope that helps.

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

    $$$dp[index][maxval]$$$ is the maximum sum ending at $$$index$$$ containing $$$maxval$$$ as the max value. Answer is $$$max (dp[index][maxval]-maxval)$$$

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

isn't C binary search why alot of people wa on 2 testcase

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

DELETED

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

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

In q C, my code gave wrong answer in C++17(64) but got accepted in C++14. Happened with anyone?

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

I feel if E was before C it would have more solves

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

Can someone why my submission to problem D, received runtime error on test 2? It was working fine on my local machine.

Thanks

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

In Problem C, I was worried about using floating point numbers, and then thinking about a solution using only integers ...

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

    I used my own fraction class for the same, and it didn't even have a greater than operator, damn it sucked :(

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

    You could have done it by holding best current value by numerator and denominator, then just comparing fractions.

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

Not brute forcing to find a pattern do be like that sometimes. E would have been significantly easier if it was placed as problem C.

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

hi guys why this solution don't work in pb b THANKS . #include<bits/stdc++.h> using namespace std; typedef long long ll;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {

   int n,m,x,y;
   cin>>n>>m>>x>>y;
   char mat[n][m];
   cin.ignore();
   int ans = 0;
   for(int index=0;index<n;index++)
   {
       int curr = 0;

    for(int j=0;j<m;j++)
   {
       char c;
       cin>>c;

       if(c=='.')
        curr++;
       else{
         ans +=min((y*curr/2+curr%2*x),x*curr);
         curr=0;
       }


   }
   ans +=min((y*curr/2+curr%2*x),x*curr);
   }

   cout<<ans<<endl;
    }

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

    Your solution will place a 1x2 block for this case:

    .*.*
    

    The problem states that you can not break the 1x2 block, so this block can be used only when 2 dots are together, like this:

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

      I don't think that's true. In your example, the innermost "else" triggers on each *, at which point curr has value 1, so x is added to the total and curr is reset to 0.

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

        thanks guys for ur replyes acually , my solution work . i jut forget "(" in y*curr/2 cuz (curr/2)*y!=y*curr/2 . that why i get wrong answer.

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

My AC solution of problem F is wrong. Can anyone hack me? Please (>__<).

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

AC problem F, just after the contest... WHY I DIDN'T REMEMBER TO USE 1e-10 INSTEAD OF 0.0 !!!

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

For D, i took : max of (maximum subarray sum ending at index i — max element in that subarray) for all indices i, why doesn't this work?

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

When you missed the last exercise because you didn't round an almost zero value to zero before comparing it with zero. So sad :(

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

Can C be solved using ternary search?

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

Can someone explain the following case for problem D?

11
3 0 1 -2 5 -5 -1 0 3 2 2

The answer is 4 but I'm getting 3 after trying it out by hand and with my code.

Edit: Figured it out. In case anyone's wondering, the max_num at each step when taken from left maybe different from the max_num when taken from the right.

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

Can anyone tell hack for C? TIA

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

Video Editorial :- Problem C

I will add editorial for problem D using segment trees soon.

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

Hi! So I was going through the hacks and saw something odd...

https://codeforces.com/contest/1359/submission/81798994

So this guy made a smurf, submitted his own code, and intentionally added code which would fail on certain input. And you can even see that the author's name is still the same! There aren't any points for hacks in this contest, but shouldn't there be some action against this user?

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

How to solve D without using dp ?

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

For the problem C, I think there is always a way to achieve the average temperature equal to c. Let's say, x number of hot cups were poured and y number of cold cups were poured if we solve the equation assuming, the average temperature will eventually be equal to c, we have hx + cy = tx + ty from here, you get x:y = (t-c):(h-t) taking x and y in this ratio should give the answer, so final answer should x+y For example, in the second sample test case given, x = 15, y = 11, the average temperature will come to 30. So, the judgment is wrong for this question. Please advise on my understanding and correct me if i am wrong.

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

can someone hack my C? 81742048

I believe it is wrong :)

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

    I made some random tests for your code, and after 3000 tests, all answers were the same as my code. I think your code is correct! (Or we both made the same mistake)

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

    long double is not hackable I think.

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

Here's a proof for $$$E$$$.

Take any index $$$i \neq 1$$$. The condition applied to $$$x = a_1a_2\dots a_k + a_i$$$ in the order $$$a_1,a_2,\dots ,a_k$$$ gives $$$a_i \pmod{a_1}$$$ on each step since this is at most $$$a_1-1$$$ and all modules are greater than that.

Now evaluating in order $$$a_i,a_1,a_2,\dots a_{i-1}, a_{i+1}, \dots a_k$$$ evidently gives $$$0$$$ as $$$a_i | a_1\dots a_k + a_i$$$. Therefore $$$a_i \pmod{a_1}$$$ must be zero, which means $$$a_1|a_i$$$ for all indices $$$i$$$.

Proving that the smallest element dividing all others is enough is not hard. Say $$$r_1 = x \pmod{a_{p_1}}$$$, $$$r_2 = r_1 \pmod{a_{p_2}}, \dots$$$.

Notice that for any $$$r_i$$$ by definition we have $$$r_i = r_{i-1} \pmod{a_{p_i}}$$$ thus $$$a_{p_i}|r_i-r_{i-1}$$$ where we define $$$r_0 = x$$$. Since $$$a_1|a_{p_i}$$$ we must have $$$a_1|r_i-r_{i-1}$$$ for all $$$i$$$. Thus $$$a_1|(r_1-r_0)+(r_2-r_1)+\dots + (r_{k}-r_{k-1}) = r_k-r_0 = r_k-x$$$.

We also know that the result is a non negative integer at most $$$a_1$$$ because once $$$\pmod{a_1}$$$ is applied the result becomes constant as all other modules are bigger. Thus $$$r_k$$$ is always $$$x \pmod{a_1}$$$ no matter what order we do the operations in.

Therefore the problem reduces to finding for each smallest element $$$a$$$, the number of ways in which we can choose $$$a_2 < a_3 < \dots < a_k$$$ integers divisible by it in the range $$$(a,n]$$$.

This is just $$$\displaystyle \sum_{a=1}^{n} \dbinom{\left\lfloor \frac{n-a}{a} \right\rfloor}{k-1}$$$.

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

Today's ques C went like a Game changer for many .

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

what is the approach for D except seg tree! can we solve it using kadane

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

    Apply Kadane 2 times, one from the first element and second from the last.

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

    I don't know if some variation of kadane can work here . But I can provide you a, without seg solution .

    1. for each element i, we first find smallest j<=i, such that maximum in range [j,i] = ith element. and similarly, we find largest k>=i such that maximum in range [i,k] = ith element. (These both can be achieved with binary search, using any RMQ data structure, sparse table is easiest to write)

    2. Now we need to find, left and right index in range [j,i] and [i,k] such that we get maximum sum. Again binary search and range min/max queries over prefix sum .

    Take the maximum among all indices.

    Solution.

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

In Problem C, Test Case# 4 999977 17 499998

Judgement is: wrong answer 14th numbers differ — expected: '499981', found: '499979'

But 499979 gives perfact 499998 result and it is < 499981 so why it is not correct answer?

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

    yes you are right

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

    Same problem here...

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

    awoo Please explain this . I have the same problem.

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

    The result when you pour 499979 cups is not 499998, but 499998.00000200008400352814818222. ‬

    For 499981 the result is 499997.99999799992399711189025183, which is closer to 499998.

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

      But needing the doubles to be so accurate can be problematic. I think the problem for us is the fact we used Java, and perhaps Java calculates the doubles less accurately/differently than c++. This is a problematic property of this problem, even though I think it was somewhat interesting.``

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

        1) Java has BigDecimal library

        2) It is possible to do all calculations and comparisons in integer values

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

      Thanks for the clarification, I guess mentioning some kind of cutoff precision in problem statement would have been helpful. Most people who use java will use double by default and will fail this.

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

    Yeah, and the calculated differences, for me at least, are the same for both numbers: 2.0000734366476536E-6 Maybe it's a problem cuz we use Java? Maybe is c++ more accurate or something.

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

      Some solution in c++ also faced this problem. But it can be solved not using double.

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

    For 499979, the answer is

    $$$|499998.00000200008400352814818222‬ - 499998| = 0.00000200008400352814818222‬$$$

    and for 499981, the answer is

    $$$|499997.99999799992399711189025183‬ - 499998| = 0.00000200007600288810974817‬$$$

    So, 499981 is the answer.

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

      I got 2.0000734366476536E-6 for both... Why do you think that is the case? I calculated it like this (x is the number of cups — 1 and divided by 2):

      private double averageAfterTries(int x, int h, int c) {

      double result = x;
      
      
          result *= (h + c);
      
      
          result += h;
      
      
          result /= (2 * x + 1);
      
      
      
          return result;
      
      
      }
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I struggled with that Test case. When I compared 499979's value and that of 499981 using type double, these values are treated as same because of error. By compareing by fraction like this submit, the result became accepted. https://codeforces.com/contest/1359/submission/81813380

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

    My submitted code outputs correct answer in CF but wrong answer in my machine for this test case. I tried to hack some solutions using this TC but failed :v

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

Is it possible to solve problem d in O(n), not using a segment tree?

https://codeforces.com/contest/1359/submission/81786125

I merged same consecutive sign elements.

Let's say chunk1 = +, chunk2 = -, chunk3 = + ~~

I judged which one is better between (chunk1 + chunk2 + chunk3) or (chunk1) or (chunk3) I couldn't find why this logic is wrong..

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

Is it possible to solve problem D with Kadane Algorithm + Segment Tree to get max query ?? I tried but I'm getting WA.

E: Just tried doing it going once from forward and other backwards but now TLE.

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

who can tell me about the case 999977 17 499998 why 499981 is better than 499979?

499979 => 499998.0000020001 499983 => 499997.9999979999

is that cause by accuracy?

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

I think educational rounds are going more towards math and heavy implementation nowadays!

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

How to solve B If I can rotate the 2 x 1 tile?

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

    At first I didn't see that 1x2 tile can't be rotated, so I did this : Run a dfs along adjacent cells and for each connected component, calculate it's cost using the same approach as before.

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

    You would have to check if there exists a perfect bipartite matching for each connected component.

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

      And how is checking a bipartite will calculate the lowest cost?

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

        If 2x <= y, then it's always cheaper to buy two $$$1 \times 1$$$ tiles anyway.

        Otherwise, we would want to maximize the number of $$$1 \times 2$$$ tiles used. You can color each square white or black in an alternating pattern (like a typical chessboard). Since each domino covers one white and one black square, placing the maximum number of $$$1 \times 2$$$ tiles is equivalent to finding a maximum matching.

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

    So you don't want to me solve B also (C, D, E are enough hard I guess) LOL.

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

Can anyone check my submission of Problem D 81799081 I used kadane's algorithm from left and right. It was AC but now it's hacked.

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

Can anyone please suggest me which compiler is to use?? I am really suffering from this.

81814748 compiler: GNU C++17 (64) — WA

81814723 compiler:GNU C++14 — ACC

I can't get myself out of this.

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

Is there anybody who solved problem C using python? I did a parametric search, but I got WA. I think it's because of the python precision issue...

499979 => 499998.0000020001 499981 => 499997.9999979999

Or should I solve the problem C with a different approach?

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

Here's why I think E was probably easier than even C.

So for E literally the only observation you need to make is that all array elements need to be divisible by atleast 1 number in the array or all elements need to be a multiple of a single number in the array for the array to be stable.

So if n(i) is total possible elements divisible by i then ans = ncr(n(1)-1,k-1) + ncr(n(2)-1,k-1) + and so on. Notice that I'm subtracting 1 because I'm fixing the smallest number in n(i) i.e i and finding the combinations of the rest.

So the code just boils down to:

ll ans=0;
for(int i=1;i<=n;i++){
    ll q=n/i;
    ans=(ans+ncr(q-1,k-1))%p;
}
cout<<ans;
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yes, but how can you be so sure that other arrays will give you different modulo? Apart from checking with bruteforce?

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

      Just imagine 2 numbers a and b where a>b and b is not a multiple of a. Now take a number x=a+1, then x%a and x%b will be different always. Now you can add a couple more numbers along with a and b to make it into a longer array, but the mod(array with a before b) will always be different from mod(array with b before a)

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

    Problem E is easy if you know the tricks, but not easy if you do not.

    Some tricks that we need to know are: - (hardest) Computing nChooseK in mod P space (MOD — 2 trick) - (hard) Recognizing that when you fix the first element of the array, and the appropriate calculation for that is choose(n-1, k-1) - (easy) Using DP to compute factorials quickly

    The problem is definitely suitable for an education round. But, depending on your strengths (whether it's in number theory or implementation), you might think problem E is easy or hard.

    Personally, I found C quite easy — I did a bunch of algebra on paper and then coded it up pretty easily with minimal floating point calculations (despite missing some edge cases)

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

      I think ncr%p is an extremely standard problem. Even if you just know about it, the code can be easily taken from the internet, but yea making the observation may take some time based on one's experience.

      I compared it with C because the implementation of C can be a bit tricky, although the equation can be derived easily. If one uses double they have to be extremely careful.

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

I could upsolve D using 2 segment trees to find min of prefixes and suffixes between given indices. However, I am constantly getting feels of an O(n) solution. Has anybody done this in O(n)? Is it simple enough and could you give a hint?

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

For problem D: We can use the fact that the range of numbers is very small. So, for each number from -30 to +30, we can assume it(let's call it x) as the largest sum and find the maximum sum subarray. For this we can apply modified Kadane's by ignoring the elements > x.

Saw this approach in Ashishgup's code: 81746030

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

I'm unable to hack other people's solutions. I get an "Illegal contest ID" error when I click the hack button. Does anyone know of a work around?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +13 Проголосовать: не нравится
    1. Go to Standings
    2. Click on the solution
    3. Click on #
    4. Click on hack
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    You are unrated in this contest. You are red bro.

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

      Yeah, it turns out the problem was that I was trying to use the uphacking interface instead of the in contest one. I don't know why they are different, but oh well.

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

OMG!! solving C using equation was much simpler :(

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

Why from the past 4 to 5 contests div. 2 and educational rounds are based on mathematical problems, in place of them algorithmic problems should be asked which test the actual capability of contestant.

PS- Mathematical Questions results in large negative delta :)

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

In pF, is it intended to let $$$O(n^2)$$$ pass?

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

    It was not, but unfortunately we cannot cut it off because of 64-bit compilers. They are not present in Polygon, so we could not test quadratic solutions there — and I don't think that it's possible to cut $$$O(n \log^2 n)$$$ from $$$O(n^2)$$$ on 64-bit compiler under reasonable constraints since $$$O(n \log^2 n)$$$ solution gets almost no performance improvement while switching from C++17 to C++17 64-bit, but $$$O(n^2)$$$ solution becomes more than twice faster.

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

      This actually begs a question as to whether we really need the 64-bit compiler.

      As of now, cons outweigh pros: sure, you can use __int128 and avoid some inconveniences thanks to it, but mostly it is used to squeeze sh*t into the time limit (I've used it only for that purpose, to be honest).

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

      Actually, this $$$O(N^2)$$$ solution with execution time 2620 ms was not compiled with the 64-bit compiler (it does not get much faster using the 64-bit compiler).

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

        Now that's odd. Our naive solution is something like 5x slower than that (and it's not even the usage of pragmas that makes this code fast).

        Unfortunately, it seems that it's hard to reasonably cut $$$O(n \log^2 n)$$$ from $$$O(n^2)$$$ in this problem since the maximum TL in Polygon is $$$15000$$$ ms (thus we couldn't increase $$$n$$$ up to $$$10^5$$$).

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

      My contest submission also passes if I submit with a 32-bit compiler. I don't have any proof, but the 64-bit compiler might be faster because it's GCC 9.2 (versus 7.3) rather than because it's 64-bit.

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

      What was the intended solution? The one I've thought of is to binary search the answer, then test for any line segment intersections inside that, for $$$O(n \log n \log(\frac{maxxy}{precision}))$$$.

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

Can somebody tell me how to solve problem C using binary search and if not then why? Thanks in advance.

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

Hi, can anyone explain what I'm getting wrong in my solution? Submission I used binary search, m is the the of cups of hot water. Edit: Figured out the problem, was missing a few conditions that could occur. AC submission

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

Question C sucked life out of me but I could not solve it. Can anyone please tell me my error....81801589. Thanks in Advance....

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

Educational Rounds are meant to fuck java participants! Last time around with that fenwick tree problem and now with Problem C!

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

    That's true. I don't know why they do this.

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

    All the cpp guys are downvoting I guess! Keep doing Im liking it:)

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

      I think that you could solve it in java without any problems link.

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

        But not by using double like the cpp guys could :/ I had no clue why my code was failing and it failed just bcoz of double precision error!

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

          You should not use doubles, there are only 3 cases to check you could just compare fractions one by one.

          You can check that many people in c++ also got WA because of double precision.

          There is not need to blame the contest.

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

            I submitted exact same code in cpp and got accepted, maybe they had wrong logic or something ! And sorry for blaming these guys as they are putting an effort for sure during these hard times!

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

I was specifically careful not to use doubles (or long doubles) in C, to avoid precision issues. After the contest finished, I find out some participants did use doubles and got AC. I tried to find a case where precision breaks their solution, so I figured out some big values that made the following true: $$$\left\lvert t_b-t \right\rvert = \left\lvert t_{b+1}-t \right\rvert$$$. But these imprecise solutions didn't break with that case. I got kind of upset, since I could've saved time submitting with doubles and gotten less penalty. Does anyone know if there's a logic behind float operations leading to imprecisions? Is there some kind of upper bound for which imprecisions just don't happen? How do I know when it's safe to use floats?

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

Today's Education : 'Don't Believe double.

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

My solution for D:

We iterate over each value v in range [0, 30] and we fix this value to be the maximum value in the segment we will take. We iterate through the array from end to beginning and when we encounter an element with a value greater than our current fixed value v, we set our current best segment value starting from the current idx to 0 (we reset it). Otherwise we take this element and we add it to the best segment we can take starting from the element to the right of this element. Whenever our current segment value is smaller than 0 we set it to 0 again (we will clear the segment). Now for each iteration we set the max possible segment value to current segment valuev. This is easy to code and is just O(31 * N) = O(N).

https://codeforces.com/contest/1359/submission/81819736

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

    Nice solution.The only mistake i made in contest that i didnot iterate from -30 to 30 at first.The remaining part is a simple two pointer problem.

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

In Problem C :-> WA code using C++17(64) [in contest time]: https://codeforces.com/contest/1359/submission/81772254

AC code Using C++14 Exact same code [After Contest :( ]: https://codeforces.com/contest/1359/submission/81811049

But, I can't understand why ?

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

In Problem C,

WA in contest time using C++17(64): https://codeforces.com/contest/1359/submission/81772254

AC After contest Using C++14 Exact same code :( : https://codeforces.com/contest/1359/submission/81811049

But i Can't understand Why???

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

Problem C reminded me of JEE calorimetry problems from Heat and Thermodynamics

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

Hello

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

PROBLEM C

For test case

999977 17 499998

Why is minimum number of cups 499981 and not 499979? Calculated temperature for both are equally distant from t.

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

    No, Can you please recheck your calculation. I am getting closer value at 499981

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

      What is the difference in values that you're getting? I'm getting a difference of 2.0000734366476536E-6 with both the values.

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

        Yeah bro, Sorry. It is what you are saying. I don't know why the answer is that. I My code gave 499979 and was giving wrong answer in the contest.

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

        Yes u r right for both of the values we got 2.0000734366476536e-06 this difference and also in question clearly mentioned "If there are multiple answers with the minimum absolute difference, then print the smallest of them." So answer must be 499979

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

          I guess all the solutions of problem C must be re-checked regarding this issue.

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

    No issues in Test cases bro :

    if answer 499981 , difference is 0.00000200007599460150231607258319855

    if answer 499979 , difference is 0.00000200008400952356169000267982483

    U can clearly see that 499981 is more optimal :)

    If u have any other test case let me know :)

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

even div 3 E's were better than this E

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

Pardon me if I am wrong but problem C was unfair to most of the participants who tried to solve it through Integer Arithmetic.

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

    I don't know why the community here behaves like this. The same issue when posted above by a red coder got upvotes and here all are downvoting my comment. It is demoralizing. It makes someone think twice before posting his views. Instead of downvoting if people could have replied to this thread that would have helped me to learn something. After all, we all are here to help each other. I tried to solve this problem using integer arithmetic but because of very high precision, I wasn't able to solve it. The same code in C++ 14 passed all the test cases. So, it frustrates when you spend your whole time in a problem and later you discover something like this. I would love it if someone corrects me in reply to this thread.

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

      Did you mean double arithmetic? I'm not seeing any integer-based solutions in your submissions.

      There are many other problems that also have issues with double precision, and I think it was just by chance that C++ 14 worked in this problem. You just have to deal with what you're given sometimes. I wrote a working (but ugly) Java solution during the contest by implementing a fraction class, but I'm sure using BigDecimal would work here if you wanted to have more precision than double.

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

        Yes, I mean double arithmetic. Yeah, Thanks for providing such a detailed explanation.

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

        How do you expect someone to realise during the contest that they're getting WA due to bad precision even with double and that they need to use BigDouble?

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

          You sort of build up an intuition about when doubles are ok and when they're not. My general rule of thumb is that if you need to get some binary/integer answer from a comparison, you shouldn't use doubles, especially if two values can be within $$$10^{-4}$$$ of each other.

          This problem had binary comparisons with precision of $$$5 * 10^{-7}$$$, which is well below $$$10^{-4}$$$.

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

            What about when I use C++17(64), it gives me WA, while the same code is AC on C++14. I could never guess this in a contest.

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

              I really think it's just coincidence that C++14 works and C++17(64) doesn't (some weird compiler differences). You can't rely on that to always be the case.

              Maybe try long double for higher precision?

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

D was a good problem, great way to apply so many different techniques.

My first one was (the one I came up with in the contest): go through the prefix, maintain on $$$ [1, r] $$$ suffix maximums for that prefix and prefix sums. Also maintain in the segment tree $$$ \mathrm{PrefixSum}[i] + \mathrm{PrefSufMax}[i] $$$. Then the answer assuming that the end of segment is in $$$ r $$$ is $$$ \mathrm{PrefixSum}[r] $$$ minus minimum query in the segment tree. Now how to update the maximums and segment tree: just do it naively. $$$ C \leq 30 $$$ and it will work fast enough: this could be proved rigorously if you consider potential function $$$ \Phi(S) := rC - \sum_{[1,r]} \mathrm{PrefSufMax}[i] $$$. But this is seriously overcomplicated stuff (although it appears to be slightly fun). Submission: 81806418 in $$$ \mathcal{O}(n C \log n) $$$.

This one is much more interesting imho. Run kadanes (that must take at least one element), subtract 30, relax the answer, set $$$ a_i = 30 $$$ to $$$ a_i := -\infty $$$. Now kadanes again, $$$ a_i = 29 \rightarrow a_i := -\infty $$$, subtract 29, relax the answer and so on. Submission: 81825489 in $$$ \mathcal{O}(n C) $$$.

I saw people coming up with completely different techniques, quite interested to see what is going to be in the editorial.

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

    What do you mean by "relax the answer" ? Give it a massage xD ? sorry if its a bad joke but legit confused.

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

      Suppose $$$ ans' $$$ is cost function on a feasible solution and $$$ ans $$$ is the global answer you're going to print. What I meant by relaxing was updating $$$ ans = \max(ans, ans') $$$. I thought it was a technical term, but apparently it's not lol

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

    I don't get why the second aproach works, could you please explain it?

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

solution for C using binary search + struct for comparing fractions 81827499

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

I know E was mathematical but still, inmho contest would have been better if E and D swapped positions. Many people use m2.codeforces during the contest, hence don't see standings sometimes.

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

    And again, E had less submission than D. So, even the normal users wouldn't get the intuition that E was easier than D.

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

Hey guys, I try to solve problem C, but my code keeps failing at TC 3 (on a seemingly corner case). Can you help me spot the bug?

Here is the code: https://codeforces.com/contest/1359/submission/81828965

Thanks!

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

For Div2C, I'm not sure about this Test case #2:

759542 609405 620256

The correct answer is 2, which implies:

64217.5 = abs(t - (h+c)/2)

But if you use just 1, you get:

10851 = min(abs(h-t), abs(c-t))

which is smaller. Shouldn't the correct answer be 1?

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

    Well, I guess if you use just 1 then difference should be abs(h-t) and not min(abs(h-t),abs(c-t) and in this case, abs(h-t) is 139286 which is definitely greater than 64217.5

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

Why do we have time for hacking when pretests are so strong?

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

Problem D had a DP solution as well:

If we assume arr[i] is the maximum element in the answer subarray, then we just need to find the maximum subarray starting from (i — 1) going towards left and not having any element greater than arr[i] and similarly for right.

Define solve_left(index, max_allowed) as a function which gives the maximum sum starting from (i — 1) and going towards left and not having any number greater than max_allowed, now it simply terminates if arr[index] > max_allowed otherwise we can try including it and going one step left.

Similary we can do for right, so answer will be maximum of solve_left(i — 1, arr[i]) + solve_right(i + 1, arr[i]) for all such i. This ofcourse works only because arr[i] can't be very large.

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

...where $$$x$$$ is the number of jokers in the winner's hand, and $$$y$$$ is the maximum number of jokers among all other players. If there are two or more players with maximum number of jokers...

Was anybody else thrown off by perceiving the last sentence as referring to "the maximum number of jokers among all other players"? :(

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

how do you solve D?

please don't tell the complete solution.

just tell me along what lines should I be thinking?(apart from segment trees which i have not studied yet:( )

thanks in advance. :)

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

Could someone please mention what is the hack for problem D. So many solutions are failing

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

Problem C can be solved without binary search. There are 3 possible cases

Case 1: h=t

Case 2: number of hot water cups=n and number of cold water cups=n

Case 3: number of hot water cups=n+1 and number of cold water cups=n

we can solve each case separately and select the appropriate answer.

(in case 3, we need to consider both ceil and floor value for answer)

My Submission: https://codeforces.com/contest/1359/submission/81845040

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

    Can you explain how to get the optimal answer from a formula? Because I still don't understand. Thanks in advance.

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

      Let the number of hot cups be p and cold cups be q

      So our value closest to given_temp(t) would be in the form ((h.p)+(c.q))/(p+q)

      For case 1, the minimum count of cups to be poured is obviously 1

      For case 2 p=q=n, our equation would just be ((h.n)+(c.n))/(2.n) [for this case the minimum count of cups to be poured will always be 2]

      For case 3 p=n+1 and q=n, put the values in the equation and equate it to given_temp(t) and solve for n. Then consider both floor and ceil value of n.

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

        Thanks. I understand now. Now i feel like my binary search solution is a bit stupid.

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

Most simple solution for D is trying out all maximum values: Solution

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

    Can u explain ur solution?

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

      I am checking for each number i from 1 to 30, such that this number i is the maximum allowed candidate in any contiguous sub-sequence by running a loop over N (like we do in Kadane's algorithm). Now if we carefully analyse this and dry run over a test case, then we can observe that all the possible contiguous sub-sequences will be taken into account and we get our maximum answer.. :)

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

Help me please!

https://codeforces.com/contest/1359/submission/81801071

why my code is tle?Truly thanks!

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

    Exactly same here brother...... I am also getting TLE on test case 4.

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

    Trying every result is too slow if the test case is:

    30000

    1000000 1 500001

    [Same test case for 29999 more times]

    Your code has a time complexity of O(result/2-1)

    Which maximum could be: O(30000*(99999/2-1) <-maximum result) = O(1499955000), which is TLE.

    Try binary searching the result.

    TLE on test case 4 (Trying all values of n): 81758945

    Accepted using binary search: 81782856

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

2 hours since hacking phase got over

Why isn't the system test starting?

»
4 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится
  • Problem C : This Problem Can be Solved Mathematically using inequalities.
Idea
Solution

Link to my solution : 81821029

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

    Can you explain step 3 in more detail. Namely, how does the inequality simplify?

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

      you simply have to solve for n :-

      t >= (n*h+(n-1)*c)/(2*n-1) ==> (2*n-1)t >= (nh+nc-c) ==> (2nt-nh-nc) >= (c-t) ==> n(2*t-h-c) >= (t-c) ==> n >= (t-c)/(2*t-h-c)

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

Is it taking longer than usual in rating updation :/ ???

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

Weak pretests for D...solutions which used segtree(without kadane) were very much prone to it!!

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

So many different solutions for D work. even my naive O(nlog^2(n)) solution.

https://codeforces.com/contest/1359/submission/81855994

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

Is someone's luck more broken than my increased rating?

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

CF-Predictor shows -2 in my rating but got +2. Became master with minimum required.

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

    It is exactly deviated by 4 . I don't know why but it happened with me too in last round .

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

Whats going on? Tell me my rank is 3568 in this contest without any wrong submission and my friend also get same rank with wrong submission and he attempted same number of ques

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

C: Could someone please tell why this is failing?

https://codeforces.com/contest/1359/submission/81861059

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

Wait for the editorials is too long!!

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

Can we get a diversity of problems? Problems where we need to use data structures like Trees, Graphs, Union Find, Tries? Now half of the problems are math.

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

when will the editorial be out????

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

My code gives correct answer for Problem C test case 2 in Sublime Text and online compilers but incorrect output by codeforces compiler. Please Help.

Code

Test case-(5th subtask of test case 2)

1

763097 140997 594537

Expected Output- 3

My output in cf-2

My output in other compilers-3

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

can anyone tell me about penalty system? i solved two question without incorrect solution and one of my friend also solved two question with -6 penalty but still got same rank as mine ? how ? and also we both submitted the questions on same time.

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

UPD : Fixed

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

How to solve problem E ?

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

    for first case do some pen and paper work, write down all combination (like : 1,2,3 and 1,2,4 and so on). Than you can see that from all the value of array(a1,a2,...ak) the minimum one should be the divisor of all other value, if any array satisfy this than this is a stable array. So, now you can put (i = 1 to n) every value in the first position of the array and you can choose rest k-1 position from the number of divisors of that i in (n-i). you can do this by ncr, here n is the number of divisor of chosen i in (n-i) and r is k-1.
    Now, why it works. you can observe that when in array a1,a2..ak (the array is sorted) at least 1 value is not divisible by a1 than you can choose that value (for example that value is ak), now if your observe that when the permutation is look like this one : ak, ak-1, ... a1, than the total modulo will be 0 and if you take this permutation : a1,a2,..ak, than total modulo will be different cause ak is not divisble by a1 and that is why (ak%a1) will not be 0 and also will be less than all other value in that array and it will remain same till the end.
    I upsolved this problem, it turned out that E was much easier than C and D. I wish i could try to solve E instead C and D in the contest time. Anyway, i tried to share my approach.

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

    What I could think of was... If you consider a case where there is a number A and you make your array in such a way that the first element is A and then all the other elements are multiples of, you can be sure of following the constraint. If you consider any permutation of this array the answer to the modulus after all the elements will be X%A. You can try out some cases using pen and paper and you will see that is only what happens. So now you want to make an array like this. For this, you can just fix the first element A. Now let us say there are M multiples of A which are <=N. So, now you can choose K-1 from these M multiples doing C(M , K-1) % MOD. Find the summation for all the values of A. And this will be your answer. You can find the number of multiples of each value of A in O(NlogN) and you can compute C(M , K-1) for all of them by pre-computing the factorials and using Fermat's Little Theorem. Overall Time complexity will be O(NLogN)

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

wrong answer ll ans = m/(k-1) + (m%(k-1) >0) ? 1:0 ; right answer ll ans = m/(k-1) ; ans += (m%(k-1) >0) ? 1:0 ; why???

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

When do we get the editorial for the contest?

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

Can somebody please explain the solution for problem F? Long time no editorial:(

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

    Well, there's the intended solution and the brute force solution.

    The intended solution: we'll binary search for the answer. So we need to know whether it's possible for two cars to collide in the first T seconds. For a specific car, the possible points it could be after T seconds form a line segment (from the initial point to the point it would reach after driving for T seconds — it can be anywhere along this segment depending on when it starts). If any two of those segments intersect, it can be arranged for the respective cars to collide, otherwise not. There is a standard (although somewhat complicated) $$$O(n \log n)$$$ line sweep algorithm to decide whether a set of line segments contains any intersections.

    The brute force solution is just to check each pair of cars to find the intersection time. As long as you implement it reasonably efficiently (e.g. make sure you do O(n) rather than O(n²) sqrts) and are careful about rounding errors, it'll pass. You need to consider a few cases: - The cars move in non-parallel directions: solve a system of linear equations, and check that both cars reach the intersection after a positive time. - The cars move in parallel directions, along different lines. - The cars move in parallel directions along the same line, either towards either other, away from each other, or one of each.

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

Problem D :- Dp approach [submission] :D(https://codeforces.com/contest/1359/submission/81882431)

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

Problem D :- Easy Dp approach :D 81882431 check it

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

    This solution is too simple to try to understand what x, fl, mx, -mx, abs(mx) mean ;)

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

Editorial not published yet? by the way, great contest! Cheers

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

    I think authors are busy with today's Kotlin Heroes: Episode 4 as both rounds are prepared by same authors. So editorial is not published yet.

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

Hello,

I would like you to help me with this problem https://codeforces.com/contest/1359/problem/C

The expected answer for : h = 999977, c = 17, and t = 499998 is 499981

Shouldn't it be 499979 instead ?

I've checked using this snippet (python 3):

h = 999977
c = 17
t = 499998

def f(a):
   x = a // 2
   return (x * (h + c) + h)/(2 * x + 1)

print(abs(t - f(499981)) - abs(t - f(499979)))
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    I'm too working on this problem now.

    I'm also getting 499979 as the answer

    in order to debug printed the range of answer close to the target and their absolute difference.

    for the test case

    1 999977 17 499998

    Debug is printed in the format (how many times we pour water, average temperature, difference of average with the target temperature)

    499977 499998.0000060003 0.0000060002785176038740000
    499979 499998.0000020001 0.0000020000734366476536000 499981 499997.9999979999 -0.0000020000734366476536000 499983 499997.9999939998 -0.0000060002203099429610000 499985 499997.9999899997 -0.0000100003089755773540000

    by this precision 499979 and 499981 trials are closest to t=499998 with same differnce as the problem asks for minimum amount of times with which we can pour water that achieves closest distance 499979 should be the answer.

    Still wanted to know whether there are any precision errors here ? Can anyone help we with this case ? or debug the correct precision ?

    EDIT : Got it from other comments regarding the precision difference :(

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

tutorials are still not published :(

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

Alternative solution for problem D using dp https://ideone.com/wPZS3p

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

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