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

Автор ninja_28, история, 4 года назад, По-английски

1498A - GCD Sum

Video Editorial

Author and Problemsetting: ninja_28
Editorialist: sigma_g

Hint
Hint 2
Hint 3
Solution
Corner cases
C++ solution
Python solution

1498B - Box Fitting

Video Editorial

Author and Editorialist: sigma_g
Problemsetting: ninja_28

Hint
Hint 2
Solution summary
Solution implementation
Another implementation
Proof of correctness - brief
Proof of correctness - elaborate
Alternate implementation with easier proof
Does this solution work when block widths are not a power of two?
C++ solution
Python solution
C++ solution - multiset
C++ solution for easier proof

1498C - Planar Reflections

Video Editorial

Author, Problemsetter and Editorialist: sigma_g

Hint 1
Solution idea
Solution details
Implementation details
Note
C++ solution
Python Iterative solution

1498D - Bananas in a Microwave

Video Editorial

Author: shash42
Problemsetting and Editorialist: sigma_g

Brute force solution
Optimizing the brute force: hint
Optimizing the brute force: hint 2
Optimizing the brute force: details
Optimized solution implementation
Common mistakes
C++ solution
Python solution

1498E - Two Houses

Author, Problemsetting and Editorialist: dixitgarg

Description
Hint1
Proof of unique topological sorting
Hint2
Proof
Hint3
C++ solution
Python solution

1498F - Christmas Game

Author: nikhil_c
Problemsetting and editorialist: sigma_g

How do we solve a standard Nim game on arrays?
How to solve tree nim game for one rooting if K = 1: classifying odd/even steps
How to solve tree nim game for one rooting if K = 1: how bad are even steps
Reducing tree nim game to linear array: the stair case nim
Extending to general K
Calculating the answer for all roots
C++ solution
Python solution
  • Проголосовать: нравится
  • +419
  • Проголосовать: не нравится

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

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

»
4 года назад, # |
  Проголосовать: нравится +176 Проголосовать: не нравится

Excellent problem set! Need more Div2 rounds like these.

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

Thanks for the lightning-fast and detailed editorial!

»
4 года назад, # |
  Проголосовать: нравится +79 Проголосовать: не нравится

One of the best editorials I've ever seen if it's not the best...Congratulations to all the team behind this round !

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

a SCC is a strongly connected component, but what is a compressed SCC?

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

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

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +475 Проголосовать: не нравится

E can be solved in $$$O(n\log n)$$$ with ZERO queries.

Consider sorting by in degree. For the $$$i$$$th point, one can tell whether it is the last point of a SCC by comparing $$$i(i-1)/2$$$ with the sum of in degree of the first $$$i$$$ points.

So one can find all SCCs just by iterating through the degree array. Thus finding the answer.

Implementation

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

    Now i'm curios -- did authors know about this solution?

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

    Thank you for letting us know! Our previous version of E was suffering from this issue (answering without asking queries). So, we had to change the question to ask for the pair of bi-reachable houses with maximum indegree difference, not just any pair of bi-reachable houses. However, we were not aware that this version also suffers from the same issue.

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

      Sorry, I'm curious why compare i * (i−1)/2 with the sum of in degree of the first i points can determine whether it is the last point of a SCC?

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

        When you process the very last node in an SCC, it means that all of the indegrees processed so far have been accounted for (no future node will ever have a directed edge towards a node at index $$$\le i$$$). So the sum of indegrees must be the same as the number of pairs processed so far, which is $$$\binom{i}{2} = i(i-1)/2$$$.

        Another way to think about this is to keep track of a count "how many of the indegrees I have processed so far are due to future nodes", and you know you are in the last node of an SCC when this count becomes zero. In fact, this is what dengyaotriangle does in the submission they linked.

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

    Yeah. I too had a feeling that it can be done with zero queries. But couldn't come up with this solution. :(

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

    Wonder why the problem setter didn't know this well-known conclusion. :)

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

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

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

for B why using map fails but using freq arr pass ? frq arr : 111405356

map: 111388954

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

    You are missing the reference (&) Check this. Basically, you are changing a copy of the value but not the actual value

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

