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

Привет, Codeforces!

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

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

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

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

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

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

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

Harbour.Space

Harbour.Space берет верх над SWERC, выиграв золото и серебро впервые в своей истории, и примет участие в Финале ICPC. Поздравляем всех наших участников и тренеров, которые сделали это реальностью!

Это очень важный момент в многолетнем сотрудничестве Harbour.Space и Codeforces: организовано 127 образовательных раундов и большой Harbour.Space Scholarship Contest, прошедший 22 июля прошлого года. Мы выбрали победителей того соревнования (early-morning-dreams, Meijer и amanbol), чтобы сформировать наши нынешние команды.

С момента своего создания одной из целей Harbour.Space было выиграть SWERC и конкурировать на высоком уровне в ICPC в целом. 24 апреля эта цель была достигнута, когда команда RAW POTS из Harbour.Space (читай наоборот!) выиграла золотую медаль и в общем зачете у лучших соперников из Западной Европы.

Harbour.Space

Команда Raw Pots — золотой медалист:

Maksym Oboznyi (MaksymOboznyi), Marco Meijer (Meijer), и Danil Zashikhin(early-morning-dreams)

Команда Kempirqosaq — серебряный медалист:

Temirlan Baibolov (bthero), Dinmukhamed Tursynbay (DimmyT), и Amanbol Kanatuly (amanbol).

Команда Harbour.Backspace — заняли 27е место:

Anier Velasco (aniervs), Fadi Younes, и Ekaterina Podruzhko.

Преподаватели, нынешние студенты, выпускники и все, кто связан с Harbour.Space, хотели бы поздравить победителей и участников SWERC 2021-2022 с прекрасным выступлением и поблагодарить за всю проделанную работу.

Как обычно, мы всегда рады видеть участников Codeforces в качестве наших студентов здесь, в Harbour.Space. Вот почему мы рекомендуем вам подать заявку на участие в нашей программе обучения в партнерстве с Hansgrohe в качестве Kotlin-разработчика до 31 мая 2022 года.

Подать заявку

Команда университета Harbour.Space

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

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

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

Wish i will solve problem ABCDE and go orange this time!!!

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

nvm

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

good luck to every one :)

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

I can't wait to get back the rate I lost in #789!!!ψ(`∇´)ψ

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

rotavirus face reveal?

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

All the best everyone!!! Hoping that everyone will get a positive delta

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

Do your best guys and never give up

GOOD LUCK!

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

Только A B C и все!!! Ты должен постараться и решить все задачи раунда.

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

Wishing everyone luck to overcome the curse of Friday the 13th.

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

Привет всем и удачи в сегодняшнем раунде вы все всё сможете постарайтесь решить как можно больше задач

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

I Hope to solve A B C D and become specialist.

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

I didn't participate contest for a long time, very happy to be back and good luck to everyone!

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

can u provide the score distribution?

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

Wish I will go outside the infinite loop between Newbie and Pupil :)
Who is like me !!

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

How many questions I need to solve to be a specialist if my current rating is 1207 ? Can Somebody tell me ?

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

Congrats to the gold and silver medalists!

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

Is it allowed to browse the internet during the contest?

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

    Yes

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

    Yea, you can even copy the exact code from some public websites and it won't be counted for plagiarism. Copying from private websites or from friends is counted for plagiarism

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

Happy to see Kazakh names on the leaderboard! Good luck everyone!

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

Sorry if this is harsh, but this was a very poorly prepared round. If you need to make three contest announcements on problem C, change the output format of problem F after half the contest, massively misjudge the difficulty of E, and have major wording issues on problem D, then there hasn't been enough proofreading. That's 4/6 problems in a 6 problem contest having serious issues.

Clarity issues with C:

Clearly this wasn't explained well enough in the statement, because we needed (or at least we got) 3 contest announcement to clear it up. It's a bit annoying to have to click through a bunch of dialogs during contest about announcements.

Wording issue with D:

The statement says "what is the maximum possible number of different integer points of the line your dog could have visited". This is equivalent to asking "how many points X exist such that there is some way of replacing 0s with integers -K to K such that your dog would be at point X at some time and eventually return to point 0?". That's not what the problem writers mean though, they should say "You know your dog chooses her path in such a way to visit the most number of spaces. How many spaces did she visit?"

