https://atcoder.jp/contests/abc157
n = int(input())
ans = n//2 + 1 if n % 2 else n//2
print(ans)
The output was classified according to whether n was even or odd. Submission https://atcoder.jp/contests/abc157/submissions/10518520 Reference: Ternary operator (Python)
B
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
mark = [[False, False, False] for _ in range(3)]
for i in range(3):
for j in range(3):
if a[i][j] in b:mark[i][j] = True
ans = 'No'
for i in range(3):
if all(mark[i]):
ans = 'Yes'
break
for j in range(3):
if mark[0][j] and mark[1][j] and mark[2][j]:
ans = 'Yes'
break
if (mark[0][0] and mark[1][1] and mark[2][2]) or (mark[0][2] and mark[1][1] and mark[2][0]): ans = 'Yes'
print(ans)
I made a two-dimensional list mark
that shows whether or not it was marked, and marked it as True
.
(If you mark while receiving the input, you don't need the list ʻa` to store the input.)
After that, check if horizontal bingo, vertical bingo, and diagonal bingo are established.
Submission https://atcoder.jp/contests/abc157/submissions/10444407
C
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = float('inf')
k = 0
if n == 2: k = 10
elif n == 3: k = 100
for i in range(k, 1000):
flg = True
for s, c in sc:
if list(str(i))[s-1] == str(c): continue
flg = False
if flg:
ans = i
break
if ans == float('inf'): ans = -1
print(ans)
Since N and M are small, I tried all the numbers in the range from the smaller one, and if there was a corresponding one, I exited the loop and output.
Submission: https://atcoder.jp/contests/abc157/submissions/10518841
I would like to add it if I can AC.
Recommended Posts