KAN's blog

By KAN, 10 months ago, translation, In English

The harder 4 problems are from the Yandex Cup Finals.

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Vote: I like it
  • -327
  • Vote: I do not like it

»
10 months ago, hide # |
 
Vote: I like it -143 Vote: I do not like it

There are many people cheating (including me :(). Why don’t cheaters get banned?

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

div2 D was so amazing problem!

»
10 months ago, hide # |
← Rev. 2  
Vote: I like it +23 Vote: I do not like it

div1D can be reduced to a well-known problem: finding MEX in a path. I wonder why only 2 participants solved this problem.

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

    I tried to code that but not passed because of the case of $$$sum-w_{n-1}-w_{n-2}+w_n+w_{n+1}$$$ :(

»
10 months ago, hide # |
 
Vote: I like it -228 Vote: I do not like it

Great problem 2174D LeoPro and proof for 2-swap is cool.

I solved it as follows

  • Check if cheapest $$$N-1$$$ edges are disconnected.
  • Standard 1-swap(brute-force)
  • Top $$$K$$$ 2-swap(brute-force with $$$k=20$$$)
  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +46 Vote: I do not like it

    Cheater, that was definitely solved by AI. :)

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

    Shut the fxxk up AIer,obviously you're a cheater.

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

    Bro wants that #1 so bad

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

    A stupid cheater using AI could only hide behind the screen and be laughed by a fake "rank 1"
    Might you spent time on deleting the note generated by AI,like here 352200733 ,another cheater
    It's pretty "hard",isn't?

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

I changed one letter and my code was accepted in question C.

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

As the author of d1B, here's another solution:

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

    Hi, could you suggest me an optimization for my implementation for Li Chao Tree? It gets TLE on test case 2. Or do i need to learn CHT/dynamic Lichao Tree? (i hate myself)

    C++

    any help is appreciated

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

      Because you are building a Li chao tree of size $$$4 \cdot 10^5$$$ too much times :(

      There are $$$k$$$ slopes at most so you can pre-calculate them to reduce the size to $$$k$$$ if you don't want to implement a dynamic one.

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

Div 2 Problem B can be solved using random values by making sure that we don't have any duplicate element in the prefix except for the range l to r where we want it to be 0.

https://codeforces.me/contest/2175/submission/352263703

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

The time limit is somewhat tight, but problem F can also be solved using FFT 352263995. The idea is you consider the colors in the Prufer sequence. You can figure out with what parity each color has to appear, and you get an EGF for the number of ways to choose which nodes appear for each # of times the color appears. Naively, you could have to do up to n convolutions of size n, which is too slow. However, you can batch these together by (#of nodes of a given color, mask) and do binary exponentiation, and since there can only be O(sqrt(n)) of these, we get an O(n^(1.5)log^2(n)) algorithm.

I am interested to see if this is hackable.

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

    My solution is basically same as yours, and I figured out a much faster way to deal with it. Suppose there are $$$c_i$$$ vertices with color $$$i$$$, then the EGF for the color is $$$\frac{e^{c_i x}+e^{-c_i x}}{2}$$$ if parity is 0 and $$$\frac{e^{c_i x}-e^{-c_i x}}{2}$$$ if parity is 1. Let $$$t \gets e^x$$$ and what we need to do is convolution of some $$$F(t)$$$'s with total size $$$O(n)$$$, which can be done in $$$O(n \log^2 n)$$$.

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

      Yeah I realized this as soon as I posted my comment, the way I did it was extremely dumb.

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

      Use Log and Exp for formal series, and analyze the complexity as $$$\sum n/i$$$, you can optimize it to $$$O(n \log n)$$$, non-NTT modulus is used so annoying any-modulus convolutions are required.

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

        as a big generating function fan !! I was waiting for n log n optimization, Kudos !!

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

    it seems hackable, but got Unexpected verdict

    maybe some testers used the same idea

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

Why "tutorial" not "editorial" and why russian bugaboo names?

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

For the Div2 D editorial.. isn't the time complexity for the naive solution supposed to be O(n*k*k) instead of O(n*k*k*k) ?

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

    I tried with O(n*k*k), it was wrong( testcase 4 in pretest 1 , it gave 18, answer was 19)

    then i moved to O(n*k^3) one, it is obviously too slow.

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

    mate, for the naive transitions, you will also iterate over b[i], which signifies how much of a[i] you want to use, which goes from 0 to k. So, three states for index, sum and maximum value and an iteration to choose from a[i].

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

Why only me is refusing about what's "$$$\mathbb{E}$$$" stands for?

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

Is there any simpler solution for div1C?

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

I don't think the proof in div1.c is rigorous enough. Actually that's what confused me. $$$(s_2+1)/2 \lt len$$$ might happen, right? If the intersecting part passes through the center, it is different.

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

    I got it. But it's quite tricky and counterintuitive as the possibility is independent , isn't it?

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

    I thought about the same thing. It will still work, but I think the proof has to be a little bit different. Can you please share your thought process?

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

Thanks to div.1 C for making me IM again. It's too hard to me.

»
10 months ago, hide # |
← Rev. 2  
Vote: I like it +60 Vote: I do not like it

F:

  • Given a degree sequence $$$g_{1...N}$$$ with $$$g_i \gt 0$$$ and $$$\sum g_i = 2(N-1)$$$, the number of trees is $$$(N-2)! / \prod (g_i-1)!$$$. This is sometimes known as the generalised Cayley's formula. We can split it into independent products for each colour.
  • If some colour corresponds to $$$K$$$ vertices and the sum of their degrees is $$$S$$$, the number of ways to assign their degrees is $$$\left(\sum_{g \gt 0} x^g / (g-1)!\right)^K [x^S] = x^K e^{Kx} [x^S]$$$.
  • Without parity constraints, the answer would simply be $$$(N-2)!$$$ times the coefficient of $$$x^{2N-2}$$$ of the product of $$$x^{K_i} e^{K_i x}$$$ over all groups. Note that $$$\sum K_i = N$$$ so we can throw away their product $$$x^N$$$ and update parity constraints to $$$mask_i \oplus (K_i\%2)$$$.
  • Now we just want to find the product of formal power series $$$\sum_{S: 2 | (S-mask_i)} e^{K_i x} [x^S] x^S$$$ over all groups $$$i$$$. It's well-known that each such series is $$$(e^{K_i x} + e^{-K_i x})/2$$$ if $$$mask_i$$$ is even and $$$(e^{K_i x} - e^{-K_i x})/2$$$ if $$$mask_i$$$ is odd.
  • We apply dynamic programming to express the product as $$$\sum_{j=-N}^N c_j e^{jx}$$$ in $$$O(N^2)$$$. The coefficient at $$$x^{2N-2-N}$$$ is $$$\sum_{j=-N}^N c_j j^{N-2} / (N-2)!$$$, calculated in $$$O(N \log N)$$$.
  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +16 Vote: I do not like it

    I think "the number of trees" in the first line is actually $$$(N-2)!/\prod (g_i-1)!$$$. A typo maybe :)

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

    I've also solved the problem in a similar way. Using some theory of exponential generating functions, it's not hard to see that the solution is the coefficient at $$$x^{N-2}$$$ of a product of some $$$\sinh$$$ and $$$\cosh$$$ functions. In particular, for each color whose parity is even (not the given parity, but parity including the number of vertices) and appears in $$$a$$$ vertices, we multiply by $$$\cosh(ax)$$$, and if it's odd, we multiply by $$$\sinh(ax)$$$.

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

Don't like to wait long for the editorials

»
10 months ago, hide # |
← Rev. 6  
Vote: I like it +81 Vote: I do not like it

Another take on problem F. There is a well-known bijection between these two objects:

  • Functions $$$f: [n] \to [n]$$$ ("endofunctions")
  • Permutations of labeled rooted trees

From formula perspective, we know that there are $$$n^n$$$ endofunctions, as we can pick $$$f(k)$$$ for each of $$$n$$$ values of $$$k$$$ in one of $$$n$$$ ways. Another way to count them, is to split $$$[n]$$$ into $$$n$$$ sets that represent predecessors of each $$$k$$$, i.e. values $$$i$$$ s.t. $$$f(i) = k$$$.

In generating functions, the number of such splits is $$$\left[\frac{x^n}{n!}\right] e^{nx}$$$, where the left $$$n$$$ means that the total size of the sets is $$$n$$$, and the right $$$n$$$ means that there are $$$n$$$ sets.

If we wanted to ensure total size is even, we would count them as $$$\left[\frac{x^n}{n!}\right] \cosh nx$$$, and for odd size as $$$\left[\frac{x^n}{n!}\right] \sinh nx$$$, as $$$\cosh x$$$ and $$$\sinh x$$$ are the even/odd parts of $$$e^x$$$ correspondingly.

Then, from endofunctions perspective, the degree of each $$$k$$$ is the size of the $$$k$$$-th set plus $$$1$$$. To map it back to regular trees, if $$$n \gt 1$$$, we can pick any two vertices $$$u \neq v$$$ and demand that $$$u$$$ and $$$v$$$ do not appear anywhere in predecessor lists, which would also mean that they have no successors. Doing it this way, we can think of the objects we count as a triple:

  • A tree rooted in $$$u$$$
  • A permutation $$$P$$$ of rooted trees with two "dangling" edges in each root
  • A tree rooted in $$$v$$$

There is a one-to-one correspondence between such triples and labeled trees on $$$n$$$ vertices, as we can arrange $$$u \to P \to v$$$ as the unique path from $$$u$$$ to $$$v$$$ in the tree. Now, accounting for $$$+1$$$ in the degree, for each vertex color we know how many vertices we need and what the total parity of their "predecessor sets" should be.

Let's say that there are $$$k$$$ colors that need even sum of predecessor set sizes, with vertex counts $$$a_1, \dots, a_k$$$, and $$$l$$$ colors that need odd sum, with vertex counts $$$b_1, \dots, b_l$$$. We can then arrange the bijection above into the following formula:

$$$ \left[\frac{x^{n-2}}{(n-2)!}\right] \prod\limits_{i=1}^k \cosh a_i x \prod\limits_{j=1}^l \sinh b_j x $$$

To compute it quickly, we may note that $$$\log P(kx) = \sum\limits_{i=1}^\infty k^i b_i x^i$$$, where $$$b_i$$$ are the coefficients of $$$\log P(x)$$$. As such, we can find $$$\log \cosh x$$$ and $$$\log \frac{\sinh x}{x}$$$ in $$$O(n \log n)$$$, and then the problem reduces to finding $$$A_t = \sum\limits_{i=1}^k a_i^t$$$ and $$$B_t = \sum\limits_{j=1}^l b_j^t$$$.

The latter can be done in $$$O(n \log^2 n)$$$ by computing $$$\log \prod\limits_{i=1}^k \frac{1}{1-a_i x}$$$, but also constraints allow to find it in $$$O(nm)$$$.

Apparently, you can also use $$$\cosh x = \frac{t+t^{-1}}{2}$$$ and $$$\sinh x = \frac{t-t^{-1}}{2}$$$ for $$$t = e^x$$$, and find the product as a polynomial in $$$t$$$ in $$$O(n \log n)$$$, as suggested by one of the comments above.

»
10 months ago, hide # |
← Rev. 2  
Vote: I like it +42 Vote: I do not like it

I came up with an alternative solution for Div1D: 352286058.

The first observation is that any graph on $$$n$$$ vertices and $$$n-1$$$ edges must have a connected component which is a tree. Proof sketch: There must exist a connected component with more vertices than edges, and any connected graph with more vertices than edges is a tree. (Note that this tree might be an isolated vertex.)

For the following arguments, let me assume for simplicity that all weights are distinct, and that the edges are sorted by weight.

So let $$$T$$$ be a tree in the optimal solution. Since we can replace the edges of $$$T$$$ with any spanning tree of $$$G[V(T)]$$$, $$$T$$$ must be the MST of $$$V(T)$$$. Furthermore, all edges between $$$V(T)$$$ and $$$V(G) \setminus V(T)$$$ must have weights larger than all weights in $$$T$$$, since otherwise, we could obtain a better solution by replacing an edge in $$$T$$$ with a lighter edge between $$$V(T)$$$ and $$$V(G) \setminus V(T)$$$ (to see that the better solution is still not a tree, observe that we do not break any cycles). In other words: If we execute Kruskal's algorithm on the input graph, we will produce $$$T$$$ at some point.

When we have such a candidate tree $$$T$$$, we now add any $$$n - 1 - |E(T)|$$$ edges not incident to any vertex in $$$T$$$. If $$$T$$$ does not span the entire graph, the produced solution will not be connected, so it will be a valid solution. Clearly, we want to choose the lightest edges possible.

To quickly find the total weight of these edges, we maintain for each component the set of all incident edges in a treap. With smaller-into-larger merging we can do this in total time $$$\mathrm O(m (\log n)^2)$$$. Then, we will choose some prefix of the edges not in the treap. We can represent this by a prefix of all edges, and a prefix of edges in the treap which is subtracted. All necessary computations can be done in time $$$\mathrm O(\log n)$$$ (see code for details, this is essentially a weird binary search).

The total runtime is $$$\mathrm O(m (\log n)^2)$$$. This passes in slightly under half timelimit.

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

    I like the idea, very neat! It is a pity that the implementation requires binary search on a treap, that doesn't sound easy. I wonder, if there exists another look on the problem, that allows to use the idea and implement it, say, in linear time. I see that treap is needed here, but don't feel like there is any specific reason for it to be present.

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

    This is the same as my solution, but instead of small-to-large merging, because those vertex sets are formed by merging, we can make the union-find tree and process the subsets in HLD order on this tree using a global data structure. So we get the same performance as small-to-large but we can have binary search on segment tree this way instead.

»
10 months ago, hide # |
← Rev. 3  
Vote: I like it +4 Vote: I do not like it

Why mine this div-2 D solution got tle : Submission
And this passes : Submission

i just stored dp[i][left] in a variable in accepted one. Is this related to cpu cache?

Also both have complexity $$$\mathcal{O}(k^4)$$$ . So i think both should tled as they are not intended to fit in time constraints.

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

hey I'm looking for a cp peer group to solve problems daily & discuss contests, if anyone is open then please inform me. thank you!

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

Div 2 B was a nightmare.
Even to generate an array with all XOR's of all subsegments non-zero was a nightmare.
Alternate solution:
0) Write a bruteforce and see the results on small n, cross fingers to see some pattern. This step os optional if you are smart enough, hehe :)
1) Take some power of 2 and put it in the middle of array, with intention to never use that power of 2 (never set the corresponding bit to 1) further. So, every subsegment which crosses that number will be for sure non-zero.
2) Solve recursively for left and right parts.
3) Now we have an array with XOR's of all subsegments non-zero. Shift elements from [l, r] to [l + 1, ...]. Thus making so that XOR(l, r) = 0 will not harm to subsegments which cross both l and r boundaries.
4) Fill [l, r] in a similar way, so all XOR's inside of [l, r] are non-zero.
5) Set a[r] = XOR(l, r — 1), so XOR(l, r) = 0 now.
6) Add some unused power of 2 to a[l] and a[r] (XOR(l, r) stays 0), thus no subsegment which crosses l or r boundary (bot not both) will be non-zero.
So, the main idea is put some big power of 2 as a separator and switch to smaller power of 2.
Probably this is also not easy enough for div2b, but just an alternative way.

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

    Actually, let bi be a1^a2^...^ai, it should be ok if you make bi = i(i!=r) and b_r=l, it took me quite long to solve it too.

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

    1) — 2) can actually be easily solved non-recursively: Notice the structure you are describing, if we always would choose the lowest power of 2 that haven't been used yet:

          1
    
      1   0   1
    
    1 0 1 0 1 0 1
    

    Compare it to the binary representation of the numbers 1 to n:

          1 1 1 1
    
      1 1 0 0 1 1
    
    1 0 1 0 1 0 1
    
    1 2 3 4 5 6 7
    

    we can see that for each index the value is just the lowest set bit. And we can get the lowest set bit easily with i & -i. So for 1) — 2) its enough to iterate from 1 to n and set the vals to i & -i.

    For the rest you are free to use the (unused high) bits 29 and 28. Also instead of shifting [l, r] to [l+1, ...] (?), I have simply add an additional unused power to a[r+1].

    PS: I don't know if I am allowed to post code solutions as comments. But in my solution it's just one loop with 3 lines of code

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

