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

Автор awoo, история, 2 года назад, По-русски

2004A - Closest Point

Идея: BledDest

Разбор
Решение (BledDest)

2004B - Game with Doors

Идея: BledDest

Разбор
Решение (Neon)

2004C - Splitting Items

Идея: BledDest

Разбор
Решение (adedalic)

2004D - Colored Portals

Идея: BledDest

Разбор
Решение (Neon)

2004E - Not a Nim Problem

Идея: BledDest

Разбор
Решение (BledDest)

2004F - Make a Palindrome

Идея: BledDest

Разбор
Решение (Neon)

2004G - Substring Compression

Идея: BledDest

Разбор
Решение (awoo)
  • Проголосовать: нравится
  • +64
  • Проголосовать: не нравится

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

finally it is released.!!!

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

In D, also you can use bellman-ford after construct a graph: 276620074

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

The implementation / logic of F makes me feel I am the dumbest man on planet.

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

    Same, it is very unintuitive for me how you can just add the cumsums; This implementation makes a lot more sense to me: 276838911

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

      I like this kind of solution. This solution is completely different from author's solution.

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

      Can someone please explain this marked solution? How is looking at the difference in the prefix sums giving the answer? The ranges (i,j) with same Prefix sums can be completely disjointed after all

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

        What do you mean by disjoint? Lets denote the first range as $$$i_0$$$-$$$j_0$$$ and the second one as $$$i_1$$$-$$$j_1$$$. We can only account for $$$i_0 \lt i_1$$$, Also we can say $$$j_0 \lt j_1$$$ because other ways the second range will always have smaller sum than the first.

        This means that the first range always describes a prefix and the second one a suffix, that have a unique start and end point. Now it is just counted how often they are the same.

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

can someone explain to me what is wrong with my solution of problem C : 276692116

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

Здравствуйте, в разборе задачи D опечатка.

X < Z < Y

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

Hello ..

Can anyone tell me that for problem D , why this solution is giving wrong answer https://codeforces.me/contest/2004/submission/276820238 or can anyone suggest some test cases where this failed

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

В разборе задачи B ошибка — сказано, что в отрезке пересечения min(R,r)-max(L,l)-1 дверей, на самом деле их min(R,r)-max(L,l).

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

finally the text editorial is here, still waiting for rating recalculation :(

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

can anyone tell why this solution for problem D is giving tle ?

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

why did problem E get so much hate and backlash ? the problem is actually really nice and high quality even tho there were 10+ videos that leaked the solution first hour which had nearly 5k views combined that doesnt take from the quality of the problem i honestly found it really interesting and gives a new way of approaching problems atleast for me

»
2 года назад, скрыть # |
Rev. 10  
Проголосовать: нравится +9 Проголосовать: не нравится

In the editorial for problem F, it is written that: "It can be shown that it doesn't matter which of these actions we take".

Please mention in the editorial how it can be shown. I have an intuition for this, but I don't have a rigorous proof.

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

    i dont get this part aswell if u understand it please explain it below here

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

    A rigorous proof would be something like that:

    Consider the prefix sums of an array, and denote $$$s$$$ as the sum of all elements in it. An array of positive integers is palindromic if and only if its prefix sums are "symmetric" with $$$\frac{s}{2}$$$ as the center (i.e. if an integer $$$\frac{s}{2} + x$$$ exists in the array of prefix sums, then the integer $$$\frac{s}{2} - x$$$ should also exist, and vice versa). If there is a pair $$$(\frac{s}{2}-x, \frac{s}{2}+x)$$$ such that only one of these elements exists in prefix sums, this pair violates the condition, and we need to "fix" every such pair.

    Now consider what our actions do to the array of prefix sums. When we merge two adjacent elements, we delete a prefix sum. When we split an element, we add a new prefix sum between the existing two. Every such action can "fix" one of the violating pairs $$$(\frac{s}{2}-x, \frac{s}{2}+x)$$$: merging two elements deletes one element from a pair, and splitting an element adds an element into the pair. So, if we have a pair that violates the condition, it doesn't matter whether we fix it by split operation or merge operation — we will still spend one operation to fix this pair.

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

    I think a rigorous proof might also go like this:

    Given the array $$$b[1\cdots n]$$$ after doing the minimum number of operations to make it a palindrome.
    While possible, pick any element $$$b_i$$$ that was obtained by a split operation, and do the following:

    $$$ \textbf{Case 1:} \text{ if } i \gt \left\lceil \frac{n}{2} \right\rceil \text{or } i \lt \left\lfloor \frac{n}{2} \right\rfloor \text{, undo the split operation in any possible direction, and fuse } b_{n - i + 1}$$$
    $$$\text{in the opposite direction that } b_i \text{ got unsplit towards.This increases the number of operations by at most 0.} $$$

    $$$ \textbf{Case 2:} \text{ if } i = \left\lceil \frac{n}{2} \right\rceil \text{or } i = \left\lfloor \frac{n}{2} \right\rfloor \text{, do the same as case 1 but if the direction of unsplit of } b_i \text{ is towards } b_{n - i + 1}$$$
    $$$\text{don't do anything after the unsplitting step. This also increases the number of operations by at most 0.} $$$

    $$$ \textbf{Case 3:} \text{ if } i = \frac{n}{2} \text{, unsplit } b_i \text{ and fuse the result in the opposite direction.} $$$

    Note: when you fuse two elements $$$b_i$$$ and $$$b_j$$$, the state of the resulting element is the union of the split directions of $$$b_i$$$
    minus the direction $$$b_i \rightarrow b_j$$$ and the split directions of $$$b_j$$$ minus the direction $$$b_j \rightarrow b_i$$$.

    This process has to end because in each iteration you decrease the number of split elements by at least 1.

    A similar argument can be constructed to convert all fuse operations to split operations.

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

Any idea why this submission for Problem D is going TLE? As per my understanding, the time complexity for this should be O(q * 6 * logn) which should be within limits I guess. Thanks in advance!

https://codeforces.me/contest/2004/submission/276826924

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

    Ok I see, issue was with 1., deep copying of vector. 2. Solves it. So dumb, it was going to be the first time I solved a D in div 2!!

    1.vector<int> nodes = colorToNodes[all_colors[j]];

    2. vector<int>& nodes = colorToNodes[all_colors[j]];

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

I thought of applying dfs for D but will it give tle?

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

Idk how the B task was for you guys. But for me, as a beginner, it's very tricky.

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

Hello ...

https://codeforces.me/contest/2004/problem/D

Could anyone tell why this is giving TLE for Problem D and how could i improve .

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

    In this line

    set<int> temp=m[s];
    

    you're copying a whole set which maximum size can be $$$2 \cdot 10^5$$$. Potentially this copy can be done for each query (again $$$2 \cdot 10^5$$$) and moreover a function solve() is called 8 times for every query.

    If you really need this temporary variable, you can use a const reference:

    const set<int>& temp=m[s];
    
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I always skip problem C. Every contest, If I can not come up with solution as soon as I read problem C then I used to skip it. Then I would solve the next problem D. Educational Codeforces Round 169 is one example. I skipped D, then solved E. And in the EPIC Institute of Technology Round August 2024 (Div. 1 + Div. 2), I skipped C, then solved E. After contest, I was disappointed that I did not solve C. Could anyone explain me about this? I can not sure the reason.

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

For G, how do you get the digit you placed in the last odd block if in your transition you put a dummy state c=0? Thanks!

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

so slow

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

Idiot me, who wrote 500 lines of code in D :] 276672729

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

Can someone please tell what am i missing in this D problem :- 276639203. This got WA .

But this got AC :- 276654708

Could you please tell what is the difference

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

Can some1 please help me understand why this won't work for prob C??

https://codeforces.me/contest/2004/submission/276886399

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

Can anyone explain editorial of e , i read it many times still i didn't get approach , i understand concept of nim problem because there are alot of editorial are exists already but i'm not getting approach of this problem can anyone explain please ??? thanks

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

F. Can you tell me in more detail what what the line means: ans -= (s % 2 == 1 || !binary_search(p.begin(), p.end(), s / 2)); As far as I understand, this is a check for a palindrome of odd length. But why there are two checks here is not quite clear.

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

In problem E tutorial's induction proof, author writes "if x is a composite prime number", this should be corrected to "if x is an odd composite number".

Great explanation otherwise :)

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

