Last time I thought I shouldn't write because there is AGC today, but I couldn't solve a single question, so I'll write it. Recently, I get tired because AGC-A is also recommended.
#12 Problem 1WA. Problems that I participated in but could not solve
** Thoughts ** The first thing to think about is when $ B-A $ is even, and when it is even, $ \ frac {B-A} {2} $ is fine. The problem is when $ B-A $ is odd. When $ B-A $ is odd, no matter how close they are, they cannot be on the same table. So either one has to go to 1 or N to adjust the evenness. Of course, the closer to 1 and N, the less the number of times it takes to get to the same table, so find which is closer with $ min (a-1, n-b) $. The reason for a-1 is that the numbers on the table start from 1. When you go to 1 and N, +1 and $ B-A-1 $ become even numbers to adjust the evenness, so you can do $ \ frac {B-A-1} {2} $.
n, a, b = map(int,input().split())
d = b - a
if d % 2 == 0:
print(d//2)
else:
print(min(a-1,n-b)+1+(b-a-1)//2)
Judgment of oddness is made by if, and the rest is calculated as described above.
AGC-A is difficult. Tomorrow's ABC will aim for A ~ C's three finishes for the time being !! see you. good night.
Recommended Posts