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

Привет, Codeforces!

В 12.05.2023 17:35 (Московское время) состоится Educational Codeforces Round 148 (Rated for Div. 2).

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

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

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

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

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

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

Harbour.Space

Ваш путь к успеху начинается в Harbour.Space Bangkok

Привет, Codeforces!

Мы рады предложить 10 полных стипендии для изучения Computer Science и Data Science в Harbour.Space в кампусе Бангкока!

Приглашаем подать заявление в наш университет в Бангкоке, Таиланд, где мы предлагаем полную стипендию для квалифицированных участников.

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

Если вы хотите получить высшее образование, получить аккредитацию и расширить свой кругозор, эта возможность для вас! Как члены сообщества Codeforces, мы признаем ваш талант и стремление к решению задач. Вы станете отличным кандидатом для нашей программы.

Требования:

Обучение: 3 часа в день

За год обучения вы завершите 15 модулей (длительность каждого 3 недели). Ежедневная учебная нагрузка составляет 3 часа, плюс домашнее задание, которое нужно выполнить в свободное время.

Требования университета

  • CV
  • Аттестат об окончании старшей школы/диплом бакалавра
  • Знание английского языка
  • Medalist in any Programming competition is a plus!

Не забудьте подать заявку до 30го июня, 2023, чтобы иметь шанс получить стипендию и снизить плату за подачу заявления.

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

Мы с нетерпением ждем вас в нашем университете.

Всего наилучшего, The Harbour.Space Team

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

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

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

Ready to get +DELTA (◠‿◠)

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

awoo's round.

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

As a participant, give me a contribution.

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

As a cyan tester,I recommend you to see all problems.

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

Hope for the _Best_

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

I hope after this round I will stop being a prisoner of the blue

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

Hoping for a nice contest

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

It is my first codeforces contest, please say good luck to me.

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

I'm ready to get educated.

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

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

crazy standing XD,but Why did more people pass E than D

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

SPEEDFORCES ABC

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

bad round :dislike:

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

I really enjoyed this round. The dynamic programming idea behind E is so fun!!!

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

ABCforces

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

Shiit, needed 1 more second to submitttt

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

is E convolution?

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

    After dealing with all the math it ends up being something like the O(N*R) dp for calculating nCr on steroids.

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

      i tried to understand your code, i understood why we are using pref[k][i] = pref[k-1][i-1]+pref[k][i-1], but i have a silly doubt why the solution getting stored at 1 index more than the original index(eg: pref[1][k] at pref[2][k])?

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

        Yeah, I messed up something with the indexing and saw that as an easy fix. During a competition I don't really care about being exact in my indexing/naming.

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

    Apparently it can be solved using that within the time limit (comment by physics0523), but this is (probably) not the intended solution. There exists a much simpler and (imo) more beautiful solution using properties of the binomial coefficients and dp (and the fact that k is small).

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

    Dynamic programming. If you remember the recursive formula for the f(x, y) = f(x — 1, y — 1) + f(x — 1, y), then the solution is quiet obvious Let dp[i][j] be the solution for the problem find $$$b_j$$$ if k = i, then dp[i][j] = dp[i -1][j — 1] + dp[i][j — 1] Then its just simple optimisations.

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

I got thought of the B and C, but I can never pass them... pity! hoping for your next contest!

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

Can someone explain how in problem B 6 2 15 22 12 10 13 11 got an output of 46 max I could calculate was 40

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

I think there should be an explanation to the sample test in task E

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

Solved A-E. But it seems that the number of accepted solutions of F is far less than it should be.

A: Let n be the length of string s, then we only need to check first floor(n/2) chars of s. If they are all the same, we can't get any another palindrome. Otherwise we can choose 2 different chars from them and swap them (and chars on the symmetric positions on the right half) to get another palindrome.

B: Sort the array and calculate the prefix-sum. Assume we use the 1-st operation for t times, we will remove 2t elements from the front and t elements from the back of the array. We can try all possible options of t from 0 to k to get the answer.

C: First we can remove all adjacent elements with equal value, and the contrast value will remain the same. Then we only need to remain local maximum and minimum elements of the array (including the first and the last), since if a < b < c or a > b > c we have |a-b|+|b-c|=|a-c|.

D: If k<=n, we can add values from 1 to k on different elements of the array. But if k>n, some values from 1 to k will be subtracted from the array. To make the numbers subtracted be as small as possible, the increments of each operation will be like this: 1, -2, 3, -4, 5, -6, ..., k-2, k-1, k (there are n or n-1 positive values on the back of this sequence, depending on the parity of k-n), then we need to subtract 1 from any values of the array for ceil((k-n)/2) times, and add inc=(k-2*ceil((k-n)/2)) values (from k-inc+1 to k) to different values of the array. To simulate this process, we need to sort the array, and add k+1-i to a[i] for 1<=i<=inc, and find the minimum of the array (we can do this fastly by pre-calculating prefix-minimum of a[i]-i and suffix-minimum of a[i]), then do the subtract operations on some maximum values of the array.

