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

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

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
Разбор задач Codeforces Round 1093 (Div. 1)
Разбор задач Codeforces Round 1093 (Div. 2)
  • Проголосовать: нравится
  • +12
  • Проголосовать: не нравится

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

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

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

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

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

Nice Contest!

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

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

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

Nice Contest

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

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

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
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

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

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 :)

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

    Here you go:

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

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

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

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

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

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

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

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

    Me too bro

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

    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.

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

      "(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)

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

    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

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

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

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

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

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

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

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

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

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

    what was your approach can you elaborate a bit?

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

      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.

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

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.

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

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

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

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

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

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

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

    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 :)

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

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

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

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?

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

    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$$$.

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

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

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

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

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

div1A illustration should say n=6 not n=7

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

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

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

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
»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

div2 B and Cis too hard

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится
Solution to Extra of 2C/1A
»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

Problem C was interesting, thanks.

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

Interesting problems, thanks!

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

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

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

Editorial isnt linked to the div 2 round

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

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
»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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)

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

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