omsincoconut's blog

By omsincoconut, 5 months ago, In English

2179A - Blackslex and Password

Author: IceBorworntat

Hint 1
Solution
Implementation (Python)

2179B - Blackslex and Showering

Author: spycoderyt

Hint 1
Solution
Implementation (C++)

2179C - Blackslex and Number Theory

Author: omsincoconut

Hint 1
Hint 2
Hint 3
Solution
Implementation (Python)

2179D - Blackslex and Penguin Civilization

Author: omsincoconut

Hint 1
Hint 2
Hint 3
Solution
Implementation (Python)

2179E - Blackslex and Girls

Author: spycoderyt

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Implementation (C++)

2179F - Blackslex and Another RGB Walking

Author: omsincoconut

Hint 1
Hint 2
Hint 3
Solution
Implementation (C++)

2179G - Blackslex and Penguin Migration

Author: omsincoconut

Hint 1
Hint 2
Hint 3
Solution
Implementation (C++)
Challenge

2179H - Blackslex and Plants

Author: NortGlG

Hint 1
Solution
Implementation (C++)
  • Vote: I like it
  • +164
  • Vote: I do not like it

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for the contest. It was nice one

»
5 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Can you please put the codes on the blog? I can't visit the solution links.

»
5 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I liked the problems, Thanks for the good contest.

But E was a blocker for me, couldn't come up with a valid approach :(

»
5 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Very good contest and fast editorial

Please put the codes on the blog

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for the contest and fast editorial, the problems were quite interesting, maybe just E could have been swapped with F. Overall the contest felt good!

»
5 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

My roommate was playing games and shouting while I was solving problems, which distracted me so much that even though I had fully figured out Problem D, it still took me 30 minutes to write the code. But I seem to have no idea at all about Problem E. :<

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

none of the implementation link is accessible.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great Contest ! I'll need to work on Bit Manipulations now :)

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Couldn't even solve C. I don't even know what went wrong for me in this contest.

»
5 months ago, hide # |
Rev. 8  
Vote: I like it +16 Vote: I do not like it

Problem G: (Challenge)

After finding first corner, now we have N candidate corners. the farthest candidate from the arbitrary point (initial random point) would be the corner which we are looking for. And those distances from initial point are already computed.

So we can find 2 non-opposite corners in $$$2n^2$$$ queries, thus solving the problem in $$$3n^2$$$ queries

Corner Case: If the first random picked point is at the corner. (max distance = $$$2N-2$$$) then we can use this arbitrary point as the corner, and proceed with the editorial solution, would cost $$$2n^2 + n$$$ queries

Submission: 354860434

  • »
    »
    5 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Consider when the "arbitrary point" from the start is a corner itself, so the distance of every "candidates" to the "arbitrary point" will be $$$n-1$$$, which is indistinguishable.

    Update: Yes, I implemented this approach and failed miserably.

    • »
      »
      »
      5 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it +13 Vote: I do not like it

      If initial point is corner, then we can completely skip step 2 (since we have all distances from a corner) and proceed with the normal solution

      • This would take: $$$n^2$$$ (initial point) $$$+ n$$$ (main diagonal points) $$$+ n^2$$$ (other corner) queries = $$$2n^2 + n$$$)
»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for the contest. Though it went pretty bad for me, I learnt a lot.

»
5 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

I was stuck on E while trying to find a construction (I have no idea why I was trying to construct a solution) but anyways, I reached a way to construct a solution that I want to share.

Let $$$sumX$$$ be the sum of array $$$x$$$ for any array $$$x$$$. It is trivial that there is no solution if $$$sumP \gt x + y$$$. Otherwise, we know that $$$sumP \leq x + y$$$. Now, consider the following approach of iterating over the string if $$$s_i$$$ is equal to $$$1$$$ put $$$b_i = p_i$$$, otherwise put $$$a_i = p_i$$$. Now, we are sure that the second and third conditions are satisfied. We will try to satisfy the first one without messing with the other two.

The main observation is that since $$$sumP \leq x + y$$$, we have atmost one correct codition of $$$sumA \gt x$$$ or $$$sumB \gt y$$$ (since $$$sumA + sumB = sumP$$$ and $$$sumP \leq x + y$$$). Let us focus on one of them and the other one will be solved similarly because of the similarity. Let $$$sumA \gt x$$$. We will try to fix it while maintating $$$sumB \leq y$$$. Now, we can check all indices where $$$s_i$$$ is equal to $$$0$$$ and we know that $$$a_i \gt b_i$$$. So, we can reduce the value of $$$a_i$$$ and add the difference to $$$b_i$$$ while still not reaching $$$a_i$$$ and $$$sumA \geq x$$$. (you can ask yourself now if this can violate the condition of $$$sumB \leq y$$$ but the answer is no because we know that $$$sumA + sumB = sumP$$$). If we can not fix the condition $$$sumA \gt x$$$ using this approach then we will never can.

If the condition is fixed so we now have $$$sumA \leq x$$$ and $$$sumB \leq y$$$. The last part of the algorithm is easy by trying to add the difference anywhere in both arrays and it is easy to see that this will not violate any of the three conditions.

