I solved it together with ABC088 that I will give at the same time. It's actually 70 minutes, but I was happy because I was able to solve the two contests in 120 minutes in total, and I was able to solve it at the last minute. I was able to come up with the D problem because it was much more than a puzzle and was similar to the AGC problem I had solved before.
I took a little time thinking that the unlimited ride ticket could not be cheaper than the regular ticket.
answerA1.py
a,b,c,d=[int(input()) for i in range(4)]
print(min(a,b)+min(c,d))
Instead of counting one by one, we will determine if the participants are eating chocolate each day. Since we eat $ 1, A_i + 1,2 A_i + 1,… $, we should judge whether the remainder when divided by $ A_i $ is 1 day, but only when A_i is 1, the remainder becomes 0. Therefore, you need to be careful.
answerB.py
n=int(input())
d,x=map(int,input().split())
a=[int(input()) for i in range(n)]
ans=0
for i in range(1,d+1):
for j in range(n):
if a[j]==1:
ans+=(i%a[j]==0)
else:
ans+=(i%a[j]==1)
print(ans+x)
I didn't notice it during the contest, but it's easy to think of adding $ A_0 = 0 $ and $ A_ {n + 1} = 0 $ to the inputs $ A_1, A_2,…, A_n $ **. Here, since each tourist spot is canceled one by one, I thought that it would be better to consider the difference when one tourist spot was canceled from the total amount of money in the original trip.
At this time, if the sum of visiting all the tourist spots in order is S, the following formula can be established.
Furthermore, if you do not visit the i-th tourist spot from here, the total amount of money at that time will be the difference, considering the difference.
answerC.py
n=int(input())
a=list(map(int,input().split()))
base=0
for i in range(n+1):
if i==0:
base+=abs(a[0])
elif i==n:
base+=abs(a[n-1])
else:
base+=abs(a[i]-a[i-1])
ans=[]
for i in range(n):
if i==0:
ans.append(base+abs(a[1])-abs(a[0])-abs(a[1]-a[0]))
elif i==n-1:
ans.append(base+abs(a[n-2])-abs(a[n-1])-abs(a[n-2]-a[n-1]))
else:
ans.append(base+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1]))
for i in range(n):
print(ans[i])
answerC_better.py
n=int(input())
a=list(map(int,input().split()))
b=[0]
b.extend(a)
b.append(0)
a=b
base=0
for i in range(n+1):
base+=abs(a[i+1]-a[i])
ans=[]
for i in range(1,n+1):
ans.append(base+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1]))
for i in range(n):
print(ans[i])
Since one is output, there is only ** to find the one that is convenient for you **. This kind of problem often comes up at AGC, but if you don't clarify what you want to do, you're likely to enter a labyrinth. First, in this problem, there were two variables, A and B, so I tried to set either A or B to 0. However, ** if one is 0, the rest will be connected **, so I thought it would be better if there was no difference between A and B. Therefore, in order to eliminate the difference between A and B, I decided to divide it into ** small structures that can freely adjust the difference **. Furthermore, at this time, I thought that it would be easier to create a grid that was convenient for me if I ** made the grid as wide as possible and made one connected component as small as possible. The first thing that came to my mind was a combination of the following minimum structures.
I tried to make a structure that satisfies A and B by ** combining the above structures so that the reverse patterns are adjacent to each other, but it didn't work. However, when the same pattern was combined while experimenting with this structure, it became as follows. In the case of this pattern, the white connecting component is 0 to 50over and the black connecting component is 1, so I thought it would be very easy to adjust. (The reverse pattern is 0 to 50 over for the black connected component and 1 for the white connected component)
In the above pattern, there is a little waste of black in the part where the small structures overlap, so ** reduced waste and improved ** is the structure below.
Here, let's set the height of the above structure to 100 and the width to 50, and connect the reverse patterns. Then, for the above structure, the white connected component is 0 to 25 * 50 and the black connected component is 1, and in the reverse pattern structure, the white connected component is 1 and the black connected component is 0 to 25 * 50. I will. Therefore, when connected, the white connected component is 1 to 25 * 50 and the black connected component is 1 to 25 * 50. Therefore, if 1 <= A <= 500 and the limit of 1 <= B <= 500, a grid can be created by this method.
answerD.py
a,b=map(int,input().split())
print("100 100")
a-=1
b-=1
for i in range(100):
if i%2==0:
print("."*50+"#"*50)
else:
for j in range(50):
if j%2==0 or j==49:
print(".",end="")
else:
if b>0:
print("#",end="")
b-=1
else:
print(".",end="")
for j in range(50):
if j%2==0 or j==49:
print("#",end="")
else:
if a>0:
print(".",end="")
a-=1
else:
print("#",end="")
print("")
Recommended Posts