misteg168's blog

By misteg168, history, 5 months ago, In English

Thanks everybody for participating in the round!

Div2A. Blocked

Author: misteg168 Preparation: misteg168

Hint1
Solution
Code

Div2B. OIE excursion

Author: danx Preparation: danx

Solution
Code

Div1A Grid-L

Author: rlidon2006 Preparation: misteg168

Hint1
Hint2 (strong spoiler)
Hint3
Solution

Div1B Unique values

Author: misteg168 Preparation: misteg168

Solution B1
Solution B2

Div1C

Author: misteg168 Preparation: misteg168

Hint1
Solution

Div1D. MEX Replacement on Tree

Author: Misuki Preparation: Misuki

Hint1
Hint2
Hint3
Hint4
Hint5
Solution

DivE. Weird Chessboard

Author: rlidon2006 Preparation: misteg168, rlidon2006

Hint1
Hint2
Hint3
Hint4
Hint5
Hint6
Hint7
Hint8
Hint9
Hint10
Solution
  • Vote: I like it
  • +12
  • Vote: I do not like it

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

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

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

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

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

Nice Contest!

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

371035963 Is this the cleanest way to write Div1 B2 :) ?

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

Nice Contest

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

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

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
for i in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    if len(set(a)) == n:
        print(' '.join(sorted(list(map(str,a)))[::-1]))
    else:
        print('-1')

i think i did exactly" If there are two equal elements in a , one of them will be blocked. Otherwise, sort a decreasing."

still didn't worked

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

Contestant so goated (HE IS ACTUALLY THE GOAT) that his contest submission is used as the formal code for solution E. Though, would love to have the author's code for problem E added as well :)

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

    Here you go:

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

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

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

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

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

It turns out this greedy implementation for D1C passes. Does anyone have an idea why?