https://codeforces.me/contest/2004/submission/276672351

this solution is O(n+q) but still gave TLE just because I was using python

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

I had some trouble grasping that the solution for F actually worked (going in increasing order through sizes of segments) because I thought you could end up counting disjoint segments. But all the elements being non-negative makes that impossible, that is, all arrays with equal p[l] + p[r] are one inside of the other.

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

Good problems!

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

please help me with this 277073432 it will be very helpful

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

Nevermind, All this time in problem F, I thought we're asked to form a "PERMUTATION" NOT PALINDROME

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

277159203 help me with the solution

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

I'm very curious why my code with primitive array in java 8 should get timelimit in 21 tests int a []. But the same code with Integer a[] should pass all tests and should be accepted the same logic. Can someone explain me why is that in java solutions.

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

I tried all source shortest path (Floyd-Warshall) in D and apparently got tle. There have been many problems that I tried to solve with the algorithm yet failed again and again at the time limit. Can anyone tell me better approach to solve problems like these? (and also if there is a faster variant of the algorithm)

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

    It will TLE. There is no cutting corner around Floyd-Warshall that would help you, the algorithm is doing its best (sort of, this is excluding any research paper improving it to an extreme, but as far as I understand, this cannot have a better complexity than quadratic).

    D is more of an exercise to practice implicit graph. That is, you know what you are solving is a graph, but it has special attributes that you should take advantages of instead of blindly jumping into a regular graph algorithm just because you deduce "shortest path" from the problem statements.

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

Why algorithm described in solution for F problem is optimal? function f(l, r) is defined as minimum operations required to make a palindrome from a[l..r]. there's no proof in solution. can you explain it plz BledDest?

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

In the tutorial for problem E (Not a Nim Problem), the last paragraph says "if x is a composite prime number...", is this probably a typo? I think it would be correct to write "if x is an odd composite number..."

upd: I saw such a comment with such content, I apologize

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
If z < x < y
ans = (y - z) + (x - z) = (x + y) - 2* z
Considering z = (x - a)
ans = (x + y) - 2 * (x - a)
    = x + y - 2x + 2a
    = y - x + 2a.  eq(1)
If x < y < z
ans = (z - y) + (z - x) = 2z - (x + y)
Considering z = (y + a)
ans = 2 * (y + a) - (x + y)
    = 2y + 2a - x - y
    = y - x + 2a   eq(2)

From eq(1) and eq(2) it is clear that z can be either close to x or close to y and it should not matter. I don't understand how is D being solved.

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

Hey guys, I don't know why my solution for C got TLE. Can anyone tell me where it went wrong? Thank you ^^

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

Did anyone try to solve D with using BFS?

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

dang the theory behind $$$E$$$ is really cool

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

Can someone please tell me why the submission 344412256 fails but the submission 344413243 passes? The only difference between both are that in the second one I run the sieve from $$$j = i$$$ instead of $$$j = i * i$$$ like the first one.