A. Registration
Of new id
ABC167a.py
a=input()
b=input()
s=len(a)
if b[:s]!=a:
print("No")
else:
print("Yes")
B. Easy linear programming If $ k $ is less than $ a $, choose $ k $ cards for $ a $. If $ k $ is less than $ a + b $, the sum of the cards is $ a $. Otherwise the sum of the cards is $ a- (k- (a + b))) $
ABC167b.py
a,b,c,k=map(int,input().split())
if k<=a:
print(k)
elif k<=a+b:
print(a)
else:
print(a-(k-(a+b)))
C. Skill up It was AC 5 minutes after the contest deadline. I'm sorry. Since $ N <12 $, you can search all the bits and update the lowest price that meets the conditions.
ABC167c.py
n,m,x=map(int,input().split())
l=[]
for i in range(n):
a=list(map(int,input().split()))
l.append(a)
ans=99999999
for i in range(2 ** n):
bag = []
for j in range(n): #bit full search
if ((i >> j) & 1):
bag.append(l[j])
skill=[0]*m
enough=[0]*m #Determine if each skill exceeds x
money=0
for sub in bag:
money+=sub[0]
for kk in range(1,m+1):
skill[kk-1]+=sub[kk]
if skill[kk-1]>=x:
enough[kk-1]+=1
if 0 not in enough: #Calculate price if all skills exceed x
if ans>money:
ans=money#Update if below the minimum price
if ans==99999999: #If there is no change from the initial value-Output 1 otherwise, lowest price
print(-1)
else:
print(ans)
D. Teleporter All telepods go to some city, so you'll rush into the loop within $ N $ at most. For example, $ 1 => 3 => 4 => 1 ... $ in Example 1, $ 1> = 6 => 2 => 5 => 3 => 2 ... $ in Example 2. Assuming that the number of teleports before entering the loop is $ t1 $ and the number of teleports per loop after entering the loop is $ t2 $, the position immediately before the last teleport is $ (k-t1) mod. It will be t2 $. All you have to do is output the destination of that location. There are many lines and the code is dirty, so there may be a more efficient solution.
ABC167d.py
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[1]
di={}
di[1]=1
for i in a:
b=a[l[-1]-1]
if b in di:
x=b
break
l.append(b)
di[b]=1
t1=0
for j in l:
if j==x:
break
else:
t1+=1
t2=len(l)-t1
if k<=t1:
print(l[k])
else:
aa=(k-t1)%t2
print(l[t1+aa])
In addition, I ran out of time until D. Next week ...
Recommended Posts