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

Привет, Codeforces!

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

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

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

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

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

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

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

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

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

It's rare that an official blog was posted 36 minutes ago and there are no upvotes.

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

I've pretended to be expert. But still I have ambition to be expert and never lose hope. Wishes to positive delta.

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

Last educational round in year, makes me feel nervous ...

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

Good luck everyone!

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

19 educational rounds this year. We hope more in 2022 INSHAALLAH.

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

We are downvoted by Zeke (Snk, Season 3 Part 2)

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

hello community

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

I want to be in this rare moment, down vote me too!

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

1 upvote = $1 for poor kids in africa

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

Segment tree is very indian

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

Expecting a good contest. :3

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

Who let the downvotes out? I promise this is not a rickroll

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

My first round as a red coder

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

Not a single comment (votes > 0).

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

Instead of downvoting, do programming !

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

lol why so many dislikes

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

Downvotes, Downvotes everywhere

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

Enjoyed problem C, very interesting. But It took me 3 tries to accept this porblem, but anyway I love it

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

OHHH! GOD ! I will become Master ??!! It only took two contests to go from expert to Master(maybe)and that's CRAZY!!!

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

What about the idea that every upvote's or downvote's value is function of current rating, contribution and account creation date?

May be it is non-democratic..

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

It's strange how you don't do any significant change in the code and still expect it to get accepted each time.

6 wrong submission on C.

Wrong on pretest 2 forces ;)

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

Can someone give a hint on task D please?

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

    Find number of strings where first position where it differs from original string is ith

    and last such position is jth.

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

      Could you have a look at my code? I think I've done something similar.

      If it's not too much trouble. Thanks

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

Can problem C be solved with binary search on number of moves??

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

Loved the E! chef's kiss

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

how to solve C

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

Why do div1 players in official standings?

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

Thanks for short and clear statements!

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

Can someone pls find the error in my code for C? My solution I used binary search on ans so it should run in Q(nlog(1e17)) but somehow I am always getting WA in test 2 T_T.

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

Can someone help me understanding what I did wrong in solution C? 140802492

I made chances array which indicates chances that will be required by decreasing small element by some amount and changing all elements from i to n — 1 for i in [1, n) and took minimum of them.

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

Just curious , why the constraints were set for a O(n^2) or maybe O(n*k) solution for D? Is there any solution that relies on this small constraints (like maybe a dp)? I could only come up with O(n) solution.

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

KOVAL_ IS A CHEATER!!!!!!!!!

140792053 140792490

please reject his submissions MikeMirzayanov

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

How to solve C using binary search?

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

Can someone give me a counter-example for my approach to C?

1) Sort the array

2) For every index $$$i$$$, we will copy the value of the smallest member i.e $$$arr[1]$$$ from $$$i+1$$$ to $$$n$$$, but before copying we will find the minimum decrements, $$$d_i$$$ in $$$arr[1]$$$ that are needed so the constraint of sum $$$ \le k$$$ is satisfied

To be precise, let $$$m$$$ be the smallest member, then for every index $$$1\le i\le n$$$ we find smallest non-negative $$$d_i$$$ such that-

$$$prefixsum[i]-d_i + (n-i)*(m-d_i) \le k$$$

where $$$prefixsum[i]$$$ is the sum from $$$1$$$ to $$$i$$$ in the original sorted array

Overall, the answer will be minimum of all the $$$d_i + n - i$$$ over all $$$i$$$ because we do $$$d_i$$$ decrements and $$$n-i$$$ copy steps.

Here is my submission. Gives WA on test 2.

EDIT:

I found the error, int x = -1/2 will give x=0 and not x=-1. I had an implementation bug. My code failed for the following case-

5 6

1 4 1 1 1

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

I solved C without binary search (more of like greedy approach)

First of all the main observation is we should always decrease the smallest element and then make some greater elements of array equal to the smallest element.

Now simply brute force over the total number of values which you will make equal to the smallest element (suppose it is x) and the smallest element is decreased to a value y

then,

we know

sum of remaining elements + x*y <=k

calculate sum of remaining elements using 2 pointer or prefix sum (your choice)

and brute force over all values of x from 0 to n-1

and take minimum over all values

for more clarity look at the submission 140822105

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

Here are my solutions for Problems A-D, you can check it out, since edu editorials take time, they come after hacking phase usually.

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

when I pressed sumbit for problem D, notification of contest end appears then I couldn't submit and get contest is over.

