AtCoder Beginner Contest 047 Review of past questions

Time required

スクリーンショット 2020-02-27 18.45.04.png

Impressions

It's too easy and it feels strange. After all, the level of ABC these days is too high ...

Problem A

Whether you can add small ones to make a big one

answerA.py


x=list(map(int,input().split()))
x.sort()
if x[0]+x[1]==x[2]:
    print("Yes")
else:
    print("No")

B problem

To find the area of the rectangle, it is sufficient to know the x, y coordinates in the lower left and the x, y coordinates in the upper right, and since the rectangle narrows from the given information, it is sufficient to classify the cases based on the value of a. Also, a2-a1 and a4-a3 can be-respectively, but in that case a rectangle cannot be created, so it must be set to 0.

answerB.py


w,h,n=map(int,input().split())
a1,a2,a3,a4=0,w,0,h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        a1=max(a1,x)
    elif a==2:
        a2=min(a2,x)
    elif a==3:
        a3=max(a3,y)
    else:
        a4=min(a4,y)
print(max(a2-a1,0)*max(a4-a3,0))

C problem

Since it can be seen that one continuous color section is inverted by one operation, it can be seen that the number of sections is reduced by one by this operation. Therefore, since it is sufficient to repeat this operation to make all into one section, the number of sections-1 is the number of stones to be obtained. In addition, the number of intervals can be easily obtained by using a self-made group by function.

answerC.py


def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

s=groupby(input())
print(len(s)-1)

D problem

Since the problem statement is very long, I thought it was a difficult problem, but nothing was difficult and I missed the beat. (It took me a long time to get ready. ** I want to get used to the long sentences! **)

First of all, since you have 0 apples at the beginning and buy and sell with a total of T apples, you can see that if you buy and sell T // 2 apples together in the city where the difference in amount is maximum, the profit will be maximum. I will. Therefore, ** what you want to find is the city group (i, j) ** that maximizes the difference in amount. If you move both of the town groups here, the amount of calculation will increase, so I paid attention to ** of the two towns, which sells apples **. At this time, the city i where you should buy apples is uniquely determined. This is because apples are the cheapest of the cities 1 to j-1. Also, at this time, if the apple is looking for the cheapest city among the cities 1 to j-1 for each city j, the calculation amount is 0 ($ n ^ 2 $) and it is not in time, so ** cumulative sum The minimum of adjacent objects is calculated ** ("minimum in town 1 ~ j" is equal to "minimum in town 1 ~ j-1 and minimum between town j"). Therefore, you can reduce the profit by lowering or raising the price of one apple (only one yen) for the group of cities where the difference in the amount of money is the largest, so ** Count the number of groups of such cities. It's good ** (Since the price of apples is different in each city, you can simply count the number of pairs. If you have apples of the same price, you can reduce the profit at a lower cost, but it depends on the restrictions There are no apples of the same price in the city.)

answerD.py


n,t=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*n
x[0]=a[0]
for i in range(1,n):
    x[i]=min(x[i-1],a[i])
d=dict()
for i in range(1,n):
    y=a[i]-x[i-1]
    if y>0:
        if y in d:
            d[y]+=1
        else:
            d[y]=1
d=list(d.items())
d.sort(reverse=True)
print(d[0][1])

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