Atcoder ABC167 A-D in Python

A. Registration Of new id|S|-1Output Yes if the characters are the same, otherwise output No

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

Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Daily AtCoder # 36 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Solve ABC169 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python