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 if — if 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 :)\




