1日3ACしていて、解説PDFにサンプルコードがない物もあるので記事にしてみました。
他の方の参考になれば嬉しいと思います。
ABC 157
A - Duplex Printing
Python
N = int(input())
print(N//2+N%2)
B - Bingo
- 3*3の為、全探索でも間に合う
Python
A = [[0] * 3, [0] * 3, [0] * 3]
Field = [[False] * 3, [False] * 3]
for i in range(0, 3):
A1, A2, A3 = list(map(int, input().split()))
A[i][0] = A1
A[i][1] = A2
A[i][2] = A3
N = int(input())
B = [0] * N
for i in range(0, N):
B[i] = int(input())
for b in range(0, N):
for i in range(3):
for j in range(3):
if A[i][j] == B[b]:
Field[i][j] = True
Ans = False
for i in range(3):
field = True
for j in range(3):
if Field[i][j] == False:
field = False
if field==True:
Ans = True
break
else:
for i in range(3):
field = True
for j in range(3):
if Field[j][i] == False:
field = False
if field==True:
Ans = True
break
else:
if Field[0][0] and Field[1][1] and Field[2][2]:
Ans = True
if Field[0][2] and Field[1][1] and Field[2][0]:
Ans = True
if Ans:
print('Yes')
else:
print('No')
ABC 156
A - Beginner
Python
N, R = list(map(int, input().split()))
if N>=10:
print(R)
else:
print(R + 100*(10-N))
B - Digits
Python
N, K = list(map(int, input().split()))
res=0
while N > 0:
N = N // K
res+=1
print(res)
C - Rally
Python
N = int(input())
X = list(map(int, input().split()))
X.sort()
MAX = X[len(X)-1]
res=100000000
for i in range(MAX+1):
SUM=0
for j in range(len(X)):
SUM += (X[j] - i) ** 2
res = min(res, SU
M)
print(res)
ABC 155
A - Poor
Python
A = [0] * 10
B = list(map(int, input().split()))
for i in range(len(B)):
A[B[i]] += 1
for i in range(len(A)):
if A[i] == 2:
print('Yes')
break
else:
print('No')
B - Papers, Please
Python
N = int(input())
A = list(map(int, input().split()))
res = True
for i in range(N):
if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0):
res = False
break
if res:
print('APPROVED')
else:
print('DENIED')
C - Poll
Python
N = int(input())
A = {}
MAX = 0
for i in range(N):
s = input()
A[s] = A.get(s,0) + 1
MAX = max(MAX, A[s])
B = sorted(A.items())
for k, v in B:
if v == MAX:
print(k)
ABC 154
A - Remaining Balls
Python
red, blue = input().split()
red_num, blue_num = list(map(int, input().split()))
s = input()
if s == red:
red_num -= 1
elif s == blue:
blue_num -= 1
print(red_num + ' ' + blue_num)
B - I miss you... /
Python
import re
N = input()
N = re.sub(r'[A-z]', 'x', N)
print(N)
C - Distinct or Not
Python
N = int(input())
A = list(map(int, input().split()))
MAX = 0
A_map = {}
for i in range(N):
num = A[i]
A_map[num] = A_map.get(num,0) + 1
MAX = max(MAX, A_map[num])
if MAX>=2:
print('NO')
else:
print('YES')
ABC 153
A - Serval vs Monster
Python
H, A = list(map(int, input().split()))
count=0
while H>0:
H-=A
count+=1
print(count)
B - Common Raccoon vs Monster
Python
H, N = list(map(int, input().split()))
A = list(map(int, input().split()))
if H<=sum(A):
print('Yes')
else:
print('No')
C - Fennec vs Monster
Python
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
SUM = 0
for i in range(N - K):
SUM += A[i]
print(SUM)
D - Caracal vs Monster
Python
def dfs(h):
if h == 1:
return 1
else:
return dfs(h//2) * 2 + 1
H = int(input())
print(dfs(H))