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

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

Neapolis University Pafos

Привет, Codeforces!

Благодаря поддержке Neapolis University Pafos, продолжается серия образовательных раундов.

В Apr/29/2024 17:35 (Moscow time) состоится Educational Codeforces Round 165 (Rated for Div. 2).

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

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

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

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

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

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

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

Waiting for a good contest!

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

Make this comment most disliked comment in CF

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

I hope there will be an interactive problem soon

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

Edu time I hope A-E is data structures problems , or 2 of them at least

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

All the best guys :) ;

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

The penalty for each incorrect submission until the submission with a full solution is 10 minutes. what this line means, how penalties are given in this case. I know only -50 for wrong submission is a type of penalty.

  • »
    »
    2 года назад, скрыть # ^ |
     
    Проголосовать: нравится +8 Проголосовать: не нравится
    • in Edu rounds the leaderboard is sorted Depending on how many problems you solve there is no score

    • but what if there is 2 people have the same number of problems solve they will sum the times of them and sort it by the person who have less time

    • but if person got 2WA on a problem then AC the sum of time will increase by 20 which will give him bad leaderboard place
»
2 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Hope able to solve ABC

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

I hope I don't get negative delta...

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

I wish high rating to participants

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

1800 plz!

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

Best of luck everyone.

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

Very long time no see, Educational Codeforces. I wish this contest teach me a lot.

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

pls no guessforces

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

My first Educational round. Hop to get positive delta for everybody.

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

"I wonder how you folks (BledDest, adedalic, Neon, Roms, awoo) come up with so many tasks. It's like you've been holding Educational Rounds since the invention of sliced bread=)

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

Will the 12-hour hacking part give any additional score? Will it be possible to hack the solutions of your room during the contest?

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

Hope everyone will not get stuck in A, B and C.

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

It was kinda shitty contest tbh

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

C>>>D. 10 minutes for D and 1hr+(multiple WA) for C.

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

D <<< C

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

orz

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

why my solution is failing for C ?

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

Good contest, I liked the problems.

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

Idea for D?

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

    Hint: Think in reverse operation order. Suppose you include N elements and want to remove one, what's the optimal strategy for Alice?

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

    The model approach is the following one:

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

      ah nice explanation, thanks broski

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

      Why Bob will take for free most expensive for him, if his goal is to minimize Alice profit? I sorted by $$$b_i-a_i$$$ and got different answer on pretests.

      Upd: Think I got it, Alice already paid for entire subset, so it makes sense to sort by $$$b_i$$$

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

      I sorted the lists based on the decreasing differences in values and it WA on test 3. Basically sorted a list of pairs $$$(b[i]-a[i], i)$$$. Why does this idea fail?

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

      I believe I have a more "elegant" greedy solution which utilizes different observations so I'd like to share it.

      First observe that if Alice selects fixed $$$M$$$ elements, Bob will take the $$$K$$$ with the largest sum of $$$b_i$$$.

      Next, observe that Alice never wants to take an element if $$$a_i \gt b_i$$$. Just consider both cases (Bob takes this element and Bob does not take it) and the answer never becomes worse if Alice excludes it.

      Now that we know this, suppose that Alice chooses all elements such that $$$a_i \lt =b_i$$$, let the count of such elements be $$$l$$$. Let's denote the elements selected by Bob by $$$(a_1,b_1),(a_2,b_2),...,(a_k,b_k)$$$ and the remaining ones by $$$(a_{k+1},b_{k+1}),(a_{k+2},b_{k+2}),...,(a_l,b_l)$$$. We know the total sum for this choice, because Bob chooses greedily the $$$K$$$ largest $$$b_i$$$'s.

      Now what happens if Alice wants to choose $$$l-1$$$ elements?

      We never want to remove an element that is not already chosen by Bob, because it will just reduce the total sum. If we remove an element $$$(a_p,b_p)$$$ that is chosen by Bob, the total sum increases by $$$a_p$$$ and it can trivially be proved that we can never add $$$b_p$$$ to our total sum in the future by performing removals. So it's always optimal to remove the element with the largest $$$a_p$$$ and instead of it insert the one with the largest $$$b_q$$$ such that $$$(a_q,b_q)$$$ is not present in Bob's set.

      We can easily simulate this process using two multisets.

      I didn't write the proof in a formal way here, because it would be lengthy, but one can derive it if they want.

      Here's my submission 258749293

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

    If Alice chooses some subset of elements, then Bob will pick the $$$K$$$ elements with the highest values of $$$B_i$$$. If we sort the items by $$$B_i$$$, then this just means Bob will always pick the rightmost $$$K$$$ elements in any subset. Therefore, our array will become split into 2 partitions: the left partition's elements go to Alice, and $$$K$$$ of the elements in the right partition go to Bob (we can choose the ones with lowest $$$B_i$$$).

    We can do the following: Iterate over the size of the right partition from size $$$K$$$ to size $$$N$$$, and maintain the sum of the smallest $$$K$$$ values of $$$B_i$$$ using a multiset. We then calculate Alice's profit as $$$\max(0, B_i-A_i)$$$ for all elements $$$i$$$ in the left partition, which we maintain with a prefix sum array.

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

