AtCoder Beginner Contest 109 Review of past questions

Time required

スクリーンショット 2020-04-26 9.25.40.png

Impressions

I'm glad that the old problem has good performance, but I'm good at it, so I'd like to tighten my mind. I'm not good at DP, so I'd like to take measures against DP soon (I think there was something like a DP contest).

Problem A

Find out if $ A \ times B $ is odd or even.

answerA.py


a,b=map(int,input().split())
print("Yes" if (a*b)%2==1 else "No")

B problem

It takes the strings as input in sequence and checks in order whether the first letter matches the end of the previous word. Also, store the character string in set and check if there is any cover.

answerB.py


n=int(input())
now=input()
s=set()
s.add(now)
for i in range(n-1):
    now2=input()
    if now[-1]!=now2[0]:
        print("No")
        break
    now=now2
    s.add(now)
else:
    if len(s)==n:
        print("Yes")
    else:
        print("No")

C problem

You can only move y → y + D, y-D, and since you are at coordinate X at the beginning, you can only visit coordinates where the distance from X is a multiple of D. Since we only need to consider the largest number in D, the greatest common divisor is the solution when considering the distance from the X coordinate of the coordinates $ x_1, x_2,…, x_n $.

answerC.py


from fractions import gcd
n,X=map(int,input().split())
x=list(map(int,input().split()))
ans=abs(X-x[0])
for i in range(1,n):
    ans=gcd(abs(X-x[i]),ans)
print(ans)

D problem

First of all, it is difficult to make the number of coins even number for each square because you can move one coin for each square ** there are only even or odd number **. I found that there is no **. Therefore, I thought of an operation that allows you to make an even number of coins for all the squares **. Then, when paying attention to each line, I found that such an operation seems to be possible by checking the evenness of the number of coins in each square from the left end to the right end. In other words, if the number of coins in the square you are checking is odd, move one coin to the right, and if it is even, do not move it. This allows you to ** an even number of coins for every row, except for the rightmost square. Furthermore, you can maximize the number of squares with an even number of coins by moving the coins from top to bottom for the rightmost square (that is, the rightmost W column). Also, you cannot move coins in the (H, W) squares, but if the total number of coins on all the squares is odd, you can only make the number of coins in that square an odd number. On the contrary, if the total number of coins is even, the number of coins in the (H, W) squares will also be even, so the number of squares with even coins can be maximized. I understand.

✳︎ The last output was 1WA as an array. Don't neglect ** Check the output format **.

answerD.py


h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            a[i][j]-=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h):
    if a[i][w-1]%2==1:
        if i!=h-1:
            a[i+1][w-1]+=1
            a[i][w-1]-=1
            ans.append([i+1,w,i+2,w])
l=len(ans)
print(l)
for i in range(l):
    print(" ".join(map(str,ans[i])))

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 070 Review of past questions
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 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 056 Review of past questions
AtCoder Beginner Contest 087 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 060 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 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 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 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 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 120 Review of past questions
AtCoder Beginner Contest 108 Review of past questions
AtCoder Beginner Contest 106 Review of past questions
AtCoder Beginner Contest 125 Review of past questions