ABC147 - Atcoder/Python精進のための解説メモ
2022/12/27
ABC147 - A.Blackjack
AtCoder公式 | ABC147 - A.Blackjack解答
a, b, c = map(int, input().split())
if a + b + c >= 22:
print('bust')
else:
print('win')
要点解説メモ
- シンプルにやるだけ
ABC147 - B.Palindrome-philia
AtCoder公式 | ABC147 - B.Palindrome-philia解答
s = input()
ans = 0
for i in range(len(s)):
if s[i] != s[-i - 1]:
ans += 1
print(int(ans / 2))
要点解説メモ
- 奇数時の分岐が面倒なので、ひっくり返した文字列とすべて比較して最後に半分にする
ABC147 - C.HonestOrUnkind2
AtCoder公式 | ABC147 - C.HonestOrUnkind2解答
n = int(input())
xyxy = [[] for _ in range(n)]
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
xyxy[i].append((x - 1, y))
ans = 0
for i in range(1 << n):
is_ok = True
cnt = 0
for j in range(n):
if (i >> j & 1) == 0:
continue
cnt += 1
for x, y in xyxy[j]:
if (i >> x & 1) != y:
is_ok = False
if is_ok:
ans = max(ans, cnt)
print(ans)
要点解説メモ
- Nがたかだか15なので、正直者or不親切な人のパターンを全探索する
ABC147 - D.
AtCoder公式 | ABC147 - D.解答
まだ解いていません