Best contest ever!!! I very much enjoyed it :)

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

I bruteforced sorting criteria for D and resulted in a +7 AC... what a way to live... XD

Anyway, anyone can prove the validity of D? My (greedy) approach is to sort everything, first on Alice's buying cost in increasing order, then Alice's theoretical profit (assuming Bob doesn't take anything for free) in decreasing order.

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

    Let's think of a strategy for Bob. If I take s elements (s>k) then he will choose s-k elements with the minimum b. That's obviously true because sum of a is fixed and to minimize the profit Bob will choose the smallest bs. Now, I'm Alice and I know that. Then I wiill check each b. If I fix some b[i], then for all b[j] such that j>i I will choose minimum k as from them. I know that since they are k and Bob will choose minimum bs, he will not choose from them. So now remains the elements in the prefix of i. Any element I will choose in this prefix, Bob will choose it too. So I want all positive profits in this prefix. I'm not sure if this is kind of a proof, but this was my though process.

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

can someone please tell why is this giving WA on 3 is there any logic error or bug

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

I hope I'm not the only one who thinks C is an oddly difficult as usual...

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

TFW you get a WA a couple minutes before the contest ends and out of supreme luck, you unknowingly click "Mobile Version" on Codeforces and instead of debugging your code, you end up debugging what just happened 🙃

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

I got AC on problem E one minute after the contest ended. The problems were really nice, thanks

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

https://mirror.codeforces.com/contest/1969/submission/258748770 How to memoize this recursive approach to C ? Or any other recursive solution ?

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

what's the idea for c? I couldn't debug my dp solution in time, with mp[j][val] standing for j operations used and the last value being val. since val could be huge, i used unordered_map to store the status. and to avoid space overflow, status with the values that aren't possible to be at the end for current moment need to be erased. or is there a much easier solution?

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

It seems like the time limit of E is too tight. Submission https://mirror.codeforces.com/contest/1969/submission/258765134 got TLE on test 25 by using BTreeSet, however, submission https://mirror.codeforces.com/contest/1969/submission/258766945 got AC by using HashSet (it was simply replaced BTreeSet as HashSet)

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

Can anyone please explain me the DP approach to solve problem c?

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

    $$$dp[i][j]$$$ = the minimum sum when we only consider the first $$$i$$$ elements, and perform $$$j$$$ operations. We can do $$$dp[i][j] = dp[i-1][j] + A_i$$$ to do nothing. Suppose we perform $$$x$$$ moves: we convert elements $$$A_{i-x}, ..., A_{i}$$$ to the minimum element in this range (call it $$$min$$$), and the new sum of this range is $$$(x+1)*min$$$. The minimum sum for the remaining elements can be obtained with $$$dp[i-1-x][y]$$$, where $$$y$$$ is the # of moves performed beforehand. Therefore, we do $$$dp[i][x+y] = (x+1)*min + dp[i-1-x][y]$$$ for all pairs $$$(x,y)$$$ where $$$x+y \le K$$$.

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

      thanx for explaining the states and transitions

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

      If I define dp[i][j], the maximum sum of elements I am able to delete, if I am at index i and perform j operations. Then I subtract the maximum value of dp[i][j] from the total original sum of the array, why am I getting wrong answer ?

      Edit — Resolved. Should have used long long.

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

My second educational round, and again not solve C. So educational round means high difficulty??? Both two my edu round solve only AB and rank 3600+ (:_;)

I'm going to be specialist and hope to get my rate back in div3 round a few days later X(

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

Fantastic Edu round as always. Thanks a lot BledDest awoo adedalic Neon Roms and all testers!

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

I posted my code of problem D in the last 10 seconds, but the evaluator didn't receive it.

After the contest finished, I reposted my code, and then it was accepted.

Now I wanna die right now.

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

C was bit hard for its position.

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

C was obvious dp don't why some people found D easier than C is it because there is some standard idea / technique if so please tell me. Thanks!

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

Many solutions to problem A, including mine, are hacked, because of set.

How is it possible? The time complexity is $$$O(t∗n∗(n−1)/2∗4∗log(4))=O(5∗10^7)$$$ which should not work longer, than 2 seconds.

I have solved ABCDE, and would become a master, if my solution to A wasn't hacked :(

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

For problem E 258747661 should be hackable. I have no proof on the bound of the no of iterations.

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

Can anyone explain what does it mean "Generator is not determinate [the verification run produces different output, cmd =7 4956565656565656564512121], [1100006 bytes, '1000 300 6 151 55 114 76 65 24 12 86 135 38 98 2...290 266 282 34 73 297 245 5 118 261 79 200 35 ', sha1=f0a1c17d87899a11c1db8f805df18da45b1251d5] vs. [1100006 bytes, '1000 300 2 151 55 114 76 65 24 12 86 135 38 98 2...290 266 282 34 73 297 245 5 118 261 79 200 35 ', sha1=a2117fdfb95eb249f578f57f01f328e2a91fc766]."

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

I really liked problems D and E!

»
2 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится
Solution on C using DSU

can anyone provide counter example? I don't see any reason why this not working.

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

    You are applying a greedy algorithm, i.e. merging the immediate best, rather than doing a deeper search.

    For example,

    1 5 2 20 10 19 28

    Your algorithm will see the largest difference (20-10) and merge them, and then merge 19 together, totaling 10+10+10+28 = 58. but the optimal solution would be 20+10+10+10 = 50

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

I just spent quite a while debugging my solution to C, which I was confident was correct but failed on test 5 due to a runtime error. It turns out that it was a stack overflow error, and after I increased the stack size, my solution passed (original, with increased stack size). I feel that I should have gotten credit for my original solution during the contest since it would have passed within the given time and memory constraints and only failed due to a restriction in the judging environment.

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

I have solve the problem E by Monotonic Stack in O(n).

The submission

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

How to solve E?

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

    let st[i] be the largest j so that j < i and the subarray [j, i] is not unique (if j doesnt exist, st[i] = inf).

    Now, if st[i] < i (for i = 1 -> n), we have a segment [st[i], i], now the problem becomes: calculate the minimum number of black points so that each segment contains at least 1 black point. It's easy to solve using deque and dp.

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

Could someone explain why this solution was hacked in problem A? Here's the link to the submission: link. It's supposed to be ( n^2 ) and should pass. Can someone verify if the test validator is working correctly?

awoo adedalic BledDest Neon Roms

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

Good edu round :)

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