I got a method of O(nk^2), and have been checking it for hours, but it keeps getting WA on test 9, and I really can't find where I made a mistake. The way is to use dp[i][j] to record the happiness and max(bi) when you use j cards on first i friends, and assume that no friends coming later bring any card. Then use b[i][j] to calculate b[i+1][j], it turns out to get correct answers in most tests, but goes wrong on several specfic test points, I wonder where I made mistakes and how should I fixed it, my code is in my latest submission, I'd appreciate it if anyone can help me check my code.

»
10 months ago, hide # |
← Rev. 2  
Vote: I like it +11 Vote: I do not like it

I like div2D, but my $$$O(\sum k^4)$$$ solution(link) have accepted this problem, I wonder why hacks are disabled in this problem and why the tests aren't strong enough.

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

I don't really understand how the array generated in B is always valid can somebody explain?

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

    You can get the XOR of a range $$$(l, r)$$$ by doing: $$$b_r \oplus b_{l-1}$$$, since applying the same number twice reverses its effect in XOR. So, if $$$b_r$$$ is equal to the XOR of all $$$a_i$$$ up to $$$r$$$ and $$$b_{l-1}$$$ is equal to the ones up until $$$(l-1)$$$, then $$$b_r⊕b_{l-1}$$$ would "subtract" the XOR of numbers between $$$(1, l-1)$$$, leaving us with the range we wanted.

    If the problem only required the XOR of all pairs to be equal to 1, an array where all $$$b_i$$$ values are distinct would be the correct answer: the XOR of any range $$$(x, y)$$$ could be represented as $$$b_x⊕b_{y-1}$$$. The XOR of two distinct numbers $$$(b_x$$$ and $$$b_{y-1})$$$ can't be zero, which means all ranges give non-zero results.

    Now, if only one range $$$(l, r)$$$ needs to be zero, we can still make all $$$b_i$$$ values distinct with the exception of $$$b_r=b_{l-1}$$$. Since they are the same number, the XOR of the range $$$(l, r)$$$ will be equal to zero; but since they are different than all other $$$b_i$$$, any other $$$f(x, y)$$$ will be equal to 1. From what I get, it is not necessary to make $$$b_i=i$$$, that is merely the most convenient way to get a bunch of distinct numbers.

    Lastly, you can find the values of the original array you were supposed to generate through its prefix XOR. Prefix sum is built by: $$$b_i=b_{i-1}⊕a_i$$$. Which means $$$a_i=b_i⊕b_{i-1}$$$: All previous values removed from the XOR would give the original $$$a_i$$$. Every adjacent value is distinct, which means $$$a_i$$$ will never be equal to 0.

    Please correct if I have any mistakes. Hope this helps!

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