https://codeforces.me/contest/2219/submission/371036202

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

    Me too bro

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

    Assuming you understand the elements of the solution (you should pick some order to go through the nodes in, and then for each keep picking it until it turns red), here:

    Consider you have two neighboring nodes $$$u$$$ and $$$v$$$ that are used one after the other in the order with red neighbor ratios $$$\frac{a}{b}$$$ and $$$\frac{c}{d}$$$ respectively (at the time that they're used). Then, the expected value here is $$$\frac{b}{a} + \frac{d}{c + 1}$$$. If you swapped their order, the expected value here is $$$\frac{d}{c} + \frac{b}{a + 1}$$$. So, it's beneficial to swap if $$$\frac{d}{c(c+1)}$$$ is bigger than $$$\frac{b}{a(a+1)}$$$.

    Note that this is a comparator based on the nodes themselves! So, at any given step, if the node with the minimum value of $$$\frac{b}{a(a+1)}$$$ is at some later point in the projected order, you can keep bubbling it up earlier and never lose (note that if two nodes didn't neighbor, swapping them in the order doesn't matter).

    Maybe not the most formal but yeah roughly this exchange argument is the reason.

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

      "(note that if two nodes didn't neighbor, swapping them in the order doesn't matter)" could you explain that a bit more, please? I'm having trouble visualizing the case:

      R-1-2-3-R, where R is a Red node.

      1 and 3 don't neighbour, but isn't there a possibility that even though 1 is better than 3 at first, choosing 3->2->1 is better than 1->2->3 or 1->3->2? (Considering 1, 2 and 3 may have other neighbours besides the ones drawn)

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

    UPD: I found out why it works

    For any black node $$$u$$$ with degree $$$\deg(u)$$$ and $$$cnt(u)$$$ red neighbors, the probability of selecting a red neighbor in one operation is $$$\frac{cnt(u)}{\deg(u)}$$$.

    $$$\therefore$$$ the expected number of operations to color node $$$u$$$ red is:

    $$$ cost(u) = \frac{\deg(u)}{cnt(u)} $$$

    Suppose you have two adjacent black nodes, $$$u$$$ and $$$v$$$. If you color one, it becomes a red neighbor to the other, increasing the other's $$$cnt$$$ by $$$1$$$ and reducing its expected cost.

    Let's compare the total expected cost of the two possible color orderings:

    $$$ cost(u,v) = \frac{\deg(u)}{cnt(u)} + \frac{\deg(v)}{cnt(v) + 1} (u\text{ and then }v)$$$
    $$$ cost(v,u) = \frac{\deg(v)}{cnt(v)} + \frac{\deg(u)}{cnt(u) + 1} (v\text{ and then }u)$$$

    To minimize the expected operations, we must order $$$cost(u,v)$$$ and $$$cost(v,u)$$$ (exchange argument):

    $$$ \frac{\deg(u)}{cnt(u)} + \frac{\deg(v)}{cnt(v) + 1} \lt \frac{\deg(v)}{cnt(v)} + \frac{\deg(u)}{cnt(u) + 1} $$$

    Rearranging:

    $$$ \frac{\deg(u)}{cnt(u)} - \frac{\deg(u)}{cnt(u) + 1} \lt \frac{\deg(v)}{cnt(v)} - \frac{\deg(v)}{cnt(v) + 1} $$$

    Some more rearranging and simplifying:

    $$$ \frac{\deg(u)}{cnt(u)(cnt(u) + 1)} \lt \frac{\deg(v)}{cnt(v)(cnt(v) + 1)} $$$

    Use this as a heap (priority queue) comparator

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

how tf tourist hardcoded div1E ive seen him many times hardcoding unlike other top coders

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

    Surprisingly appeared in his dreams!!

    He might have used any generator or something similar with intended logic, ran it locally and got the values. What else can be the reason? And everyone has their own coding style. We can see people become LGMs with different approaches, not something one should focus on.

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

      Yeah, and your llm coding style is funny too! Which we probably should focus on

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

        Doesn't matter to me! I don't have any ulterior motive with my rating (unlike others). I would probably defend it, but it's too futile. You might have your own reasons, let CF decide that. Thanking you for your kind words.

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

    It is not "hardcoding", he seems to be using the same fractal as the official solution. (We run the visualizer)

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

    haha i was wondering the same

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

    what happened to u today bro, why didnt u solve the contest after B??

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

      i am no more into coding am pursuing an altogether different stream(humanities) so i just code for the sake of refreshment in my breaks and to maintain that streak thats it the moment i get even a little discomfort in thinking i just quit ill be participating in icpc thats it for the sake of passion that i previously had nth more than that

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

Wow... I realised the trick for Div2B with m = 2 but I didn't realise it would work for m > 2... Is it still possible to simulate Div2B? I tried with some kind of method but it kept getting WA2

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

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

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

I solved Div2C problem in a way that I can't even imagine why it's correct. 371022604

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

    what was your approach can you elaborate a bit?

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

      Since geometry isn't my strongest suit, I used a constructive approach instead of a pure mathematical one. My approach is based on the observation that if we have enough L-pieces, we can always form a base $$$n \times n$$$ grid. From there, I expanded the grid into an $$$n \times m$$$ rectangle by adding columns.

      Each additional column of height $$$n$$$ requires $$$n$$$ L-shaped pieces and $$$1$$$ unit segment (_). If I have an excess of unit segments, I can perform an "exchange": 2 unit segments can be replaced by 1 L-piece at any corner of the grid.

      To find the balance, I solved the equation for $$$k$$$ (the number of exchanges): $$$n \cdot (P - 2k) = Q + k$$$ $$$\Rightarrow k = \frac{n \cdot P - Q}{2n + 1}$$$

      • Where:
      • $$$P$$$ is the available unit segments.
      • $$$Q$$$ is the available L-pieces.
      • $$$n$$$ is the current height (fixed side).

      I simply iterated through all possible $$$n$$$ up to $$$\sqrt{S}$$$ and checked if a valid $$$m$$$ exists that satisfies the total segment count.

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

A, B, C were great but clearly today was not my day, misread the question in A, made a silly error in B, and panicked in C which resulted in me ignoring a obvious condition, end result being 0 solves.

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

Hint 2 of D1A should have if and only if instead if an oly if. Just a small typo :)

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

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

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

Could anyone please explain Div2C's solution. I'm having a hard time understanding it.

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

    For any answer to exist, it must satisfy the following 2 conditions :
    1. A valid $$$n \cdot m$$$ matrix should exist.
    2. It must be possible to arrange these p (segments) & q (L-shapes), to cover all edges of the $$$n \cdot m$$$ matrix.

    For condition-1, for a $$$n \cdot m$$$ matrix to exists, then its total edges must be equal to $$$p + 2 \cdot q$$$.

    Now let,
    $$$E_h$$$ = Total horizontal edges of $$$n \cdot m$$$ matrix
    $$$E_v$$$ = Total vertical edges of $$$n \cdot m$$$ matrix

    Then,

    $$$E_h + E_v = p + 2 \cdot q$$$
    $$$(n + 1) \cdot m + n \cdot (m + 1) = p + 2 \cdot q$$$
    $$$n + m + 2nm = p + 2 \cdot q$$$

    Here, it can be proven that :

    $$$min(n, m) \le \sqrt{p + 2 \cdot q}$$$

    Now let n <= m (for ease of understanding), then we can iterate over all n in sqrt(p + 2 ⋅ q) time. Then for FIXED p, q and n we can easily find m as,

    $$$n+m+2nm=p+2⋅q$$$
    $$$m \cdot (1 + 2 \cdot n) = p + 2 ⋅ q - n$$$
    $$$m = (p + 2 ⋅ q - n)/(1 + 2 \cdot n)$$$

    Hence, we get our possible (n x m) candidate dimension for given p and q.

    Now, how to check if this dimension is correct or not? For that lets analyze the edge difference of the matrix :

    $$$E_h - E_v = (n + 1) \cdot m - n \cdot (m + 1)$$$
    $$$E_h - E_v = m \cdot n + m - n \cdot m - n$$$
    $$$E_h - E_v = m - n$$$

    If the difference is non-zero, then it can only be obtained by using straight segments only.
    Cause using a L-shape increases both horizontal and vertical edge count by +1, no matter what orientation of it was used. But using a straight segment affects only one type of edge, either horizontal or vertical i.e. this difference gap could only be achieved by using straight segments only.

    So, from here we get our necessity condition :

    $$$p \ge |m - n|$$$

    Let,
    $P_h$ = Total horizontal edges using only straight segment
    $$$P_v$$$ = Total vertical edges using only straight segment

    Also, since the difference is caused only by straight segments only, we get,

    $$$E_h - E_v = m - n$$$
    $$$P_h - P_v = m - n$$$

    Also,

    $$$P_h + P_v = p$$$

    Adding these two equations we get,

    $$$2 \cdot P_h = p + m - n \implies p \equiv (m - n) \pmod 2$$$

    This means p and |m-n| MUST have the same parity.

    So, the remaining p's must be even numbered. Hence, these remaining segments come in pairs (1 horizontal + 1 vertical) and can be used as L-shape. See the editorials explicit construction for its sufficiency.

    Hope this helps :)

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