Can C be solved using iterative dp?

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

    Obviously, 111382908 .

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

      Thanks.

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

      Can you Explain this please??

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

        dp[x][y]: Number of particles that bounce in the x-th plane with y ages passed from the beginning. So, if (y & 1) then all those are bouncing to the left, and to the right otherwise. It is not difficult to notice that if(y & 1)

        $$$dp[i][j] = dp[i-1][j-1] + dp[i-1][j-2] + ... dp[i-1][0]$$$

        that leads to

        $$$dp[i][j] = dp[i-1][j-1] + dp[i][j-1]$$$

        the other case is analogous. Finally, I need to add dp[i][j] to ans for all i < n && j <= k, those are the cases when those particles don't bounce.

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

          I've done it during contest using O(K) memory and it obviously runs in O(NK) time complexity.

          Implementation

          Indeed it is kind of messy, during the contest it took me 30 minutes to debug and find out why it doesn't work for inputs with N = 1 or K = 1. (It can probably be improved somehow, but for now I'll handle them as special cases).

          Basically what I'm doing here is keeping prefixes and suffixes, where:

          Prefix — number of generated items if we start at 1, 2 ... i-1, i, and shoot in the right direction.

          Suffix — number of generated items if we start at i, i + 1 ... n-1, n, and shoot in the left direction

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

    Almost anything that can be solved using recursive dp can in principle be solved using iterative dp also.

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

could you please help me?) this is my solution for problem C and i don't know what's wrong with it. thank you! 111401801

»
4 года назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

The problems were really interesting . Great Work !

»
4 года назад, # |
  Проголосовать: нравится +19 Проголосовать: не нравится

Beautiful editorial. I just loved the way they are explained step by step.

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

In E problem, why this submission passed and this submission failed. I added following condition before asking query in AC submission.

Spoiler

Why is swapping making difference?

»
4 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

I guess this is an easier proof for Problem E not requiring discussion of things like SCC and top-sort:

So the solution is: if there exists pair $$$(A, B)$$$ such that $$$k_{A} \geq k_{B}$$$, and we can go from $$$A$$$ to $$$B$$$ (assumption), then we can go from $$$B$$$ to $$$A$$$. We have to prove this.

Case 1: if the edge is from $$$B$$$ to $$$A$$$ : since we can go from $$$A$$$ to $$$B$$$ (assumption), and from this edge we can go from $$$B$$$ to $$$A$$$, so yes.

Case 2: the edge is from $$$A$$$ to $$$B$$$. Now consider all other vertices $$$C$$$. We claim that there exists a $$$C$$$ such that edges $$$(B, C)$$$ and $$$(C, A)$$$ exist.

Proof: we can think of indegrees as score. Currently we have discovered edge $$$A$$$ to $$$B$$$ so score is $$$0:1$$$. We want score of $$$A$$$ to be greater than that of $$$B$$$. Now if for each $$$C$$$, the only edge combination that favourably increases score of $$$A$$$ is $$$(B, C)$$$ and $$$(C, A)$$$. Hence proved.

Is there any mistake or lack of rigour in this proof?

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

    What if we don't find any pair (A, B) such that $$$K_A \ge K_B$$$ and we can go from A to B ?

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

      Haha do you see what you have written. If there don't exist such pairs then the answer is NONE of course lol. Cuz one of them has to be greater than the other. And you must find a bireachable pair. Lol.

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

    Your proof avoids using SCC and topo-sort by not proving the part that requires them at all. So I would say your proof is incomplete because your proof makes assumptions.

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

    It can also be done this way :

    First we remove all the nodes with indegree 0 or outdegree 0. (After removing a node, we would again need to check for it and keep removing such nodes).

    Now if we have two nodes, $$$A$$$ and $$$B$$$, $$$k_A >= k_B$$$ then I claim that we can go from $$$B$$$ to $$$A$$$ (Yes! without any other assumption).

    Number of nodes reachable from $$$B$$$ = $$$n - k_B$$$ and

    Number of nodes reachable to $$$A$$$ = $$$k_A + 1$$$

    If we can't reach from $$$B$$$ to $$$A$$$, total nodes would be $$$n + 1 + k_A - k_B > n$$$ , its not possible. So we can go from $$$B$$$ to $$$A$$$.

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

      I didn't require the assumption to prove that we can go from $$$B$$$ to $$$A$$$. I required it to prove that they form a bidirectional pair. I proved that we can go from $$$B$$$ to $$$A$$$ if $$$k_{A} \geq k_{B}$$$ and then using the assumption I proved bidirectional thing.

»
4 года назад, # |
Rev. 4   Проголосовать: нравится -9 Проголосовать: не нравится

Wonderfull editorial with clear explanations

»
4 года назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

why i can't hack after system testing?

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Nice Editorial it helps me so much for solving rest problems which i m not able to do... Thanks

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

In problem E, can anyone please tell why did I receive wrong answer on test 2, I just implemented the same thing using multiset, LINK.

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

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

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

I framed D in a slightly different way which might be more straightforward to you if you're so inclined.

Essentially, for each timestep, we want to solve a version of the coin-change DP problem where we have a finite number of coins all of the same value. We want to do this in O(m). If there were an unlimited number of the coin, this is just the coin-change DP problem, and you just iterate left-to-right, storing DP[i] as 1 if you can get there, 0 if you can't.

Since we only have a finite number of coins, we still iterate left-to-right, but instead of storing 1 or 0, we store in DP[i] the minimum number of coins used to reach that value.

