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

Автор 36champ, 5 месяцев назад, По-английски

Problem A — Convergence

Problem Idea: 36champ
Solution Idea: 36champ

Hint 1
Solution
Code
Rate The Problem!

Problem B — Cake Leveling

Problem Idea: 36champ, Proof_by_QED
Solution Idea: Proof_by_QED

Hint 1
Hint 2
Solution
Code
Rate The Problem!

Problem C1, C2 — Seating Arragement

Problem Idea: 36champ
Solution Idea: 36champ, Proof_by_QED

There are two solutions to this problem presented below.

Hint 1
Solution (C1)
Code (C1)
Rate The Problem! (C1)
Hint 2
Hint 3
Solution (C2)
Code (C2)
Alternate Hint 1
Alternate Hint 2
Alternate Solution
Alternate Code
Rate The Problem! (C2)

Problem D — Magical Tiered Cake

Problem Idea: 36champ
Solution Idea: 36champ

Hint 1
Hint 2
Hint 3
Solution
Code
Rate The Problem!

Problem E — Snaking Arrangement

Problem Idea: 36champ
Solution Idea: 36champ

Hint 1
Hint 2
Solution
Code
Rate The Problem!

Problem F — The Cake Is a Lie

Problem Idea: 36champ
Solution Idea: 36champ

Hint 1
Solution
Code
Rate The Problem!
Разбор задач Codeforces Round 1101 (Div. 2)
  • Проголосовать: нравится
  • +97
  • Проголосовать: не нравится

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

second

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

Thank you for the fast editorial

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

good contest. relatively fast editorial

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

misjudged the constraints on D

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

Why does ternary search not work on C2?

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

Can we solve C1 by dp

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

Im very sad that i did so poorly in a very cool contest, nonetheless congrats to the writers for such an amazing contest

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

I think I came up with the weirdest solution for C1 and C2 out of all the submissions. Glad that it worked :)

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

    What was your solution? If you don't mind sharing?

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

      First I precomputed the next occurrence of an introvert for every index of the string and stored it.

      Then I iterated through the string always seating an introvert and extrovert whenever I could. For the case of ambivert there were two cases:

      1. If the ambivert was only able to become an introvert or only able to become an extrovert, make him so. Never any loss in that.
      2. If an ambivert is able to become both, again two cases here:

      2.a) If the remaining count of unseated tables is greater than the remaining count of introverts, one table will go untouched, so it is clearly better for an ambivert to act as an introvert and open it.

      2.b) If the remaining count of unseated tables is less than or equal to remaining count of introverts. This means that all of the tables will be opened regardless because there are enough introverts in the string. So, extroverts/ambiverts are more valuable now. So, we will make the ambivert an extrovert by default with the exception of one case, when, till the next occurrence of an introvert from that index, there are more extroverts/ambiverts than the amount of extroverts that can be currently seated(done using the pre-computed array). Because in that case, making our ambivert an extrovert wouldn't matter as some extroverts would be kicked out of the party before the next introvert occurs.

      Hope that made sense, in short, we can just iterate through the array and decide on the fly whether an ambivert needs to be an extrovert or an introvert, and solve this problem in O(n).

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

My post contest discussion stream for A-D problems here

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

by when will ratings update?

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

C1 will be much easier if I don't overthink

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

is there any way to do C2 with some sort of exchange argument? or we stored "unplaced ambiverts" so far and when we hit an extrovert / introvert we can retroactively place them

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

Can someone describe the solution for E in more details?

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

    I also find the editorial answer insufficient. The first thing the solution should do is create a anti-diagonal array. In the given example it will be

    anti[0] = {3}
    anti[1] = {-1, 3}
    anti[2] = {-1, 3, -1}
    

    For each antidiagonal transition we find the number of ways a new snake could be added and multiply the answer by it. For a new snake that is present the answer is simply 1. Otherwise we find the number of ways it is possible to add element to anti[i] to obtain anti[i+1]

    If anti[i][j] != -1 && anti[i][j] == anti[i+1][j] the newly added ? is at place >j

    If anti[i][j] != -1 && anti[i][j] == anti[i+1][j+1] the newly added ? is at place <=j

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

could someone please tell me, why it is failing for problem B

#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<long long >a(n);
        for(auto & it: a)cin>>it;
        vector<long long>ans;
       long long sum= 0;
      long long maxHeight=a[0];
        for(int i = 0;i<n;i++){
            sum+=a[i];
            if(a[i]<maxHeight){
                maxHeight= (long long)(sum/(i+1));
            }
            ans.push_back(maxHeight);
        }
        for(auto & it :ans){
            cout<<it<<" ";
        }
        cout<<"\n";
    }
}


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

why the answer in the problem A with sorting approach is cnt/2 not ceil(cnt/2)?

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