I got pretest passed on 18:36 UTC+2 :(

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

I want to know what is wrong with my approach for problem c

submissionYour text to link here...

My approach:-

  1. sort the array

  2. taking subarray from index 1 to $$$i$$$.

  3. finding then how much should $$$ar[0]$$$ be decremented so that after replacing $$$i+1$$$ to $$$n-1$$$ index with the decremented number the sum is $$$ \lt =k$$$

for this I used following equation Let $$$S$$$ denote the sum of number from index 1 to $$$i$$$

then $$$S + (n-i)*x \lt =K$$$ where x is the number to which all the remaining numbers will be changed into.

Found optimum $$$x$$$ from the above inequality and got the number of moves to do the said changes. Took minimum of all.

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

Hey, can anyone look at my submission for C and tell me why my code fails. It fails on some testcase number 2571 so I can't see the testcase, but I can't figure out what's wrong with my approach.

Code

Approach: Sort array a. Take l = LLONG_MIN, h = a[0]. Then binary search on the values that I need to decrease the smallest number to. So my countMoves() function counts the moves if I transform a[0] to mid and then assign the new value to the largest numbers from the end until sum > k. If the number of moves are better than previous best, I increase l to mid + 1, else I decrease h to mid — 1.

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

Unsure why my binary search solution for C isn't working. Could someone please take a look?

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

Can you give me some hints about how to solve problem 1622E - Math Test?

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

    Maximizing the absolute value is kinda hard, so let's use the fact that there are at most $$$10$$$ students. For each student, there are two ways to evaluate the absolute value in their contribution to the answer: either $$$x_i - r_i$$$, or $$$r_i - x_i$$$. You can iterate on $$$2^n$$$ different ways to evaluate the absolute values, and then maximizing the answer without absolute values becomes much easier (use Contribution to the Sum technique).

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

      Thank you! Solved with your hint 140833798

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

      how to prove that this will correspond to a valid answer (for the max answer atleast) because for some permutations to maximize the sum even though you "force" a student to score lower than expected from the bitmask, you might still assign a permutation that makes the student score higher than expected or vice versa

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

        I'm not able to figure out full proof, but maybe proof is based on statement that if we can't get answer for this algorithm, which provide maximum possible answer, then we can't get any other answer. Looks like need to assume that we can get correct answer for permutation with less result, which satisfies constrains for module expansion. Then with several number of swaps of two elements in permutation we can get maximum answer — contradiction.

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

        For some bitmasks it's true that final setup may not correspond to the definition of that bitmask. But it will give some value, which is less than or equal to one of the valid setups for the bitmask, which is equal to current bitmask with its invalid bits flipped. Let's say based on the value of bitmask, we assumed that for some student, X contributes positively and question scores contribute negatively. But we ended up with X <= score(1) + ... + score(M). But since, X — (score(1) + ... + score(M)) <= 0 <= (score(1) + ... + score(M)) — X, if we will flip all such invalid bits, we will end up with some larger or equal value which corresponds to one of the correct solutions of flipped bitmask.

        Now let's say maximum value occurs with some bitmask in a valid way. When we process that bitmask, we generate maximum possible answer, due to X's are fixed and if we distribute scores according to sorted list of correctly answered questions. Our distribution itself may be invalid, but since we know that mathematically this is the largest possible answer according to our formula, and it is less than or equal to some valid answer. This means that we will find our maximum value when we will process the bitmask which results in that maximum value.

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

        Deleted.

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

In problem C: I couldn't get where is the bug, can anyone help with this? http://mirror.codeforces.com/contest/1622/submission/140813410

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

Thanks to everybody who joined the stream! Specifically, thanks to TimmyThinMints for streaming with me, to BledDest and tourist for helping us with F, and everybody else for joining in! I very much enjoyed the problems, especially working with everybody to figure out F.

Update: link to stream: https://www.youtube.com/watch?v=RM96b68TPv8

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

    I used the idea you shared in your stream to solve C, but got stuck on test case 2. This is my submission with some comments : 140832114. Can you help to point out where the error is? Thanks!

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

      Try

      1
      3 8
      9 1 3 
      

      The optimal move is to convert 9 to 1 in one move, making the sum as $$$(1 + 1 + 3 \leq 8)$$$ but your output is 5.

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

        Oh, I think I see what went wrong now. When fixing the number of largest elements to be replaced, call it T, the correct approach is that we first replace the T largest elements with a[0] (the smallest) without modifying a[0]. We should do the replacement first because it is possible that we do not even need to decrease a[0], just like your counter example.

        What I did in my incorrect solution was to decrease a[0] first, then do the replacement.

        Thanks! This counter example really helped:)

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