To recap, iterate i from 0 to m. if DP[i] != -1 and DP[i] < y, then DP[f(i)] = DP[i] + 1. Where f(i) is applying the function (either addition or multiplication) once.

111392313

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

    Hi,

    Can you please explain this line, DP[targ] = max(DP[j]-1, DP[targ]);

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

      Oh yeah, sorry, that must be confusing.

      In my writeup I said to store in DP[i] the minimum number of coins we need to use to reach that value.

      In my code I actually store in DP[i] the maximum number of coins NOT used in order to reach that value. So if we call the value in my writeup k, then the value in my code is just y - k, and all the reachable DP[i] starts at y instead of 0.

      The reason I did it that is so that taking the max would automatically overwrite the existing DP[targ] if DP[targ] == -1, so I don't have to add the if DP[targ] == -1.

»
4 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

Finally i reached pupil after 16 contests (including this):)

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

C C can be done with $$$O(n)$$$ memory too!

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

    Love the comments from grey guys, giving improvements on C problems! Climb out of your hole first

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

      Show some respect.

      He is only helping and you are encouraging him to think that he can do above level question only when he will be at that level.

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

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

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Really quick and well explained editorial

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

can anyone tell whats wrong in my logic for part C

solve(n,k)=1 when n==0 or k==1

and

solve(n,k)=1+solve(0,k-1)+solve(1,k-1)+solve(2,k-1)............solve(n-1,k-1) when n>0&&k>1

my logic for solve(n,k) is as follows:

if present decay age is k and it passes through n planes then it will lead to new particles as follows

particle generated at plane 1 will now pass through no plane leading to increase in solution by solve(0,k-1)

particle generated at plane 2 will now pass through one plane leading to increase in solution by solve(1,k-1)

similarly particle generated at plane i will increase solution by solve(i-1,k-1).

so my formula comes out to be:

solve(n,k)=1+solve(0,k-1)+solve(1,k-1)+solve(2,k-1)............solve(n-1,k-1)

But my logic was giving wrong answer.

Can anyone tell whats wrong with the logic???

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

Problems similar to F have appeared before. Staircase nim itself is a common concept, and Move the Coins is a problem with K=1 with updates. Here's a more in-depth tutorial about staircase nim and this problem. This idea generalizes really easily as nodes with depths which have different residues mod k are independent (this isn't really mentioned in the editorial even though it's a pretty important fact).

»
4 года назад, # |
Rev. 5   Проголосовать: нравится +21 Проголосовать: не нравится

Solution for problem C with only 2 dimensions:

The idea

My full submission.

Few lines of Code

UPD: Of course this can be optimized to get rid of the second dimension since we only need the information from states with $$$age$$$ and $$$age - 1$$$, this improves our space complexity to $$$O(n)$$$, code.

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

    Fixed! :D

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

    Hey can you please explain the order of evaluation you used. I was looping through 'hits' first then 'age' like this:

    Code

    and got wrong answer and changed it and got correct answer. I am a bit confused.

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

      In this order sometimes you will use the value of the state $$$[n - hits][age - 1]$$$ while it has not been calculated yet.

      How can this happen?

      When $$$hits$$$ is small enough: $$$n - hits \gt hits$$$, and since you never reached any $$$dp[i][j]$$$ where $$$i \gt hits$$$ and any $$$j$$$ from $$$2$$$ to $$$k$$$ your code will use $$$dp[n - hits][age - 1]$$$ before it even gets calculated.

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

    Hey, As you have explained the reason for not changing the loop order below. I got that part but if we keep the order state above in your code.

    where n-hits > hits , we also need do[n-hits][age-1] to calculate dp[hits][age] which is not calculated yet.
    
    Could you please tell me what am I doing wrong here?
    
    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +6 Проголосовать: не нравится

      Notice that the state $$$[n - hits][age - 1]$$$ is calculated before state $$$[hits][age]$$$, because we had already calculated all the states $$$[i][age - 1]$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$.

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

    Great approach, the key here probably was to understand that the direction of the particle doesn't matter on the number of planks in front of it.

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

    Thanks for sharing

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

    Why Age is K only , I mean a particle can keep oscillating inside planes for longer period.

»
4 года назад, # |
  Проголосовать: нравится -14 Проголосовать: не нравится

what is complexcity of this code it should get tle

include <bits/stdc++.h>

using namespace std;

long long int gcd_sum(long long int num) { // returns gcd-sum long long int tmp = num, digitsum = 0;

while (tmp > 0) {
    digitsum += tmp % 10;
    tmp /= 10;
}

long long int gcd = __gcd(num, digitsum);
return gcd;

}