Difficulty estimation issue with E:

E has way more solves than D; I believe rightly so. I won't spoil anything here since the round is ongoing, but I have no idea what the authors were thinking with this relative difficulty estimate. Either unnecessarily complex solution ideas, or perhaps didn't have nearly enough testers, I guess.

Output format flipped with problem F:

For the first half of contest, problem F told you to print 1 if it was not in the set, or 0 if it was in the set.

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

    agreed. I thought E was quite complex until I see the huge number of people who solved it.

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

    I don't agree about C.I felt all the three announcements made are redundant

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

      But if they were completely redundant (I agree that they were), they shouldn't have been announcements (just clar request answers) because they are mildly annoying to click through for people who can read the statements.

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

    I do agree on some of these things, like bad output format in F (that's clearly our fault) and difficulty issues with D and E (they should be in reverse order, we overestimated E and underestimated D). However, I don't agree with what you said about C/D.

    Regarding C, I believe the problem statement was absolutely fine. All of the announcements I have sent during the contest either repeat what was said in the statement, or tell something completely obvious. The only reason why I had to send these three announcements is just to cut down on the number of questions on this problem — we were getting too much of them, and a lot from people who clearly haven't read some part of the problem. I actually wanted to send the fourth announcement describing that the cost is the maximum of two values, not the sum of them (even though it is written in bold in the statement, there were lots of people sending their questions where they calculated the cost as the sum of the two values).

    Now, considering D and its statement. I don't think I can argue about the English grammar (where we can use the phrase "could have" and where we cannot, for example) with someone whose native language is English, but I want to ask you a question. If you think that the statement is equivalent to "how many points X exist such that there is some way of replacing 0s with integers 0 to K such that your dog would be at point X at some time and eventually return to point 0?", then what is the meaning of the words "*maximum possible* number of different integer points"? We clearly don't maximize anything in this understanding of the problem, so it makes no sense.

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

      I think you're right under my incorrect interpretation it'd make more sense to say "total possible" than "maximum possible", but also I think that's relatively normal for people to say incorrectly. I think the real issue with the wording is that you're asking for the number of reachable spaces, not the number of spaces reached by the optimal path.

      Unrelatedly, thank you for the "additional constraints" on input rather than saying "It is guaranteed". :)

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

      I would argue that 'cost of removal' is pretty ambiguous in C.

      I myself understood it as a cost of single move — mainly because plural form 'removals' was used in previous sentence.

      But I think that task descriptions were fine.

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

    oh wow, I had completely misinterpreted D just as you said. I was wondering why the problem was so easy and yet had so few solves.

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

Before ending the contest, it's the first time to close it before thinking about problem C. It's a big gap between B and C.

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

    suppose you trim the string to $$$s[i + 1, ..., j]$$$. write out how to describe the two costs with index $$$i, j$$$ and the prefix sum of number of '1' $$$pre[i], pre[j]$$$, then you can find some relationship.

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

    learn how to use binary search. (*)

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