Can someone explain C2 in more detail? I'm not understanding either of the alternate solutions. I bricked it lol

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

    Initially, treat all ambiverts as extroverts. That is, if the next friend is an introvert, place them at an empty table, and if the next friend is an extrovert or an ambivert, place them at a partially-full table.

    Now consider the case where our next friend is an extrovert, but we have no partially-full tables to assign them to. It would have been nice if we had the foresight to place a previous ambivert instead at an empty table, opening up a seat for this extrovert, and also creating a new partially-full table for any future extroverts. This is possible if and only if there exists a previous ambivert which we treated as an extrovert, and there is at least one empty table remaining. Then, the optimal strategy would have been to place that previous ambivert at an empty table, and now once we arrive at the present moment, we'd be able to seat this new extrovert.

    Of course, treating this ambivert as an introvert (to seat this extrovert and future extroverts) could mean we're unable to seat a future introvert. Fortunately, extroverts and introverts have the same weight with regards to the final answer, so this doesn't matter (plus one extrovert + minus one introvert gives the same final answer).

    This approach can be implemented in $$$O(N)$$$ time. For details, see my submission.

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

I think I noticed a greedy for B. Somebody else did? Once I have it done, I will submit it :)

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

I solved Problem E by only observing the samples and guessing the conclusion. Is there a detailed proof?

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

Tutorial for problem only gives a hint about anti-diagonals, which is cool, however there is no explanation of how to calculate the answer. Solution code is quite long, but in tutorial it's covered by just:

This can now be solved comfortably in O(n2) or in O(n) with more optimization. It's nice to know that "This can now be solved", but how to solve it? :)

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

https://codeforces.me/contest/2232/submission/376691826

can someone please expplain why this fails, the main diff is in absence of min(ans, sum/i+1) i do not get when my logic fails.

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

can we sovle c1 by couting number of extroverts and introverts after every A using prefix approaoch

and then making good decision every time an ambivert comes

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

very beautiful problem D!

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

Also, there is another greedy approach for C2.

https://codeforces.me/contest/2232/submission/376748313

that's a shame that I submitted this in the last 30 secs and because of not getting free variable in long long i got WA on pretest 18 :)

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

the second one is a nice problem

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

    can u please check out my query, i did not use min, but i am not getting how do we come to think of min, what was ur thought. i thought, if the next val if smaller than my ans, i will set the maxH to average. else i will cut to the ans i am already having.

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

      You must use min think about 4 100000 0 100000 10000 example. While I was solving the question İ thought about a similar testcase and observed that if the min of the prefix is smaller than the average of the prefix then the answer is the min

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

        fair, it took a few min to get the soln, 2,6,1 is a good testcase that helps to understand.maybe the bad assumtipn was that if current height is less than prevH, i gotta distribute it. i cud have extras, and the math will just distribute it backwards too, which is against the rules. averaging out works, only if its smaller than prevH. it can be larger becaue u can have extras. like in 2,6,1 i get till 2,2 but 4 is xtra, and i cannot give it to i = 0.

        but man it was tricky to get this during contest, do u think about extreme testcases, is it natural to not get the complete picture initially, how did u get ahead of this prob

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

cake leveling solo leveling reference??

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

got WA at C2 because of $$$x \cdot s \gt 2^{31}-1$$$ and overflowed(:lmao)

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

Guys, can somebody figure out the problem with my code (C2 problem), I am not able to comprehend the case where this could go wrong, if anyone is interested please help find the issue and share with me. I get wrong answer on test 16 some case.