int main(void) { int t; cin >> t;

while (t--) {
    long long int n;
    cin >> n;
    if (gcd_sum(n) != 1) {
        cout << n << endl;
    } else if (gcd_sum(n + 1) != 1) {
        cout << n + 1 << endl;
    } else if (gcd_sum(n + 2) != 1) {
        cout << n + 2 << endl;
    }
}
return 0;

}

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

    It's $$$O(length(n))$$$. You can search for the Euclidean Algorithm for the time complexity of __gcd.

    For finding the sum of digits of n: $$$O(length(n))$$$.

    For finding the gcd: $$$O(\log length(n))$$$.

    The total complexity: $$$O(length(n) + \log length(n))$$$, and then it's $$$O(length(n))$$$.

    Here $$$length(n)$$$ is the number of digits in $$$n$$$.

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

E had 100 ACs in just the last 10 mins damn.

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Every editorial should be like this. Awesome job.

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

B was good this time it required more thinking than just straight implementation

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

deleted

»
4 года назад, # |
  Проголосовать: нравится +31 Проголосовать: не нравится

1498C - Planar Reflections can also be solved without using DP. Here is my solution 111412008 where i just traverse the given setup in ZigZag fashion.

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

    It is arguably still a DP solution, but this is a nice way to condense it to just N of memory.

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

      That's true, but You don't need a conventional 2/3 state Dynamic Programming approach to solve this is the point i was trying to make as the editorial clearly used that concept and it's not easy for a person to understand who doesn't know DP yet.

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

    that was the first intuition I got after drawing simulation

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

Solved problem 1498C - Planar Reflections using 2 states only. You don't need the 'direction' state or dimension if you observe the following.

Hitting the $$$i^{th}$$$ wall (/plane) in the opposite direction at any moment is equivalent to hitting $$$n-i+1^{th}$$$ wall in the forward direction at the same moment.

Thus the following short recursive DP function works perfectly, with calling the function with call(n, k)

ll call(int front, int k){
    // front = how many walls are in front.
    if(k == 1){
        return 1; // This particle itself, which is about to die
    }
    if(front == 0){
        return 1; // Again, this particle itself, which will go to infinity and beyond...
    }
    if(dp[front][k] != -1) return dp[front][k];
    ll ret = call(front - 1, k) + call(n - front, k - 1); // keep going forward + decay and turn back, aided with the observation mentioned above.
    if (ret >= modd) ret -= modd;
    return dp[front][k] = ret;
 
}

My submission 111384789

Also, looks like the spoilers get broken for comments (looks fine on the post). It would be nice if it gets fixed.

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Best editorial guys.. Keep up the good work

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

On problem E I proved my solution on a different approach.

Lemma: Let A and B be nodes such that $$$k[a] <= k[b]$$$. Then, $$$B$$$ is reachable from $$$A$$$.

Proof:

Case 1: (If there is a directed edge from $$$A$$$ to $$$B$$$.)

There is nothing more to be done.

Case 2: (If there is not a directed edge from $$$A$$$ to $$$B$$$.)

Let $$$X_i$$$ be the set of nodes such that there exists a directed edge from every element of $$$X_i$$$ to $$$I$$$. Also, let $$$Y_i$$$ be the set of nodes such that there exists a directed edge from $$$I$$$ to every element of $$$Y_i$$$. Let's prove that there is at least one node that belongs to $$$Y_a$$$ and $$$X_b$$$. We have:

$$$|Y_a| + |X_b| = (n \; - \; 1 - \; k[a]) \; + \; k[b] = \; n \; - \; 1 + \; (k[b] \; - \; k[a]) \;>\; n - 2$$$

Using Dirichlet Principle, as $$$B$$$ does not belong to $$$Y_a$$$ and $$$A$$$ does not belong to $$$X_b$$$, we have that there are n — 2 nodes and the sum of elements of $$$Y_a$$$ and $$$X_b$$$ is bigger than n — 2. So, they have an element in common. Then, let $$$X$$$ be this element. There is an edge from $$$A$$$ to $$$X$$$ and from $$$X$$$ to $$$B$$$. We have a path from $$$A$$$ to $$$B$$$, finishing our proof.

