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 :)








Auto comment: topic has been updated by ahnaf09 (previous revision, new revision, compare).
Auto comment: topic has been updated by ahnaf09 (previous revision, new revision, compare).
1) Yes, we are checking direction, parallel diagonal, from left-up corner to right-down corner, and we want the ball is staying exactly on this diagonal, that's why we are checking x+y==s
2) Collisions don't affect, because we can assume, that collisions aren't happening, and balls fly through each other, in this scenario trajectories will be the same (you can check pictures in the problem to see it)