E: The prefix-sum of a[i]:

a[1], a[1]+a[2], a[1]+a[2]+a[3]...

The prefix-sum of the array above:

a[1], 2*a[1]+a[2], 3*a[1]+2*a[2]+a[3]... (which is b[i] when k=1)

The prefix-sum of the array above:

a[1], 3*a[1]+a[2], 6*a[1]+3*a[2]+a[3]... (which is b[i+1] when k=2)

The prefix-sum of the array above:

a[1], 4*a[1]+a[2], 10*a[1]+4*a[2]+a[3]... (which is b[i+2] when k=3)

By this pattern we can solve the problem in O(n*k) by calculating the prefix-sum for k+1 times.

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

wtf is D

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

I think problem E is interesting, even if I didn't solve D or E. Can anyone explain the idea of problem D? Thanks!

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

    First of all, if k <= n the solution is easy, so everything I will say is for k > n.

    If you perform an even number of operations on an element you are guaranteed to decrease some value from it, since for each number you add you subtract a bigger number right after, so if you are trying to increase a value (and therefore made an odd number of operations) it's really only the last number you add that is the "deciding factor".

    Knowing that, you should try to have the smallest number of your array, let's call it a(0), be added by K and a(1) by K-1, a(2) by K-2, ..., a(n) by K-n.

    If (K-n) is an even number you can do it, because for each of the operations before getting to k-n you can just do an even number of operations on each element you change and you are going to end with all elements being ready for an addition.

    Also, performing an addition and right after a subtraction, is going to result in decreasing the element by one, so you just have to add each (K-i) to each a(i) and then remove (K-n)/2, in total, from the elements of the resulting array, distributing it the best way to get the biggest minimum value.

    If (K-n) is odd you won't be able to increase every element of the array, because to do that you need an odd number of operations on each element, but at least one element will necessarily have an even number of operations on it, so the best you can do is make this element the biggest one, a(n), and not add anything to it (instead of decreasing it) then you can add each value from k-n+1 to k to each element from a(0) to a(n-1) and you are gonna have an even number of operations left. Then again, you will remove (K-n+1)/2 from the resulting array in the best way possible.

    If you want to solve D2 you do the same thing, but with some tricks to make it all faster, I can describe them if you want.

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

Can anyone share their solution for C? My approach was to find increasing/decreasing segements of the array and remove all elements of segment exacept endpoints, either my approach is wrong or i failed to implement it properly. Please someone tell how to solve.

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

Spent last 1 hour 54 minutes doing recursive dp . TLE with memo array and MLE with memo map . Some different idea involved in B ?

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

Class 11 combinatorics revise karlo frandss

(Hint: Use (iv) to create a recurrence for b(n, k))

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

Nice contest! Incase you are stuck on Problem A, Problem B, Problem C. then you can check this video editorial link

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

I think arbitrary $$$MOD(1 \leq MOD \leq 10^9)$$$ would have been a better choice for problem E to cut convolution solution.

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

Given that Edu rounds weighs all problems equally, it doesn't feel right for there to be a 2-part problem in Edu round unless the two parts are extremely different in difficulty. In the context of today's contest problem D is essentially weighed double that of problems E/F, which clearly should not be the case.

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

10 minutes after contest, >20 hacks on D :)

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

If anyone facing difficulty understanding D1, Please check Tourist's solution. It is very elegant and easy to understand.

solution link

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

We can use convolution to solve problem E.

\begin{aligned} b_i &= \sum_{j = 0}^i \binom{i — j + 1}{k} a_j \\ &= \sum_{j = 0}^i \frac{(i — j + 1)!}{k!(i — j + 1 — k)!} a_j \\ \Longrightarrow \sum_{n \geq 0} b_n x^n &= \frac{1}{k!} \sum_{n \geq 0} \sum_{j = 0}^n \frac{(n — j + 1)!}{(n — j + 1 — k)!} x^{n — j} a_j x^j \end{aligned}

We can take $$$f = \sum_{n \geq 0} a_n x^n$$$ and $$$g = \sum_{n \geq 0} \frac{(n + 1)!}{(n + 1 - k)!} x^n$$$ and $$$\frac{1}{k!}(f * g)$$$ is our desired polynomial. Since $$$n$$$ is huge $$$(n \leq 10^7)$$$, we might want to use fast convolution.

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

What's the hack for D?

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