I used this and for every pair of nodes, verified if there is a path between $$$B$$$ and $$$A$$$ (assuming that $$$k[a] \; <= \; k[b]$$$).

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

    Nice proof! There's two things I would like to ask about:

    1. Why is the sum $$$|Y_a| + |X_b| \geq n - 2$$$ and not $$$\geq n - 1$$$? (given that $$$k[b] - k[a]$$$ could be at least $$$0$$$).

    2. On this line: "we have that there are n — 2 nodes and the sum of elements of $$$Y_a$$$ and $$$X_b$$$ is bigger than n — 2". Why can we say that it is bigger than $$$n - 2$$$? supposing the inequality you mentioned in 1. is $$$\geq n - 2$$$, would the statement be "bigger or equal to $$$n - 2$$$"? (or "bigger or equal to $$$n - 1$$$" if that's the correct right-hand side of the inequality). In such case, how can show that there'll be at least one element in common?

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

      Thanks!

      1: Actually the correct result was supposed to be:

      $$$|Y_a| \; + \; |X_b| \; = \; n \; - \; 1 \; + \; (k[b] \; - \; k[a]) \; >= \; n \; - \; 1 \; > \; n \; - \; 2$$$

      Because the lemma stated that $$$k[a] <= k[b]$$$. So, the sum of $$$Y_a$$$ and $$$X_b$$$ sizes is strictly bigger than $$$n - 2$$$. Sorry for that, my mistake.

      2: I will try to explain it a bit better. Because of the assumption of the case (If there is not a directed edge from $$$A$$$ to $$$B$$$), we have that $$$B$$$ does not belong to $$$Y_a$$$ and $$$A$$$ also does not belong to $$$Y_a$$$. Then, there are at most $$$n - 2$$$ different elements in $$$Y_a$$$. Similarly, there are at most $$$n - 2$$$ different elements in $$$X_b$$$.

      Suppose they have no elements in common. Then, we must have at least $$$|Y_a| \; + \; |X_b|$$$ different nodes other than $$$A$$$ and $$$B$$$. But, the graph has at most $$$n - 2$$$ nodes other than $$$A$$$ and $$$B$$$. Then, we get, from the above equation:

      $$$n - 2 < |Y_a| + |X_b| <= n - 2$$$

      By contradiction, they must have at least a common element.

      I hope that helps!

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Awesome editorial and problem set. Really appreciate the quick and neat editorials and videos. It shows how much effort you people put into this round. Congrats and keep up the good work.

»
4 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

Love this great problem set for Div2 and the detailed editorial!

»
4 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

we need more editorials like this on the platform

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

Can anyone please tell me why this solution 111375843 for problem B is wrong. I solved using 2 pointers. Thanks in advance :)

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

Very nice editorial!

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

My solution for C was correct, but my code crashed because I was exceeding stack limit on my pc. How can I increase stack size on windows? I'd seen a few blogs, nothing worked so far.

EDIT: It worked, if anyone needs help feel free to DM me.

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

How to solve the problem C in Python using recursion?

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

In problem C I made ll dp[1001][1001][2] then I wanted to write ll &ret = dp[i][j][d]; but accidentally I wrote ll &ret = dp[i][j][k]; it got Accepted but..

$$$d <= 1$$$

$$$k <= 1000$$$

so when I call ll &ret = dp[i][j][k]; it's like ll &ret = dp[1000][1000][1000]

when I put vector instead of the array I got RTE

Can anyone explain why ll &ret = dp[1000][1000][1000] didn't get RTE or MLE because it's large ($$$10^9$$$) and the array is ll dp[1001][1001][2] ?

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

Great Editorial! I love how there's hints for the solutions so that you can actually figure it out by yourself. There should be more editorials like this

»
4 года назад, # |
  Проголосовать: нравится +21 Проголосовать: не нравится

Personally, I think C Problem can be solved in linear space in a very concise and "clean" way:

Solution Idea