TYSM for this wonderful contest that promoted me to pupil!!! :)

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

For the sufficiency proof of div2C why can we assume that $$$p = m - n$$$? and why $$$p, q$$$ that satisfies the constraints will always give the construction in solution?

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

    I looked at it like this:
    1. You can always construct an $$$ m * m$$$ grid with $$$2*m*(m+1)$$$ $$$ L-shapes$$$ perfectly.(You first make the diagonal, then set all the pieces in the upper and lower triangle facing inward.)
    2. Now WLOG if you increase one side to $$$m+1$$$, then you can place all the new pieces such that only 1 line segment is missing, if you only try to increase 1 side of the grid. Then you can generalise this for any $$$m $$$ and $$$ n$$$.

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

sqrt is too fast in D1A, i couldn't see anyone doing the bonus... what's the time complexity? should an A2 be made?

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

My approach was a bit different for C ,atleast the condition to check.

L-shape contributes 1 horizontal edge and one vertical edge no matter how we place it.Total number of horizontal edges is (m+1)*n and vertical edges is (n+1)*m

therefore q >= min(m*(n+1),n*(m+1)) = min(m,n) + m*n ----------- 1

also this condition is sufficient to check as then you can use the construction in the editorial .

for implementation i saw that E = p+2*q , where E is the number of edges in the grid also E = 2*n*m + n + m It can be seen that (2*E+1) = (2*m+1)*(2*n+1) = d*e

so basically we have to check odd divisors of 2E+1 say d,e

just set n = (d-1)/2 and m = (e-1)/2 and check the condition 1 if no pair satisfies return -1

code

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

div1A illustration should say n=6 not n=7

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

we are having no contests until April 23rd, damn...

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

can sb pls explain for div2b how the answer for the following test case, is yes?

1
5
5 5 1 2 3

there is nothing you can do in the first second?! imo the question has to have two conditions :

  1. no subarray of size m+1(yes not m) with all equal elements should exist
  2. (m + 1) — number of duplicates at the begining — a[0] > 0
»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

does any body have an answer for the extra in div1A div2C ?

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

div2 B and Cis too hard

»
5 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it
Solution to Extra of 2C/1A
»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I have written the craziest solution for C lol, took so much time optimizing finding patterns and what not, just wanted to share it over here if anyone is interested.

https://codeforces.me/contest/2219/submission/371142745

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

Problem C was interesting, thanks.

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

Interesting problems, thanks!

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

https://judge.yosupo.jp/problem/factorize for this, 100 cases is about 0.1s* if p,q<=3e17, and the total number of divisors is up to about 1e7 in all cases, so doing recursion would iterate through 5e6 divisors which is doable in 1s. Squfof is probably also doable, but seems like everyone does rho instead. 1e18 is probably also doable with the same method.

*depends on implementation

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

Editorial isnt linked to the div 2 round

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

Best approach for C (DIV1 A)

  • p+2q = n+m+2nm
  • multiply 2 both sides and add 1 both sides, equation becomes 2p+4q+1 = (2n+1)(2*m+1)
  • now 2n+1 and 2m+1 are odd and we know the value of 2p+4q+1, so all we need is odd factors
  • but there is one edge case, example p=2, q=10, here (1,7) will come as a valid factor pair but it is wrong, so we need to check q<=n*(m+1) for each factor pair
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

https://codeforces.me/contest/2219/submission/371894684 Does anyone know why such construction method works? I found this totally acceptable by accident (and luck of course)

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

For question C, would the pattern consisting of two L shaped pieces placed together to form a square be a valid combination? Im not sure if this is made clear in the question