ABC143 - Atcoder/Python精進のための解説メモ
2022/12/27
ABC143 - A.Curtain
AtCoder公式 | ABC143 - A.Curtain解答
a, b = map(int, input().split())
print(a - b * 2 if a > b * 2 else 0)
要点解説メモ
- シンプルにやる
ABC143 - B.TAKOYAKI FESTIVAL 2019
AtCoder公式 | ABC143 - B.TAKOYAKI FESTIVAL 2019解答
n = int(input())
d = list(map(int, input().split()))
ctn = 0
for i in range(n):
for j in range(i + 1, n):
ctn += d[i] * d[j]
print(ctn)
要点解説メモ
- シンプルにやる
ABC143 - C.Slimes
AtCoder公式 | ABC143 - C.Slimes解答
from itertools import groupby
def run_length_encode(s: str) -> "List[tuple(str, int)]":
grouped = groupby(s)
res = []
for k, v in grouped:
res.append((k, int(len(list(v)))))
return res
n = int(input())
print(len(run_length_encode(input())))
別解
n = int(input())
s = input()
ans = n
for i in range(1, n):
if s[i - 1] != s[i]:
continue
ans -= 1
print(ans)
要点解説メモ
- ランレングス圧縮というやつ
- 前から1つずつ比較して、隣り合う文字が違う個数を数えても間に合う
ABC143 - D.
AtCoder公式 | ABC143 - D.解答
まだ解いていません