div2 B is too hard for me

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

In the "Input" of the statement of problem C, "The only line of each test case contains 3 integers $$$n$$$, $$$m$$$, and $$$r$$$",should $$$r$$$ actually be $$$p$$$?

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

Can anyone find why this solution is incorrect.Your text to link here... I know it might fail time limit, but what about correctness?

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

    you have written

    // dp[i][j][0] -> max happiness
    // dp[i][j][1] -> used cards

    is it opposite ?

    you have done ,which seems opposite

    `  // bi = 0`
    `                dp[i][j][0] = dp[i - 1][j][0] + j;`
    `                dp[i][j][1] = dp[i - 1][j][1]```
    

    what is j signifying here ?

    EDIT: sorry to bother , i understood your notations

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

352439329

for DIV2 -Problem D , can someone please point out my mistake in this code

its K^4 solution , it should give TLE, but it gives WA on TC 5 also.

dp[i][j][l] — > ith index ; j number of cards used up till i , including bi ; the max card , ie max b is l till now , including i

array aa is the modified array , where i am keeping the first non zero k elements , as the a[i]=0 elements won't affect the distribution , however they would influence the score calculation , so for that i have kept another array cnta, which works like follows

2 0 0 4 5 =a 2 4 5 =aa 3 1 1 =cnta so basically whatever max is calculated at 2 , is counted 3 times (for the two 0s ahead also )