Forgive me if that picture is simply too ugly :(

We give special treatment to $$$n=1$$$ or $$$k=1$$$ cases, and in other cases, we start by an array of length $$$n$$$, initialized 1,0,0,...,0 and calculate the partial sum of that array each step, after every calculation we reverse the array and do the exact same thing, finally terminate after $$$k$$$ rounds.

so the time complexity of this solution is $$$\Theta(nk)$$$, as you can see in my contest submissions :D

Actually, we can prove that there always exists a recursion in shape of $$$a_i=\sum_{\Delta=1}^{n}c_{\Delta}a_{i-\Delta}$$$, in the angle of view which $$$n$$$ is designated and $$$k$$$ varies as a sequence, which can be easily calculated in $$$\Theta(n^3\log k)$$$ time and potentially be calculated in $$$\Theta(n\log n\log k)$$$ time using polynomials and other (highly non-trivial) tricks.

For those who are Chinese, I think there's a website and several problems about this.

Well, me myself isn't very good at maths and especially polynomials, additionally I'm learning literacy class now, so I don't really understand this...... QwQ

ALSO, DON'T EVER TRY TO USE double TO CALCULATE INTEGER AND FRACTION CEILINGS WHEN long long IS SUFFICIENT ENOUGH.

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

C can also solved by finding regularity.We can find how many copies will be produced by all the particles going in the same direction each time.And their sum is the answer.Sorry my English is so poor.

Code:111393762

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

omg i think this is one of the best editorials on this platform!

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

for Problem D, we only need one res array (res[i] == -1 means not visited), as in a 0-1 knapsack problem, instead of iterating from 0 to m, we iterate from m down to 0, therefore no need to keep two visited arrays.

check my code here: 111428128

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

for problem B i wrote the same multiset approach, but it faield on Pretset 2. Exactly same approach of multiset..

multisetst; for (int i = 1; i <= n; i++) { cin >> a[i]; st.insert(a[i]); // mp[a[i]]++; }

int leftover = k;
int ans = 1;
while (!st.empty()) {
    auto f = st.upper_bound(leftover);
    if (f == st.begin()) {
       leftover = k;
       ans++;
    }
    else {
       // if (f == st.end())
       f--;

       st.erase(st.find(*f));
       leftover -= *f;
       // db(*f, st.size(), leftover);
    }
}
cout << ans << endl;
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится
    Wrong
    Right
    Reason
    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      Though the reason stated by you doesn't apply..It was failing because of some constant global variable issue.Accessing afterwards deleting or before doesn;t creates issue until reference poitner is in memory.

      *f is in memory till end brace so we can access that anywhere till that

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

    PS: Reason given by Dush1729 is right

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

I really liked the contest specially problem E. I still haven’t read to tutorial but in my solution I didn’t use top-sort. First I proved for any two vertices in a tournament like a and b if the output degree of a is at least as big as the output degree of b, b is reachable from a. (The proof would be kinda long if I write but it isn’t so hard using induction and u need to know that each tournament graph has a king but it might have an easier solution. Still if u couldn’t and wanted the answer just comment it and I will explain) After this it’s easy. For every two vertices we will push back the difference between k of those in a vector and then sort it from big to small and we check the first which is possible. Here is my code if it will help( I used set though) 111401603

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

Tutorial is just awesome, need more div2 problems and tutorials like this.

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

In problem D , Making x long double and using x = x' /(1e5) with inbuilt ceil function is giving me Wrong Answer

However ,

Using x as long long and with the "incline ceil function" given in the editorial is getting accepted .

Can someone please help me out and explain why this is happening ?

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

    There might be precision issues with a fractional value of the multiplier. The integral ceil function in the editorial bypasses any such issues.

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

Actually during contest I did not read the question D properly (entirely my fault). I thought that for type 2 operation x can be between 1 and 10^5m instead of 10^5 to 10^5*m (x / 1e5 >= 1). Only reread at the end of contest (b4 7 minutes of contest end). Suppose x can be a fraction value as well for the type 2 operation. i.e. 1 <= x <= 10^5 * m. Is there a solution ?

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

Just consider the case when it's not that the block sizes for problem 2 are not in powers of 2 then can anyone think of a way to implement the DP solution?

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

Peace be upon you ! I really liked this contest and it's Editorial. Good job ! I'm waiting for more contests from you :)

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

Can someone please explain the scenario in

$$$E$$$

when there is no solution ? We have proven that the topological sort of the SCC is unique, and that the indegree of vertices in those SCC increases as we go from left to right in the topological sort enumeration, but is it always possible to topological sort this graph ?

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

    There is no solution when the input graph is acyclic.

    but is it always possible to topological sort this graph ?

    It is always possible to do a topological sort of the condensation graph because it is acyclic.

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

      Can you please share the reason the condensed graph is acyclic ?

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

        If some strongly connected components are in a cycle, they wouldn't be called strongly connected components because the entire cycle would make a (subset of a) single strongly connected component.

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

Great problemsetting and Excellent tutorial! Thanks to this round :)

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

From the editorial can anyone explain that in the ith timestamp why every unvisited node (upto i-1 th timestamp) is visited atmost once? Let's assume that the operation is t=1 and "no" is an unvisited node upto i-1 th timestamp.Then "no" can get visited from no-x,no-2*x,no-3*x.... (assuming all of them have been visited upto i-1th step). I am telling this according to the solution given in the editorial. Can anyone please tell me where I am wrong?

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

    According to the solution in the editorial, no (an unvisited node) will only be visited from its closest already visited node.

    The iteration starting from no-3x will stop at no-2x (since it's an already visited node). The iteration starting from no-2x will stop at no-x (since it's an already visited node). So, only the iteration starting from no-x will actually reach no.

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

I was stuck at problem D....

S;G fans only.
»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Help needed in Problem C !
When a particle of decay age $$$k$$$ hits the $$$n^{th}$$$ plane, it produces a particle with decay age $$$k-1$$$ directed towards the $$${(n-1)}^{th}$$$ plane (if it exists), which on hitting the $$${(n-1)}^{th}$$$ plane produces a particle of decay age $$$k-2$$$ (if $$$k>2$$$) directed towards the $$$n^{th}$$$ plane, this goes on until the decay age of the produced particles is greater than $$$1$$$.
How the solution in the editorial is able to count such particles with decay age $$$k-2$$$ & the consequently produced particles when a particle of decay age $$$k$$$ hits the $$$n^{th}$$$ plane?

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

    So basically in dp transition step we are summing up the dp[curr+1][k][dir] and dp[curr-1][k-1][1-dir] here:

    if (curr < n)
      ans += solve(curr + 1, k, dir) — 1;
    
    ans %= mod;
    
    if (curr > 1)
       ans += solve(curr — 1, k — 1, 1 — dir) — 1;
    
    ans %= mod;
    

    These two dp states will take care of particles you are talking about because a dp state of n,k,dir indicates the total number of particles (at the end of the simulation) when one particle of decay age k hits the n-th plane in the direction d.

    P.S: If still not clear I would recommend to watch video editorial for this problem where we have clearly explained about how to think of dp states.

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