https://codeforces.me/contest/2232/submission/376771561

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

    There is a testcase that leads to WA (found with the help of AI, which means I don't know whether it is the right one makes your code failed)

    1 18 3 7 EEIAAEEAAAEIIIAAEA

    expected: 14 actual: 15

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

      Thank you, understood the issue with the help of the case.

      I'm assigning Ambiverts to new tables first but the problem is if lets say one table is full, and 2 other tables have ambiverts each, I'm assuming I can replace the ambivert with an introvert by moving it to an already partially filled table, (table 2), but I never marked that the ambivert on table 3 has nowhere to go except only table 2, after moving it to table 2, I don't have a slot for next introvert. My ambiguous counter says I still have a replaceable ambivert but I don't.

      https://codeforces.me/contest/2232/submission/376791142

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

There's an alternative nlog(n) solution to C2 using a segment tree which can be optimized to linear time. Check my submissions.

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

I think I found a great solution for both the C1 and C2 problems:

  • The basic idea is to traverse through the string, and we check for each character whether we can get a seat for the person or not, if we can we simply increment the final ans variable by 1.
  • Three extra variables we use are : num, ans and cea, all initialised to zero initially. num represents the number of tables currently containing nonzero persons, and ans represents the total people that can be seated. cea represents the number of ambiverts that are seated as extroverts.
  • We make an assumption that we generally make the 'A's seat as an 'E', because the occupancy for 'E' is more in number. Thus in general, we increment cea everytime we encounter an 'A'.

  • Now, while traversing through the string, we only get into trouble finding a seat for 'E', if either num == 0 or if ans/n == s (All the tables are fully occupied).

  • In this case we check whether we previously have an 'A' that was seated like an 'E'. If yes, we simply give that 'A' a completely new table, and make 'E' sit on 'A's initial position. We also decrement nea by one in this case. Notice that since we always make 'A' seated as an 'E', we also need to check this condition whenever we encounter an 'A'

  • An introvert can always be seated, unless the value of num == x.

  • The traversing of the string can be broken once we get a value of answer which is greater than x*s, in which case we print the answer as x*s. Otherwise print the final ans after traversing the complete string. This way we can get the ans directly in a single pass in O(n) time.

  • This is my code for both C1 and C2 : 376854024 I was working on these lines during the contest, but sadly couldn't complete the code and hence got only 2 AC submissions in the contest :(

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

I really liked problem D, was a nice twist on tower of hanoi. But i was wondering, whats the optimal algorithm, that moves all the layers in the fewest moves. The solution was within 2^n — 1 moves but not the most optimal, it would do extra work. So a problem variation that asks for the fewest possible moves would be interesting. I thought of this, but it was very hard to solve myself. I'm very curious to find the solution.

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

    Boy, you and I ruined the 67 comment count.

    As for your question, it would probably have been much much harder. The whole idea that we could move MORE than 3 rings(max) at once was pretty complicated already and required some pretty nieche greedy tricks already.

    It would probably be the same thing only that more restrictions on HOW and IN WHAT ORDER you decide to move them. I am courious how the code might look!

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

    The algorithm mentioned is the editorial will produce the shortest possible sequence

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

thanks !

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

The (i+2)-th ambivert is seated when they are extroverted, and is still seated when they are introverted.

Can someone explain what does this mean in the solution C2 proof.

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

    For $$$f(i)$$$, the first $$$i$$$ ambiverts are seated like they are introverted. (I just say the first $$$i$$$ ambiverts are introverted for short.)

    Therefore, the difference between $$$f(i + 1)$$$ and $$$f(i + 2)$$$ is how the $$$(i + 2)$$$-th is acting (extroverted for $$$f(i + 1)$$$ and introverted for $$$f(i + 2)$$$).

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

In Problem C2, Found the following way to think about the diminishing returns logic more intuitive -

Let f(i) = maximum people seated when the first i ambiverts are forced to act as introverts, remaining ambiverts act as extroverts. Let T_i denote this timeline.

Claim: if f(i) > f(i-1), then f(i-1) > f(i-2).

Note that T_i and T_{i-1} are identical up to the i-th ambivert, they only diverge there. This means just before the i-th ambivert arrives, T_{i-2} has exactly one fewer active table than T_{i-1}.

Since f(i) > f(i-1), forcing the i-th extra table was beneficial. This means at some future point j (post the ith Ambivert), all of T_{i-1}'s tables are completely full. At that same point, T_{i-2}'s tables are also completely full — the same stream of people filling fewer tables fills them just as easily.

So at point j, T_{i-1} has m fully filled tables and T_{i-2} has m-1 fully filled tables, and both face an identical remaining suffix from j onward.

From here it is obvious — one extra fully filled table with the same suffix ahead is strictly better, that is s extra people already seated. The only escape would be if the venue hits full capacity x*s, but f(i) > f(i-1) guarantees it didn't — otherwise T_i couldn't have improved on T_{i-1}.

So the advantage is permanent. Hence f(i-1) > f(i-2).

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

problem E is really amazing

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

I found a solution with fewer steps than the standard recursive approach for problem D, but it got a wrong answer. Is there any case where a "faster" (shorter step count) solution is invalid?

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

C also solved binary search[submission:377858111]

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

why this if else is not trivial for me :(


if (a[p-1]==0){ shift(shift ,i,other,p-1); id.push_back(p); x.push_back(i); y.push_back(j); // 1 shift(shift,other,j,p-1); } else{ shift(shift,i,other,p-1-a[p-1]); // shift 2 ^ (k-1)-1 id.push_back(p); x.push_back(i); y.push_back(j); // 1 shift(shift,other,i,p-1-a[p-1]); // 2^ (k-1)-1 shift(shift,i,j,p-1); // 2^(k-1)-1 }
»
5 месяцев назад, скрыть # |
← Rev. 21  
Проголосовать: нравится 0 Проголосовать: не нравится
As the editorial seems insufficient, here is another way to think about E:
»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Man, The Problem B is easier than A

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