EDIT ::: my doubt is cleared , thanks for reading

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

    Hey, can you please tell what was the mistake in your code. I too am facing same issue.

    Thank you:)

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

B. XOR Array | Codeforces Round 1069 (Div. 2) | EASY EXPLANATION | Varun

Youtube link

C. Needle in a Haystack | Codeforces Round 1069 (Div. 2 & Div. 1) | EASY EXPLANATION | Varun

Youtube link

Step by step, very easy explanation along with code.

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

D2E/D1C is a very nice problem. However, I think the proof at the end leaves some unhandled cases (or maybe I was unable to fully understand it). For what it is worth, here is a sketch for a another proof to show that for non-concentric substrings $$$S_1$$$ and $$$S_2$$$, we lose $$$|S_1 \cap S_2|$$$ degrees of freedom, which is an equivalent statement to what the editorial attempts to prove.

  1. For each string, group symmetric character (for the center of the strings with odd length, considered it to be a a separate group by itself).

  2. Each group (from both strings) will represent a vertex in a bipartite graph, where vertex A from $$$S_1$$$ is connected to point B in vertex from $$$S_2$$$ iff their groups share a character.

A couple of observations:

  1. No double edges: a group cannot be in both sides. Otherwise the strings are concentric.
  2. Each edge in the graph represents the shared character, and their number is exactly equal to $$$|S_1 \cap S_2|$$$.
  3. For each connected component of length $$$n$$$, we lose $$$n-1$$$ degrees of freedom.