Thanks for the wonderful solution!

Realllllly fast!

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

I got WA on D because I used ceil() instead of dividing integers :(

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

I think in D it is written to stop when we get first visited[ind]=1; But I think that is not required at all. We can do only 1 operation and stop. Maintain one num array as the minimum operation required to reach this point at this timestamp. Now suppose we want to do one operation if(num[ind]+1<=y) then only we can do this operation and update the next num and visited nxt as true.

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

    Yes you are right!. We found given implementation more cleaner so mentioned that in the editorial.

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

    Additionally, in the editorial, I wanted to highlight the subtle difference between the TLE and the accepted solution, that is why I did not cover this approach.

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

Can anybody explain problem F a bit more? I understood everything related to staircase NIM but now we have the problem of finding for each node the xorsum of values at nodes that have $$$d' = d/k$$$ odd. How can we do that an maintain the answers for all roots?

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

    Do you find any resources to explain it. I have the same question with you. :<D

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

    Hey, I have figured out this problem.

    Let's define f[u][i] is a state that root is 1, and the deep is i that value ralated to Hey, I have figured this problem.

    It is a type of root-changed(I am not sure about this word) DP.

    Whatever xD

    Let's define f[u][i] is a state that root is 1, and we just think about some nodes in the subtree of u and the distance with node u remainder by (2*K) equal to i. The value of f[u][i] is function of sg.

    dp[u][i] is a state that root is u, and we just think about some nodes distance with node u remainder by(2*k) equal to i. The value of dp[u][i] is function of sg.

    ——————— Firstly, we can calculate f[u][i] in this transfer equation as follows. The time complexity is O(n*k). Define u is the father of v

    f[u][i] ^= f[v][i-1];

    Obviously, dp[1] = f[1].

    Secondly, if we just think about the relationship between u(father of v) and v. We can find the value is about:

    dp[v][i] = f[v][i] ^ dp[u][i-1] ^ f[v][i-2];

    We also can calculate them by dfs. The time complexity is O(n*k).

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

Some solutions which passed system cases are now getting WA on E on later added test cases. So isn't this matter of luck for people who submit wrong codes and got accepted? It happened to me twice in recent contests :( (Didn't code my logic, thinking it to get WA, but another guy submitted it and passed system tests and failing on later added test cases but still getting the points)

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

Seems like there is a little typo in the C++ solution of D(in the ceiling function) which is causing compilation error.

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

    Sorry about it! This seems to be a common issue across multiple editorials, for example, the editorial of problem C here.

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

One of the best editorials I have seen off late. Great work!

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

What are odd steps and even steps in problem F ?

UPD : Understood after reading this blog

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

In planar reflections problem, can any one tell why ans was initialized to two in recursive c++ approach?

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

Problem C can be much more simple. It can simply be solved using 2-state dp. dp(i, j) implies the total number of particles generated if a particle is needed to pass i sheets with current age j. As the opposite direction is symmetric the simple reccurence comes out to be dp(i,j) = dp(i — 1, j) + dp(n — i, j — 1); (n — i bcz if there are i sheets needed to be crossed rightwards there will be n — i sheets for the newly born particle in opp. direction to be crossed).

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

I think we don't need binary search in Alternate implementation with easier proof of B(Box Fitting), It is sufficient to find least height required for every suffix of Ci and required height will be maximum of all possible least heights. here is the Solution.

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

    Binary search is used to reduce time complexity to O(nlogn).

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

      At first with Binary Search, Time Complexity was O(n+log(Wmax)log(n)). now if we don't do Binary search, then it will be O(n+log(Wmax)). Please observe carefully, I am talking about Editorial Section containing Alternate implementation with easier proof in problem B (Box fitting).

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

Unfortunately the Python solution to problem E has been uphacked: https://codeforces.me/contest/1498/submission/111571072

It TLEs with 125000 write/flush?

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

    It has not been uphacked. Test 29 was already in systests. We need to submit the code with Python 3. AC submission. Though, I am not sure why PyPy3 and Python 3 give different I/O rates.

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

Here's a sort of "meta-solution" I came up with for problem E. It's not really rigorous, but it is simple :)

