Past questions solved for the first time
It is regrettable that I can only solve the C problem in the last two times. I want to be able to solve the problems of light blue and blue difficulty.
As it is
answerA.py
a,b,c=map(int,input().split())
if b-a==c-b:
print("YES")
else:
print("NO")
It's OK if you change the output by chance
answerB.py
o=input()
lo=len(o)
e=input()
le=len(e)
for i in range(lo+le):
if i%2==0:
print(o[i//2],end="")
else:
print(e[i//2],end="")
print()
Since it is necessary to make it in lexicographic order in the end, create an array of alphabets first, find out how many each there are, and output them together at the end. Also, since we count common things, we need to take min, so we need to be careful there as well. It's very convenient because you can intuitively operate Python and character strings.
answerC.py
alp=[chr(i) for i in range(97, 97+26)]
inf=10000000
check=[inf]*26
n=int(input())
for i in range(n):
s=input()
ls=len(s)
check_sub=[0]*26
for j in range(ls):
#print(s[j])
check_sub[alp.index(s[j])]+=1
for k in range(26):
check[k]=min(check[k],check_sub[k])
#print(check_sub)
ans=""
for i in range(26):
#print(check[i])
ans+=check[i]*alp[i]
print(ans)
It was a problem that could be solved in a little while, but I missed it due to a misunderstanding. (I didn't realize that ** if there is no mistake in the code, there is a mistake in my consideration ** ...) Below, I would like to put what I wrote on paper as my own consideration. Also, commenting out in the code is a code based on your own mistakes.
** I made a mistake in the basics of counting **, which counts all possible things without duplication. From now on, I want to tell my heart not to make a mistake in this basic.
answerD.py
mod=1000000007
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
xc=0
for i in range(1,n):
a=x[i]-x[i-1]
l=min(i,n-i)
#xc+=a*(l*n-((l*l+l)//2))
xc+=a*(l*(n-l))
xc%=mod
yc=0
for i in range(1,m):
a=y[i]-y[i-1]
l=min(i,m-i)
#yc+=a*(l*m-((l*l+l)//2))
yc+=a*(l*(m-l))
yc%=mod
print((xc*yc)%mod)
Recommended Posts