Submission: 354831958

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is there a typo in Hint 2 of Problem D? It says $$$p_i = 2^n-i+1$$$, but shouldn't it be $$$p_i = 2^n-i-1$$$?

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for the contest and i really liked the problems..Need to work more on my number theory

»
5 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

Solution to challenge of G.:

Spoiler

Code: 354857075

P.S. I wonder if this problem can be solved by $$$2n^2 + o(n^2)$$$ queries.

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I believe there exists a solution with max 2.5 n^2 queries (there might exist an edge case i didnt consider):

    Spoiler
    • »
      »
      »
      5 months ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      There can be many intersections instead of $$$2$$$. Please note that the distance used in this problem is Manhattan distance.

  • »
    »
    5 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it +8 Vote: I do not like it

    sorry, wrong approach

    • »
      »
      »
      5 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      The parity only helps you when finding the corner point. However to answer the exact position you actually need something like the distance from two corners to every other grids, so optimization in finding corners seems doesn't work.

      I think the bottleneck is the first $$$n^2$$$ queries, as some worst case is $$$1$$$ on the grid $$$(1, 2)$$$ where we will lose tons of information in first $$$2n^2$$$ queries following the strategies above, causing that we have to make another $$$O(n^2)$$$ queries.

»
5 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

D can also be implemented by sorting the binary strings of the numbers from 0 to 2^n — 1 by the follwoing rules

if we compare string a & string b

the string with more continuous 1s in the suffix comes first

if both string have the same, then the string whose decimal value is smaller comes first (for lexi-min).

so 2^n — 1, has all 1s, comes first always.

Consider two numbers say 10111 and 00111 both these strings have 3 continuous 1s inn the suffix, we pick 00111 because (7 < 23).

This ensures we maintain max popcount for as long as possible in the prefixes of the resulting permutation.

Submission: 354826764

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

not that im complaining but, why are there so many communication/interactive problems in codeforces rounds nowadays? are they untouchable for AI or is it just that they're more interesting?

»
5 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Ok initially I thought H would be hard to implement, but the code was surprisingly short

»
5 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

I accidentally got $$$3n^2$$$ + $$$n/2$$$ queries for G

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Another approach for D, There was a pattern hidden in it. first number = (1<<n)-1, hence the adder here is (1<<(n+2)), add this number and insert this into the answer array this it reaches or exceeds (1<<n). Next number = (1<<n-1)-1, repeat the process. Stop when the answer array size is (1<<n). 354825334

»
5 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

I came up with another approach for H:

Let lsb(x) be the position of the least significant bit in x. It is possible to see that lsb(x-y) (with x > y) is simply the first position at which x and y differ.

The answer for plant i is the sum of (i-l+1) * (1<<lsb(i-l+1)) for each interval covering i, which can be computed this way: (i+1) * sum(1<<lsb(i-l+1))-sum(l * lsb(i-l+1)). (sum(f(l)) is the sum of f(l) over all intervals covering i).

Note that i+1 > l so we can use what's written above, then for each interval covering i we only need to know the first position at which it differs from (i+1) in order to compute lsb(i+1-l).

This can be done using a trie. In each node we need to store the number of active intervals having next bit 0,1 and the sum of l for all active intervals having next bit 0,1. This way, when computing the answer for i, we can visit the trie following the nodes based on i+1 and keep track of sum(1<<lsb(i-l+1)) and sum(l*lsb(i-l+1)).

»
5 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

I spent a long time trying to understand the statement of problem A, and eventually gave up. Seeing how many people solved it in a very short time, I guessed that it was probably just a simple formula. I inferred an answer from the samples, submitted it, and surprisingly got AC.

Problem B was very straightforward, nothing much to say.

Problem C had very good samples that gave a lot of hints, and I more or less wrote the solution directly based on them.

Problem D was the most interesting one for me — the difficulty felt just right, and after figuring it out, it didn’t feel that boring like others.

Problem E, on the other hand, felt quite uninteresting. I missed one corner case that should output NO, so I didn’t pass it. After reading the editorial, I’m even more convinced that this problem wasn’t very enjoyable.

Problems A to E took all of my time, so I didn’t get a chance to look at the more interesting interactive problems later.

As a non-native English speaker, I somewhat dislike the forced and awkward character background stories in the statements. To me, they are purely distracting. Also, there’s no need to try to make all problems look like parts of a single story — they really aren’t.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could someone explain D's solution to me? I understand up to hint 2, but I think it is a little ambiguous on what "i" is. Additionally, the python implementation seems like it doesn't follow the above solution consistently.

In particular, what does "[fixing] the i lowest-value bits" mean?

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Sorry for the duplicate variable use. $$$i$$$ in hint 2 is the index in the permutation. $$$i$$$ in hint 3 is the prefix AND popcount. Fixing the $$$i$$$ lowest bits refer to how the last $$$i$$$ bits are all 1.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't know what happened to me in this game, but I couldn't even solve the D task because of stupid mistakes. But the round was interesting.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could someone please tell me why my solution is wrong:

https://mirror.codeforces.com/contest/2179/submission/354888747

This didn't pass during the contest, and I didn't pay attention to it. Right before I went to sleep, I got an idea, and I thought that was the mistake. It made it better, sure, but it's still wrong

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Binary contesttt

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

problem C went over me completely, B was straightforward....

»
5 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

for problem C, in the sorted array, if a[1]=1, the the answer should be a[2] isnt it ? please correct me if I am wrong Edit-got the mistake, was confued bw modding and divind to make all equal :(((

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Bit difficult according to DIV3

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In problem C, there is much intresting thing i have found is that the pattern i see in the sample testcases which are basically sort the array which is given in the input and take the maximum of first value and the difference between second and first value after sorting the array, i do not know why this works but i see the pattern and it works too.

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    yeah it is correct.

    Reasoning: the answer has to be >= than the smallest element in the array(in case of equality we can make every element zero).

    If the answer is greater than that , then all elements have to become equal to the smallest element after all the operations are done. Now, lets assume x is the smallest element and y is some element bigger than x, then the condition for y to become x is : y = (k)(q) + x where k>x. This k can be maximized when q is minimum i.e. q=1 (q!=0 bcz all elements are distinct) which yields k = y-x.

    Now , this value of y-x is smallest when y is the second smallest element in the array.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

There must be something wrong with the prob c!!i couldn't even pass the sample in the contest, then i tried my thought then it turned out to be right, that's infrustrating!!!

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

wait what contest was yesterday and it is showing me that editorial was uploaded 2 days ago! is this only for me?

»
5 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

In problem-E

if one of the party run out of votes , for example say party-A we can dump some voters from party-A to party-B (only where s[i] = '1') we can check if we have enough ones to dump enough voters for A to B such that sumA become equal to x

now for any remaining y, we can arbitrarily increase voters for B, if number of ones > 0 in S

-- same can be said for party-B running out of votes -- if both party run out of votes, x + y — (sumA + sumB) becomes negative , then ans is not possible even with dumping logic

i would like to know , where i am wrong, this problem ruined my contest 354850547

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello everyone. Thank you for editorial!

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my first contest! i'm 411 now yay!

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think for the problem F, the solution will work for non-bipartite graphs as well. Can someone give me a counter-example where it fails?

»
5 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

There is a typo in the editorial for G, the "solving the system of equations" shows the wrong final equations.

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

H can be solved with a square root algorithm by directly simulating larger powers of 2 and using dynamic programming on smaller values. https://mirror.codeforces.com/contest/2179/submission/354987709

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

very mathematical contest liked it

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Guys, for problem E, why

$$$\frac{p[i]}{2}+1$$$

is the lower bound?

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone please explain problem D's solution in a simpler way? Especially the given implementa.tion.

»
5 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

It would be really helpful to me if someone can explain Problem E Solution because i am not able to understand it properly, the winning condition i got but is it necessary to have like that pi/2 + 1 . and also how are we going to fill the remaining votes and what will be the approach to do that

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i couldnt understand problem H

»
5 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

problem D I think hint 2 is wrong ?

»
5 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

In problem F, why did we restrict ourself to biparate? I don't know for sure but I solved using some approach thats similar maybe but I feel it will work for non-biparate as well..

Edit: Sorry I got it!

  • »
    »
    5 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    It is to avoid the case where two neighbouring nodes have the same color hence avoiding conflict among choices

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem H (Challenge):

Solve the modified problem where you're given a parameter $$$k$$$ and instead of $$$x\cdot \text{lsb}(x)$$$ you do $$$x\cdot k^v$$$ with $$$v=\max_{i\geq 0}{i\cdot[k^i | x]}$$$.

»
3 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For a clean implementation, note that iterating the unfixed bits is basically iterating even numbers.

can you please explain this a little bit more as I'm not getting your Implementation.

  • »
    »
    3 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    So, we will fix $$$i$$$ set suffix bits, then iterate the $$$n-i$$$ prefix bits. When iterating the prefixes from lexicographical minimum, you would be iterating all nonnegative integers with $$$n-i$$$ bits from small to large. But, the last bit of the $$$n-i$$$ prefix bits must be 0, as otherwise we’d have $$$ \gt i$$$ set bits, so we’re iterating over only the even integers.

    • »
      »
      »
      3 months ago, hide # ^ |
      Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      Ok thanks I got it, I will also add my explanation to help people in the future.

      Let's say that $$$n = 7$$$, and the current $$$i$$$ that we fixed is 3.

      Which means that we have something like this: _ _ _ _ 1 1 1

      Here we fixed the 3 bits on the right, and we want to iterate and get all the numbers that have these exact three bits on the right. Instead of going through all the possible numbers and checking which one has these 3 fixed bits, we can iterate over all numbers only up to $$$2^{n-i}$$$ and left shift each one of them by $$$i$$$ and then add $$$2^i - 1$$$ to it.

      But we don't want to have something like x x x 1 1 1 1 where the 4th bit is 1 because we already dealt with this case when $$$i$$$ was 4, so if we only use even numbers, we guarantee that this 4th bit will be 0.