To see why note $$$3$$$ is true, originally we had the freedom to give any group any character, but when they are connected, they have to have the same character. So difference in degrees of freedom is $$$n - 1$$$.

Now, the key claim is that this graph has no cycles. To see this, assume that a cycle exists $$$G_1, G_2, ...., G_n$$$, with $$$G_1$$$ belongs to the groups of $$$S_1$$$ and $$$G_2$$$ and $$$G_n$$$ belongs to those of $$$S_2$$$.

Assume, $$$G_1 = (a, b)$$$, $$$G_2 = (a, c)$$$, $$$G_n = (b, d)$$$, and $$$c_1, c_2$$$ represents the centers and $$$d_1, d_2$$$ represents the diameters of each string respectively.

This means $$$dist(a, c_1) = d_1$$$, $$$dist(b, c_1) = d_1$$$, $$$dist(a, c_2) = d_2$$$, $$$dist(c, c_2) = d_2$$$, $$$dist(b, c_2) = d_2$$$, $$$dist(d, c_2) = d_2$$$

But this means that $$$a$$$ and $$$b$$$ are equidistant from both $$$c_1$$$ and $$$c_2$$$. This cannot happen unless both strings are concentric, a contradiction.

Since the graph has no cycles, this means that the number of vertices (i.e. groups) of each components is $$$edges + 1$$$. So for each component, the number of degrees of freedom we lose = the number of edges in that component. Adding these up, gives the number of edges in the graph, which is $$$|S_1 \cap S_2|$$$.

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