Whoever hacked my submission, I hope you have a bad day.

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

my submission for B

can someone tell me in which tc does this code fail.

Problem B.

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

    Your approach itself is wrong. You can't greedily choose whether to delete two min elements or one max element, because you don't know about values in entire array so it may be possible that you don't get the optimal answer finally, hence you can't take that decision just based on 2 mins and one max. This brings us to the solution of checking all possible ways to do the operations, but here dp won't be needed as some dependencies are there, like: 1.You will delete 1st two mins always before next two mins 2. You will delete first max always before 2nd max 3. You will always delete k elements

    This brings us to a sliding window protocol solution. At first delete last k elements and find the sum. Then at each iteration, delete two mins and add one max back to the sum and compare with max sum.

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

Was it intentional to not keep keep negative answers in test cases of D?

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

https://mirror.codeforces.com/contest/1832/submission/205606471

can someone tell me the problem with my code for c

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

Why doesn't greedy method work for B?

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

I first misunderstood the statement, I thought that the order of operations did not matter( you could do +5 before +3 so basically could do operation j after i and i > j). Is there any way to solve this problem? I thought about it for about an hour but could not come up with anything.

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

The difficulty gap between C and D problems in last 5-6 Div2 Educational rounds is too large imo. It's much more enjoyable to take part in an ordinary Div2 rounds.

Can't say I'll participate in these Educationals anymore.

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

how far is the Purple id ;)

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

Why it is unrated though my rating is still under 2100?

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

Editorial please

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

is system testing is proceded?

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

how cound D1 and D2 hacked this much ????

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

Super strong pretests

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

Very weak pretests for D1 & D2 :( It's not just the negative answers, my submission FST'ed on a tc whose answer is +ve.

PS: I by mistake divided by 2 instead of n at someplace. After changing it, it's AC for D1&2. Frustrating.

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

From almost getting D2 to FSTing on D1, sigh!!

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

rating when

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

I've gotten Wa on 44 in D2 because of the corner case n=1.

It's really a nice problem, but I think it'll be better if the corner cases are included in examples or pretests. It's a part of problem for sure, but isn't it a little cruel for us participants?

Actually, in this round, not only me, but also many other participants are truly educated. As for me, I'll check if there exists a corner case before submitting. From this perspective,it's educational enough as an educational round, I think.

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

    For me, I will check the complexity of my code before the end of the competition.

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

    Well corner cases are different for everyone. When I solved D2 (after the contest ended) n=1 wasn't a problem for me. I don't think it is that cruel having this case, as it is quite logical. What IS cruel is NOT including corner cases in the test cases, for example the possibility of the answers to the queries to be negative numbers, which caused so many hacks in D1 and D2. So in my opinion, it is better to have them no matter how annoying they might be for individuals. It is more educational to come up with what is wrong with your solution during the round rather than after, when you are frustrated because of the hack.

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

I solved E in $$$O(n * k^2)$$$ with polynomials. But I saw that a lot of guys solved it with a much simpler idea in $$$O(n * k)$$$. How to do that?

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

    We use the recursion :-

    $$${n \choose r} = {n - 1\choose r-1} + {n - 1\choose r}$$$

    Given:-

    $$$b_n = {n \choose k }a_1 + \dots + {1 \choose k}a_n $$$

    Let us write:-

    $$$b_n = B(n, k)$$$

    Now, observe that (use the {n \choose r} recursion to get this):-

    $$$B(n, r) = B(n-1, r) + B(n-1, r-1) + {1 \choose r}a_1$$$

    This can be solved using DP in O(nk). However, the final solution required some memory optimizations to get accepted.

    My Solution -> 205614318.

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

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

When will the editorial be released ??

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

How to solve D?

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

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

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

As a person who needs contribution, please give me some.

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

I gained +74 delta! Good round.

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

@MikeMirzayanov I'm confused for rejudge system. in last round,my submission status is ac,but become ce after rejudge. at the same time,i submited using the same code,but it passed again

code in the game https://mirror.codeforces.com/contest/1832/my same code after rejude https://mirror.codeforces.com/contest/1832/submission/205814566

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

Candidate master!

Hello, Div.1! (Though it may send me back to expert.)

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

great round!

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

Ok

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

It took me some time to figure out the dp solution to problem E, and it was fun. I made a video editorial if anyone needs help, you can find it here

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Check these things if you can't pass 1832E and get 'Wrong Answer' on Test #2: 1.The input is compiled in modulo m, but the output isn't!!!!! 2.DO NOT MODULO m WHEN YOU ARE COMPUTING THE PREFIX SUM OF ARRAY a!!!!!OTHERWISE YOU WILL GET 'WRONG ANSWER'!!!!!