0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC380をPythonで(A~D)

Posted at

AtCoder Beginner Contest 380の解答等の速報的まとめ

A問題

並び替えた時が1,2,2,3,3,3と一致すればいい

A
print("Yes" if sorted(input()) == ["1","2","2","3","3","3"] else "No")

B問題

| が入るたびにカウントをリセットして数えていく

B
ans = []
for i in input():
    if i == "|":
        ans.append(0)
    else:
        ans[-1] += 1

print(*ans[:-1])

C問題

座標圧縮の要領で$01$の個数をまとめて$K$番目の$1$がどこかを間違えないように値を調整すればいい

C
n, k = map(int, input().split())
s = input()

lst = []
last = -1
for s_i in s:
    if last != s_i:
        lst.append(0)
    lst[-1] += 1
    last = s_i

if s[0] == "0":
    target = 2 * k - 1
else:
    target = 2 * k - 2

lst[target - 2] += lst[target]
lst[target] = 0

now = s[0]
ans = []
for l_i in lst:
    ans.append(str(now) * l_i)
    now = "0" if now == "1" else "1"

print("".join(ans))

D問題

$K_i$の値で何回目の$S$の何番目かは容易に求められる
これで$x$番目の$S$が大文字小文字をスワップさせているか求められればいい

これはbitの一番上を消した値がスワップさているか否かの真偽反転させているものと一致する
(今思うに、bitの立っている数の偶奇で求められそう)

D
def is_swap_case(x):
    if x == 0:
        return False
    elif x == 1:
        return True
    t = is_swap_case(x & ~(1 << (x.bit_length() - 1)))
    return t ^ True


s = input()
q = int(input())
k = list(map(lambda x:int(x) - 1, input().split()))

for k_i in k:
    turn, ind = k_i // len(s), k_i % len(s)
    if is_swap_case(turn):
        print(s[ind].swapcase(), end = " ")
    else:
        print(s[ind], end = " ")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?