[PYTHON] AtCoder Beginner Contest 092 Review of past questions

Time required

スクリーンショット 2020-04-01 12.30.16.png

Impressions

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.

Problem A

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

B problem

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)

C problem

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. スクリーンショット 2020-04-01 13.22.35.png 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.S-|A_i-A_{i-1}|-|A_{i+1}-A_i|+|A_{i+1}-A_{i-1}|Will be. If you think about this with i = 1 ~ n, you can find the answer.

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

D problem

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.

IMG_0155.JPG

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)

IMG_0156.JPG

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.

IMG_0157.JPG

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

AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 072 Review of past questions
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 062 Review of past questions
AtCoder Beginner Contest 113 Review of past questions
AtCoder Beginner Contest 074 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 127 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 054 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 117 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 076 Review of past questions
AtCoder Beginner Contest 089 Review of past questions
AtCoder Beginner Contest 069 Review of past questions
AtCoder Beginner Contest 079 Review of past questions
AtCoder Beginner Contest 067 Review of past questions
AtCoder Beginner Contest 093 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 123 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 078 Review of past questions
AtCoder Beginner Contest 081 Review of past questions
AtCoder Beginner Contest 047 Review of past questions
AtCoder Beginner Contest 060 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 126 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 059 Review of past questions
AtCoder Beginner Contest 044 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 048 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 088 Review of past questions
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions
AtCoder Beginner Contest 107 Review of past questions
AtCoder Beginner Contest 071 Review of past questions
AtCoder Beginner Contest 064 Review of past questions
AtCoder Beginner Contest 082 Review of past questions
AtCoder Beginner Contest 084 Review of past questions
AtCoder Beginner Contest 068 Review of past questions
AtCoder Beginner Contest 058 Review of past questions
AtCoder Beginner Contest 043 Review of past questions
AtCoder Beginner Contest 098 Review of past questions
AtCoder Beginner Contest 114 Review of past questions
AtCoder Beginner Contest 045 Review of past questions
AtCoder Beginner Contest 120 Review of past questions