First, remove all vertices that cannot be in the answer by repeatedly removing all vertices whose indegree is n-1 (and update n after that).

Now, consider a pair of vertices A and B, whose indegree difference is ID. Now, if you decide to query a pair of vertices C and D whose indegree difference is less than ID, there is a risk that A and B are the answer, since if there exists at least one graph that matches the input, and in this graph A and B are mutually reachable, you cannot ignore the possibility that this graph is in fact the graph that is given. So in a sense, we are forced to query the pair of vertices whose indegree difference is ID before we can query a pair of vertices whose indegree difference is less than ID. And, if we are forced to query it, and the answer is "Yes", we don't have any other option than to output this pair as the answer, since we don't have any other candidates.

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

Can someone explain to me please why am I getting the wrong answer in D if I use this operation function instead of theirs?

auto operation = [&] (long long &curr, double mx) {
     if (t == 1) {
          curr = curr + (int)ceil(mx);
     } else {
         curr = ceil((double)curr * mx);
     }
};
where ceil is standard cpp function and mx = x[i]/1e5.

Any kind of help is highly appreciated.

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

    There might be precision issues with a fractional value of the multiplier. The integral ceil function in the editorial does not mess around with fractions, and is thus guaranteed to always give the correct ceil.

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

I have a problem in B here . I used multiset and did quite same but still got TLE . (the only difference in my approach is I used lower_bound instead of upper_bound) .. can anyone tell me why its happening like this? i am posting the link to my code here https://codeforces.me/contest/1498/submission/112199870 thanks in advanced !!

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

    can anyone help me in figuiring out why its giving TLE? problem B i used multiset and lower_bound

    temp=0;
            out=1;
            auto it = s1.end();it--;
            temp+=(*it);
            s1.erase(it);
            while(s1.empty()==0)
            {                        
                if( (temp + *(s1.begin())) > W)
                {
                    temp=0;
                    out++;
                    it = s1.end();it--;
                    temp+=(*it);s1.erase(it);
                    continue;
                }
                it=s1.lower_bound(W-temp);
                if(it==s1.end())
                {
                    it--;
                    temp+=(*it);
                    s1.erase(it);
                    continue;
                }
                if((*it)<=W-temp)
                {
                    temp+=(*it);
                    s1.erase(it);
                }
            }
            cout<<out<<"\n";
    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится -8 Проголосовать: не нравится

      why downvoting my comment ? i really faced this issue but its sorted now :)

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

Author solution in Python for Task D does not meet Time Limit. :(

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

    It does. All the solutions we have posted in the editorial are verified on Polygon. You have to submit this code in PyPy3.

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

Best Editorial I have ever seen! Keep it up!

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

Applied multi-source BFS for D problem, not working :(. Wrong answer on testcase 12. Would appreciate if anyone points out where it is going wrong. 113828973

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
Your code here...
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double lld;
typedef priority_queue <lli , vector<lli>, greater<lli> > min_heap;
typedef priority_queue <lli> max_heap;
const lli M = 1e9 + 7;
#define FOR(i,l,u) for(lli i=l;i<=u;i++)
  
lli  count(lli i,lli j,lli d,lli n)
{
    if(i==n+1||i==0||j==1)
       return 1;
    else
    {
        if(d==1)
           return (count(i+1,j,d,n)+count(i-1,j-1,1-d,n))%M;
        else
           return (count(i-1,j,d,n)+count(i+1,j-1,1-d,n))%M;
    }
}
void solve()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    lli t;cin>>t;
    while(t--)
    {
        lli n,k;cin>>n>>k;
        cout<<count(1,k,1,n)<<"\n";
    }
    
}
int main()
{
    solve();
}

why am i getting TLE?

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

The editorial is excellently framed

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

The solution given in the editorial is giving runtime error in my local machine for the tc -> (500 250). A possible reason for this could be the limit of stack size (I am not sure about this). I am using windows os with GCC compiler. Does anyone face the same issue? Or any advice on what should I do?

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

    Yes!! I am also looking solution for this problem!! Please tell me if you can fix it!

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

    If you're worried about the correctness of the code depending on the runtime environment, my suggestion is to run the code in Codeforces customtest (https://codeforces.me/problemset/customtest ), where the editorial code indeed works fine.

    Although I do not use Windows, I can guess that stack size should not be an issue because the solution is iterative (not recursive).

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

In Div-2 problem C, My code is not giving output in codeblocks! But it got accepted .. Can anyone tell me how I can fix this? My code link

picture link, if not visible ....

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

    Hi, the code that you have shown is not the same as the code in the editorial. Editorial Python code is written iteratively, but your linked code is recursive.

»
4 года назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

It's the best editorial I have even seen.

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

Why am i getting wrong output? I have used the exact same logic as mentioned in editorial.

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

amazing problemset and set of well structured editorials , just awesome work guys