finally will be expert. thanks for the contest.

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

finally will be expert.thanks for the contest

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

If anyone is looking for video Solutions,Here they are(for A-D)

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

.

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

    Here is my guess of your code:

    • cnt is the number of 'big numbers' you want to set to a small value.
    • cnt+1 means the 'big numbers' and the minimum number in the array. All of the 'cnt+1' numbers will have the same value of the minimum number after the 'set' operation.
    • total is the total sum of the unchanged numbers.
    • (total-k) is the reduction amount needed to satisfy the requirement of the final sum of the array being <= k.
    • (total-k)/(cnt+1) is the reduction amount per element, element which changed.
    • (total-k+cnt)/(cnt+1) is the rounding up of the above division.
    • cnt + (total-k)/(cnt+1) is the total number of operations needed. The first term accounts for the number of 'big numbers' being set to the value of the new minimum. Each 'big number' requires one operation. The second term is the number of operations required for bringing down the minimum element into an even lower minimum if necessary.
»
4 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

140835874 Can someone tell me what im doing wrong for problem C. The above code fails in the 4th test case(It's too large so can't paste it here ,sry ).

My approach is for every prefix of the array(sorted in decreasing order), what is the maximum value, the smallest number can be reduced to and then assign it to all the numbers in the prefix so that the sum becomes less than or equal to k. Of all such values im finding the one with min operations. Thanks :)

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

Binary Search Complete Code Explained . I have explained in best way possible. For anyone looking for solution using binary search.

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

If anyone would like a solution for problem C, here it is :

Solution for **C. Set or Decrease** https://mirror.codeforces.com/contest/1622/problem/C
»
4 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Could anyone give me some advice please?

I could finish A,B,C in 30 minutes, however I could not work out problem D.

Maybe I can not solve such math problems,

could you please share some blogs or documents for me?

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

hey! why my O(n*log^2(n)) solution for B is getting TLE? link:- https://mirror.codeforces.com/contest/1622/submission/140858246

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

Can someone explain how can correct output of any testcase be 0 for problem D, I have seen some testcases in hacks and couldn't figure out why the correct output is 0.

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

Can anyone explain how D can be done in O(n^2), they are checking for cnt[1] <= k and also what is the relation with the boundary elements to be 1 or 0?

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

    For any substring to be shuffled, if the boundary element of this substring(right most) is not changed, no matter how much we shuffle all other elements, all the resulting substrings have been already counted during shuffling of substring which occured before(if current substring is not the first one to be shuffled). Therefore for generation of new strings boundary element must be changed. But this is O(N) solution using two pointers. I still don't get how to solve this in O(N^2).

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

In problem D changed (x — y) % MOD, to (x — y + MOD * MOD) % MOD, and got AC. What a stupid mistake

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

I can't solve problem F by thinking for a long time. I hope fast editorial.

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

I joined a few days back and participated in yesterday's round 120 and solved one question with successful submission but my rating has not increased. Could someone please tell the reason as I am joined just a few days back.

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

It's confusing that $$$n$$$ in problem D is only $$$5000$$$, for there is an obvious $$$O(n)$$$ solution using simple inclusion and exclusion.

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

    Maybe the purpose of that is to confuse contestants.

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

    It was an educational round for the participants rated lower than 2100. Their opinion about what is "obvious" and "simple" may naturally differ from yours. I would check the official editorial to see what was supposed to be the intended solution.

    Moreover, with a 12 hours hacking stage, there's always a risk that somebody may come up with a very evil hack, exploiting cache misses or branch mispredictions to significantly reduce performance. So setting excessively tight time limits and/or constraints for any problem is dangerous in this contest format.

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

    O(n)? What about n choose r? It is at least O(n log n) right? Am I missing something?

    PS: just saw your code, you just used one fast exponentiation for the precalculations, forgot about this idea, it is actually O(n)

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

When will the editorial be available? Also, how can the answer be 0 in problem D? I don't undestand... please, help!

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

Is the editorial out?? If not when can we expect it? Thank you.

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

Hi I am avinash204, and I received a message today that someone has copied my code and it has resulted in getting a penalty ,however, I have no clue how someone else has the same code like me as I wrote it all by myself. What about my ratings will I get it or not?

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

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