The D problem worked (although it's poorly implemented). However, I made a mistake in the corner case due to the B and C problems and issued 3WA, so I would like to reflect on it and make use of it next time.
Just find the area.
answerA.py
a=input()
b=input()
h=input()
print((int(a)+int(b))*int(h)//2)
You just have to do a simulation. Accurately grasp what kind of state it is in the while statement. Here, consider who the turn is and which alphabet card the person has.
answerB.py
s=[input() for i in range(3)]
l=[len(s[i]) for i in range(3)]
abc=[0,0,0]
now=0
while abc[now]!=l[now]:
s_sub=s[now][abc[now]]
abc[now]+=1
now=(0 if s_sub=="a" else 1 if s_sub=="b" else 2)
print("A" if now==0 else "B" if now==1 else "C")
When the length of the character string is l, + can be entered in l-1 places, and since ** l is small enough, all $ 2 ^ {l-1} $ patterns ** can be considered. Masu (bit full search). Therefore, after that, consider addition in a state where the place where + enters is known. Here, looking at the character strings of numbers in order from the front, when + falls between the i-th and i + 1-th characters, consider the addition of the numbers on the left and the numbers on the right, and + is the i-th character. If it does not fit between the i + 1 characters, consider the number on the left side and the sum of the numbers on the right side as a ** character string .
Therefore, write a bit full search, look between the numbers in order, and if + is entered in the jth (j = 0 → l-2), the number string (subst) saved at that time is an integer. In addition to ans_sub (don't forget to set the j + 1th number to subst), if + is not entered in the jth (j = 0 → l-2), add it to subst as a character string. , The code looks like this: ( bit I'm wondering whether to judge whether it is 1 in the full search code as `(i >> j) & 1``` or
`(1 << j) & i```. I want to unify ... **)
As I noticed later, if you put + in between and split at the end based on +, the amount of code you write will decrease.
answerC.py
s=input()
l=len(s)
ans=0
for i in range(2**(l-1)):
ans_sub=0
subst=s[0]
for j in range(l-1):
if (i>>j)&1:
ans_sub+=int(subst)
subst=s[j+1]
else:
subst+=s[j+1]
if j==l-2:
ans_sub+=int(subst)
ans+=ans_sub
if l==1:
print(int(s))
else:
print(ans)
At first, I felt that I should check all the squares, but since it is O (HW), I can't make it in time. Here, if you pay attention to the number of squares to be filled, it is 10 ^ 5 or less, so if you focus on ** filling **, you can see that you can write a program. Here, when you fill a certain square, you can see that the square is included in the board of $ 3 \ times 3 $ centered on the adjacent squares. Therefore, the adjacent squares (of which the squares that make the board of $ 3 \ times 3 $) are saved, and the squares that are included in the board of $ 3 \ times 3 $ centered on that square appear. You can update it every time you come. Also, since it is impossible to save all the coordinates of the center in terms of spatial complexity **, I try to save only the coordinates that appear in the dictionary (all the squares that do not appear even once () (It can be the center) The number of squares $ (h-2) \ times (w-2) $ can be subtracted from the coordinates.)
answerD.py
h,w,n=map(int,input().split())
d=dict()
def change(a,b):
global h,w,d
if 1<=a<h-1 and 1<=b<w-1:
if (a,b) in d:
d[(a,b)]+=1
else:
d[(a,b)]=1
for i in range(n):
a,b=map(int,input().split())
a-=1
b-=1
for j in range(3):
for k in range(3):
change(a+j-1,b+k-1)
ans=[0]*10
ans[0]=(h-2)*(w-2)
for i in d:
ans[d[i]]+=1
ans[0]-=1
for i in range(10):
print(ans[i])
Recommended Posts