Clarification Needed on xi + yi == s Condition in CF 2120B Editorial

Revision en1, by ahnaf09, 2025-08-14 17:07:02

Hey everyone, salam! I’m trying to understand a line from the editorial for 2120B - Square Pool.

Here’s the part of the code:

for (int i = 0; i < n; i++) {
    cin >> dxi >> dyi >> xi >> yi;
    if (dxi == dyi) ans += (xi == yi);
    else ans += (xi + yi == s);
}

I understand the first ifif dxi == dyi, the ball is moving along the main diagonal. If xi == yi, it’s already on that diagonal, so it will go straight to the pocket.

But I’m a bit confused about the second part:

else ans += (xi + yi == s);

Why are we checking xi + yi == s here? Is this because it represents the other diagonal of the square? And is it correct that collisions don’t affect this count because balls just swap directions, so the number heading to pockets stays the same?

Thanks in advance for the help! Really appreciate it :)\

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English ahnaf09 2025-08-14 17:11:05 6 Tiny change: 'the first `if` — `if dxi' -> 'the first **if** — `if dxi'
en2 English ahnaf09 2025-08-14 17:07:19 3 Tiny change: 'ate it :)\\n' -> 'ate it :)\n'
en1 English ahnaf09 2025-08-14 17:07:02 954 Initial revision (published)