Could someone please tell me why this contest didn't count towards my rating? I did the registration as usual

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

where's the contest?

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

Until the editorial gets published, can anyone provide some help regarding problem F? I've been thinking of some DP, where $$$dp_i$$$ = number of coins you can get if you start with a full unique deck and have the last $$$i$$$ cards in the stack. I tried to come up with the transitions but I am missing something. Thank you in advance!

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

    Assuming “full unique deck” means one card of each number, you’re on the right track. In terms of transitions, here are some questions to think about:

    1. Suppose you want to transition from turn i to turn j. How can you determine which cards to discard on turn i in order to end up with cards 1..k on turn j? (Try writing out a few small cases.)
    2. How does discarding cards affect the number of pairs you can make? (It helped me to think about your DP state as minimizing the number of pairs you eliminate from the deck. How does discarding a card with an odd number of occurrences differ from discarding a card with an even number of occurrences?)
»
2 года назад, скрыть # |
 
Проголосовать: нравится -11 Проголосовать: не нравится

Congrats to OliviaRodrigo who did very well on the contest! Big fan of your songs here!!

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

For problem B pre-test did'nt include overflow cases. :cry

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

Will the rating changes before 942??

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

Could someone explain me why this https://mirror.codeforces.com/contest/1969/submission/258724763 code for B got AC on pretests and now is getting WA on test 1? I understand why it fails but why didnt it got WA on the same test during the contest?

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

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