what is the expected rating breakdown of the questions ?

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

In D1B, if total number of cards is k or less, then number of prefix Maxima is o(sqrtK) since sum of first n integer is o(n^2)

so isn't the complexity o(k^2)? even naive transition can pass o(k^3)

»
10 months ago, hide # |
← Rev. 4  
Vote: I like it -11 Vote: I do not like it

Hello Codeforces Admins(@KAN,@MikeMirzayanov), I am writing regarding my skipped submission "https://codeforces.me/contest/2175/submission/352219881" for the problem 2175D in the contest Codeforces round 1069 (Div2),beacuse of which whole contest was skipped. After reviewing the matching submissions , i think i have done "unintentional leakage", though i did not copy from others and one of two users "elon_fan" has committed that he has cheated. During the contest, i wrote my solution in online compiler OneCompiler. I was unaware that these platforms index code publicaly by default. I believe that this caused my code to be leaked and found by others, resulting in matches. I apologize for this oversight and violation of rules if any done by me. I will from now use local IDE that i have (Clion). I respectfully ask that you consider this explanation. I did not intend to cheat, but i accept responsibility for using an insecure tool.

»
10 months ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

To Codeforces Admin, I appeal the code coincidence notice for my submission (#352216291) of Problem 2175D. My solution is independent; similarity comes from problem constraints and standard algorithms, not plagiarism. The problem limits k≤360, forcing O(k²) DP + greedy—only feasible approach. All valid solutions must preprocess a (remove zeros/redundant) and update DP by valid a_i’s max count, leading to structural convergence. My code has unique details: 1-based array indexing, idx/lim arrays for preprocessing, i64 alias, span array for coverage, and personalized DP loop logic—reflecting my own coding habits. I wrote directly in the online editor without local drafts, but these details prove independent work. I respect fair competition and never plagiarize. Please recheck my submission and revoke the notice to avoid unfair account penalties. Thanks! jintuling Submission ID: #352216291

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

Upsolving div1D I found a linear-time solution that does not use any advanced data structures. Use a selection algorithm to partially sort the edges so that $$$e_{n-2},\cdots,e_{n+1}$$$ are the $$$(n-2)$$$-th to $$$(n+1)$$$-th smallest, and the remaining nodes are partitioned onto one side or the other. After checking the $$$\left\lbrace e_1,\cdots,e_{n-1}\right\rbrace$$$ and $$$\left\lbrace e_1,\cdots,e_{n-3},e_{n},e_{n+1}\right\rbrace$$$ special cases, find via DFS in $$$T=\left\lbrace e_1,\cdots,e_{n-1}\right\rbrace$$$ the path from $$$u$$$ to $$$v$$$ where $$$e_n=(u,v)$$$, and call this the "chain", noting that the chain makes a cycle with $$$e_n$$$. For any edge $$$e_i$$$ not in the chain, $$$T-e_i+e_n$$$ has a cycle, so check $$$w_T - w_i + w_n$$$; after this, we only need to look at chain edges, so we can forget about the non-chain edges. Map all vertices onto the chain, and precompute prefix/suffix max on the chain. Then for each remaining edge, we can find the max chain edge and check that sum.

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

in the solution of 2174E 'return f(mod * m, k — 1) * mod' the last statement of the python looks like wrong, lack of m

according to the discription "So, we can distinguish numbers up to mod⋅m⋅f(mod⋅m,k−1)" it should be 'return f(mod * m, k — 1) * mod * m'

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

problem 2174E, use this query tree to accept. if the number is larger than 71874, then it can be solved by CRT.

/* 33 / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ 4 2178 / \ / \ 2 8 / \ / /\ / \ / / \ / \ [1,3][4, 7]][8,32] / \ / \ 66 71874 / \ / \ [33, 65] \ [2178,71873][71874, 2e9] [66, 2177] */

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    Your code here...
       /*
                           33
                          /  \
                         /    \
                        /      \
                       /        \
                      /          \
                     /            \
                    /              \
                   /                \
                  /                  \
                 /                    \
                4                    2178
               / \                  /     \
              2   8                /       \
             /    /\              /         \
            /    /  \            /           \
         [1,3][4, 7]][8,32]     /             \
                               /               \
                              66              71874
                             /   \          /        \
                         [33, 65] \  [2178,71873][71874, 2e9]
                               [66, 2177]
       */
    
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Div1C2 editorial mentions "the number of pairs of non-concentric substrings with a total length of $$$s$$$", but doesn't describe the way to find this number. Seems not obvious to me. Tried googling and stuff. No convolutions are required for this, right?

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

Can anyone explain the precomputation part in Wishing Cards and give the code..

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

This B made my brain hurt