104 minutes by just staring at screen : ( and trying

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

I don't understand D at all!

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

    Let $$$p_i = a_1 + a_2 + \ldots + a_i$$$. Choose some numbers in $$$[-k, k]$$$ for positions with zeros so that $$$p_n = 0$$$ and you need to maximize $$$max(p_i) - min(p_i) + 1$$$.

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

    me too...

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

What was the main idea behind problem C? Was it dp, binary search or some other algorithm?

I kind of got there with dp-greedy approach, but unfortuntely I couldn't figure out which edge cases I was missing.

Will highly appreciate to see some dp approaches, however will not mind to hear other algorithms. Thanks in advance!

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

    I used dp.

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

      Would you mind to run me through your idea briefly?

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

        Define $$$pre[i]$$$ as the number of $$$1$$$ in $$$s[1,...i]$$$. Suppose you trim the string to $$$s[i+1,...,j]$$$. The number of remained $$$0$$$ is $$$(j - i) - (pre[j] - pre[i])$$$. The number of removed $$$1$$$ is $$$pre[N] - (pre[j] - pre[i])$$$. So, if $$$j <= pre[N]$$$, the maximal will always be $$$pre[N] - (pre[j] - pre[0]) = pre[N] - pre[j]$$$. if $$$j > pre[N]$$$, you may choose the minimal of $$$pre[N] - (pre[j] - pre[j - pre[N]])$$$ and $$$min_{i=1, j - pre[N]}{(j - i) - (pre[j] - pre[i])}$$$. Note that $$$min_{1, j - pre[N]}{(j - i) - (pre[j] - pre[i])}$$$ could be calculated by a prefix maximum of $$$i - pre[i]$$$. Iterate all possible $$$j$$$ and get answer.

        Update: as $$$i - pre[i]$$$ is a non-decreasing sequence, the minimal of $$$min_{1, j - pre[N]}{(j - i) - (pre[j] - pre[i])}$$$ happens at $$$j - tot$$$. So the minimum cost for each $$$j$$$ should be $$$pre[N] - pre[j], if j <= pre[N]$$$, or $$$j - pre[j] - (j - pre[N] - pre[j - pre[N]]) if j > pre[N]$$$.

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

          Yeah, thats pretty nice solution. Thank you!

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

          Not sure my idea was same as that of yours but My idea was there exist an optimal solution in which number of zeroes in resulting sub-string equals total number of ones removed (otherwise, we can increase minimum value without altering the result). Now, zero_count in resulting sub-string = total one_count removed => zero_count in resulting sub-string + one_count in resulting sub-string = total one_count removed + one_count in resulting sub-string => length of resulting sub-string = total one_count of initial string. Now I know length of resulting sub-string (i.e, one_count of whole string) and cost (i.e, zero_count in that sub-string), I can just use prefix sum to minimize the cost in one iteration.

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

            What an elegant solution! I would say it's more easy to understand and implement than any other methods. btw, writing equation using latex maybe more easy to read.

            $$$ N_{0\ in\ result\ substring}\ =\ N_{1\ in\ removed\ string}\ \ => \\ N_{0\ in\ result\ substring}\ +N_{1\ in\ result\ substring}\ =\ N_{1\ in\ removed\ string}\ +N_{1\ in\ result\ substring}\ \ => \\ length\ of\ result\ substring\ =\ N_{1\ total} $$$
        • »
          »
          »
          »
          »
          3 года назад, # ^ |
          Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

          in the case of j<=pre[N], why you didn't consider i like pre[N] — (pre[j] — pre[i]) for all values of i and j?

          you took i = 0 and the maximal became pre[N] — (pre[j] — pre[0])

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

      what was the idea for DP ? I have solved with binary and greedy

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

    I did it using Binary search

    To check if it is possible to achieve this cost
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    A sliding window approach also seems to work. If the cost comes from the undeleted part of the string you delete more characters from the left, otherwise, you choose to delete fewer characters from the right.

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

      Could you explain it a bit more, please?

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

        Sure, I can try at least although I think it sounds way more complicated when I try to explain it than it sounded in my head.

        First of all, I find it easier to think about choosing some substring than choosing how many characters to delete from each side.

        Let's now say we have chosen where the substring should begin and try increasing the length of the substring one character at a time. At first, the cost will come solely from the ones but that number will decrease until the number of zeros will start to matter. Then the cost will start increasing again. This means the optimal cost will be when the amount of zeros and ones is the same.

        Now in the program, we want to find the optimal substring that begins at each character and then chose the optimal cost therefrom. First, we find the optimal substring that begins at the beginning. It is not hard to convince oneself that the optimal substring that begins with the second character will not end earlier that the optimal substring that begins in the beginning. Therefore we don't need to try substrings that begin earlier than the previous substrings.

        To implement this efficiently we can use a classic two-pointer/sliding window strategy. We keep track of where the substring we are currently interested in starts and ends and move the end or the start of the substring by one. All while keeping track of how many zeros and ones there are for the current substring. Each pointer only needs to move the length of the string so the algorithm runs in O(n).

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

    It can be done with binary search + sliding window(btw isn't sliding window a subset of two pointers?)

    Submission

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

    I used ternary search.157084549 Edit: and then got hacked! Can anyone give me proper implementation of ternary search to find minimum

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

    I solved C by greedy.

    Let $$$Z$$$ be the number of $$$0$$$ in the initial string.

    If we want to remove $$$L$$$ characters, and $$$C$$$ of which are $$$0$$$, then the cost is $$$max(Z - C, L - C)$$$.

    If $$$L < Z$$$ , then $$$max(Z - C, L - C) = Z - C$$$, which means we can delete up to $$$Z$$$ characters and the cost won't get higher during the deletion.

    If $$$L = Z$$$ and we want to delete another character $$$x$$$:

    • $$$x = 0$$$

      The cost will become $$$max(Z - (C + 1), (L + 1) - (C + 1)) = max(Z - C - 1, L - C) = L - C$$$. We get the same cost as that of $$$L = Z$$$.

    • $$$x = 1$$$

      The cost will become $$$max(Z - C, L + 1 - C) = L + 1 - C$$$, which is higher than that of $$$L = Z$$$.

    So the solution is to enumerate all possible deletion that delete exactly $$$Z$$$ characters and the minimum cost should be the answer.

    157091140

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

    I used two pointers and bp. If you have an answer X, then the segment that we don't change can't have more than X zeros. Just do two pointers stuff on that. Total time is $$$O(nlogn)$$$ 157048159

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

    I used binary search the answer

    Assume we want to check whether we can get score of $$$X$$$, then I will try to remove $$$i$$$ number of $$$1$$$s from the front and $$$X-i$$$ number of ones from the back ($$$0 \le i \le cnt_1$$$)

    If there is such $$$i$$$ so that the remaining substring consists with at most $$$X$$$ number of $$$0$$$s, then we can obtain score of $$$X$$$ and try lowering the answer (or increasing it if there's none such substring)

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

      can you please tell me how you concluded that it is a monotonic and continuous function? Like if the answer is valid for x then it is also valid for x+1

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

        Hey, at start you can observe that the actual answer is <= number of 1s in the string (as that's the cost if you decide to remove all characters and make the string empty).

        Now, you set the binary search range [low, hi] to [0, number of 1s]. Now you guaranteed that the hi value corresponds to a valid cost that can be generated.

        Now, let's say there is some cost X between [low, hi] that can be generated by removing some prefix and suffix, reducing the original string to string S'.

        To observe why all values between X and hi are also achievable, you can see that removing first letter from S' will change the cost either to X+1, or X-1 (depending on if it was zero, or one).

        If you repeat that operation again and again, S' will eventually turn into empty string with cost hi. All values between X -> hi will be generated on the way, as each single letter removal increases or decreases the cost by one — no value in between can can be skipped.

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

    greedy O(n) — https://mirror.codeforces.com/contest/1680/submission/157062229 We check every deletion of 1's from left side, while trying to add 1's from right side as much as possible.

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

    I used ternary search.
    Idea is "what is the optimal ans if i keep X 1's in my answer".

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

How To solve C?

I tried greedy + binary search , to find the nearest 0 from left side(using binary search) and the nearest 0 from right side ,whichever is remove in that direction and update the answer, update the corr left most point & right most point values, till first < last.

Can someone tell me where I am wrong with this approach? Thank you.

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

Who tested C.. the pretests are very strong lmao.

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

the main observation about C problem is that you need to remove 1's >= 0's

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

    Thats not necessary in my opinion. For example take the string 100110011. Here, for optimum answer(i.e. 2) you remove just one 1 and two 0's (from starting).

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

      it's important for greedy+binary search solution: in your example you can also get acceptable results such as (1001)10011 and (100)11001(1), the answer is the same — 2

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

        Well, I was trying to convey that your observation seems wrong to me through a silly example. Just take the string 100000110011. Here for optimum answer(i.e. 2) we remove one 1 and five 0.

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

          I understand what are you trying to say, but 0's in my statement are the ones which left not removed.

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

    Hello, MrOtter , how this observation is true , can you please explain ? i.e. (no of 1s removed >= no of zeroes left). And why its vice-versa is not true? What's exactly makes the difference ?

    actually, wracking my brain for hours and could not get the observation by seeing others implementation. It will be very helpful if you can explain it clearly.

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

      because to minimize answer you need to remove 0s as most as possible and leave 1s as most as possible. in other words you need to find balance between 1s removed and 0s left to minimize difference between them. how you can do it?
      you can observe that you can remove 0s from left and right for free while there are none of 1s. but when you get to 1s you can consider them as price to get to next 0s. so you need to construct threshold condition where you allow to remove 1s and it can improve answer. that's how can come up with condition "no of 1s removed >= no of zeroes left" because you can always remove 1s while no of 1s removed < no of 0s left (maxOf(1s, 0s) = 0s) and it will not get answer worse so it is worth to try.
      based on this observation you can come up to binary search solution

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

I spent all the last hour working on F,while failing to solve it in time(If only i have ten more minutes).Maybe i need another contest to get orange...

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

Can D be solved in O(n)?

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

Problem F is similar to "Voltage" from JOI Spring Camp 2014: AtCoder oj.uz

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

Before I start the contest and for NO reason I decided to take look at problem C first and I found It Crazy a little bit so I decided to not participate in this contest. I am happy to keep my color and not join this stupid contest.

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

This round is really strange. When I was solving B, I literally don't know why I got WA on first two attempts and AC on the third attempt. This is the first time I have this kind of feeling. It took me much longer than expected to solve B, which really brought down my morale. Normally I should be able to solve at least 4 problems and enter top 1000, but this time I only got 2400+ standing with 3 problems solved. This sucks.

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

Can I use the minimum spanning tree to solve E? Just like this question.

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

How to do E? My idea was to consider every chip as the last remaining chip, then to calculate answer by considering that the chips in the same row will just move towards the selected chip, and chips in the other row would first go towards the cell directly above the selected chip and then in 1 move, move downwards to finally become 1 chip. Am I missing something?

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

    I used 4 status to mark the position of chips in current column. then you can do dp transition.

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

How to solve C?

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

    Here is my approach: Let's say finally we have the remaining string from s[i...j]. Then answer for this string will be res = max(zero-pref[i-1][0]-suf[j+1][0],pref[i-1][1]+suf[j+1][1]), here I used ternary search as for every i, I need to find optimal j such that this function is minimum and we can see if we traverse j from end towards i value of function will first decrease then increase. So that's how for every i, I found optimal j using ternary search.

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

Is there a way to solve problem C using recursive dynamic programming?

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

A < B< c ~ E < D

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

How to solve C using DP ?

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

It hurts bad when your code gets accepted by just changing l = 1 to l = 0.

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

If you are/were getting a WA/RE verdict on problems from this contest, you can get the smallest possible counter example for your submission on cfstress.com. To do that, click on the relevant problem's link below, add your submission ID, and edit the table (or edit compressed parameters) to increase/decrease the constraints.

If you are not able to find a counter example even after changing the parameters, reply to this thread (only till the next 7 days), with links to your submission and ticket(s).

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

Could anybody tell me why 157030318 got AC,but 157022306 got WA?

I'm totally confused.

╥﹏╥

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

    This test case will fail in your code: 1 5 5 LLLLL LLLLL LLLLL LLLLL LLLLR

    It should be YES but it gives NO. I tested it locally on my pc and it work but on codefoces custom invocation it will fail

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

    When things pass locally but fail online (see comment from Omar_Hafez), the reason is almost always that you are accessing out of bounds memory by mistake. In this case you were accessing elements s[6][6] but your array's dimensions only allowed for indices from 0 to 5. The changing behaviour depends on what is currently held in the memory accessed inadvertently by s[6][6]. Offline its value was 'ok' so you passed; online its value was 'not ok' so you failed.

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

      jimm89 But this code never reaches s[6][6] it will always be lower than 6 because the flag he made will stop reaching this point

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

        Picture link

        It does in custom invocation (see picture). This is something to do with you attempting to read into 's[i] + 1' — it is not behaving as you expect it to.

        If you re-index i and j to 0-based, you will pass. Submission with re-indexing — note that I've even reduced to s[5][5] and it's fine.

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

          C style strings need a terminating null character \0 at the end. By not reserving the buffer for it, you're going against the rules, hence I'd guess that is what causes this unexpected behavior.

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

          In the picture you mention the code will never reach s[6][6] because the flag is 0

          if(flag && s[x][y])

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

            That’s true. But the fact that it is 6 6 is still the reason the answer returns NO.

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

Come on, problem E is really so easy that a simple dp can work it out!!! However, I forgot to give my dp a special judge because I combined the dp in three situations into one--Just the simple code "-(maze[1][j]=='*'&&maze[2][j]=='*')". O.M.G. then I've got wa in the contest and luckily got Accepted 5 minutes after the contest was over... Poor I!

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

Hi guys, can any one help me what the second loop is doing, a valid solution for C problem.

void run_case() {
    string S;
    cin >> S;
    int N = int(S.size());
    int zeros = int(count(S.begin(), S.end(), '0'));
    int ones = int(count(S.begin(), S.end(), '1'));
    assert(zeros + ones == N);
    vector<int> prefix(N + 1, 0);
 
    for (int i = 0; i < N; i++)
        prefix[i + 1] = prefix[i] + (S[i] - '0');
 
    int best = min(zeros, ones);
 
    for (int i = 0, j = 0; i < N; i++) {
        while (j < N && j - i - (prefix[j] - prefix[i]) < ones - (prefix[j] - prefix[i]))
            j++;
 
        best = min(best, max(j - i - (prefix[j] - prefix[i]), ones - (prefix[j] - prefix[i])));
    }
 
    cout << best << '\n';
}
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It finds j such that it is optimal to end up with the segment [i, j] for the given i. As you increase j the number of zeros inside the segment doesn't decrease, while the number of ones outside doesn't increase. You can prove that for larger i's, larger j's will be optimal.

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

Although the problem was a bit difficult, just because you missed some observations does not mean that problem was terrible. Every Problem has unique observation and implementation... Today i completely misunderstood D('_')

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

Idea for C: If you select the segment l,r you could find the score on that segment. Now you can search for each i, pretend that is r. Now you answer two questions for the segment ending at ith. 1. What's the best case such that at least as many deleted 1s as 0 on that segment? 2. What's the best case such that at least as many 0s as the 1s deleted?

For both cases, we could find out the number of 1s deleted from the end until ith easily. Now whats the best l for each case? First case favors l being as close to 0th index as much as possible, second case favor l as close to ith as possible. You can binary search this, if you had a prefix sum count for 1s and 0s.

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

How the answer of this testcase is 9 (Problem E):
1
6
* * * . * *
* . * * * *
I don't know why testcase is not being printed properly, maybe asterisk sign is doing something. If the test case is still not clear please go this ideone link : https://ideone.com/eJEMfj

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

Well, does anyone have some ideas for the problem D?

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

    Let the original sum of array values be $$$sum$$$. If $$$\lceil \dfrac{abs(sum)}{k}\rceil$$$ is greater than the count of $$$i$$$ where $$$arr[i]=0$$$, $$$ans=-1$$$.

    Otherwise, the maximum visited points will be the distance moved from the smallest point to the largest point, which is range sum in the final array.

    We can iterate on all the $$$N^2$$$ ranges. At each range let's see the largest and smallest sums $$$sum_1$$$ and $$$sum_2$$$ we can have by considering the count of $$$i$$$ where $$$arr[i]=0$$$ at that range, then update $$$ans$$$ by $$$max(ans, abs(sum_1)+1)$$$ and $$$max(ans, abs(sum_2)+1)$$$ (the $$$+1$$$ is to account for the point at the range start).

    Submission

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

I don't know why but I got different answers for same code 1680C in my compiler and in codeforces. Is this a glitch or what?

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

    It is called undefined behavior (sometimes because you want to access something you can't access like outside the array).

    In your code lines 220 and 244 you have to flip the conditions because what you write first got executed first.

    The second thing is that you don't give the variable n a value. I think you forgot to write "n = s.size();" (I think two times needed).

    you can check my last submission on the problem, I got WA on test 2 after fixing these issues in your code.

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

    It happens some time.

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

I used ternary search in prob C but I didn't know that it doesn't work if the function is not "strictly" increasing + decreasing. But my solution got accepted due to weak pretests.

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

I used ternary search in prob C but I didn't know that it doesn't work if the function is not "strictly" increasing + decreasing. But my solution got accepted due to weak pretests.

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

If the score is more than 2100, why do people with a score of more than 2100 participate in the ranking

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

If the score is more than 2100, why do people with a score of more than 2100 participate in the ranking

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

I was running my code on ideone in default setting and someone copied my code and I was not aware about that.I don't have idea that someone can see my solution on ide during contest, that's why i recieved a msg that your solution is collided with others. I will take care from next time. I have not used any unfair means while giving the contest.I have solved all the problems by myself. Please restore my submissions and give me ratings for the contest. I will stop using ideone from now. I promise it won't happen again.

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

editorial late op

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

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