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?

ABC449をPythonで

0
Posted at

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

A問題

公式通り計算

A
from math import pi
print((int(input()) / 2) ** 2 * pi)

B問題

問題文通りシミュレーション

B
h, w, q = map(int, input().split())
for _ in range(q):
    com, x = map(int, input().split())
    if com == 1:
        print(w * x)
        h -= x
    else:
        print(h * x)
        w -= x

C問題

尺取り法のような感じで差分計算をする

C
def add_d(s_i):
    global d
    if s_i not in d:
        d[s_i] = 0
    d[s_i] += 1


n, l, r = map(int, input().split())
s = input()

d = dict()
ans = 0
for l_ind in range(n):
    if l_ind == 0:
        for r_ind in range(l, min(r + 1, n)):
            add_d(s[r_ind])
    else:
        left = l_ind + l - 1
        right = l_ind + r
        if left < n:
            d[s[left]] -= 1
        if right < n:
            add_d(s[right])

    if s[l_ind] in d:
        ans += d[s[l_ind]]

print(ans)

D問題

各行ごとに黒が連続する部分と1個置きになる部分で分けて計算

D
def count_out(x, y):
    return y // 2 - (x - 1) // 2 if x <= y else 0


l, r, d, u = map(int, input().split())

ans = 0
for i in range(l, r + 1):
    k = abs(i)

    # 上
    ans += count_out(max(d, k + 1), u)
    # 下
    ans += count_out(d, min(u, - k - 1))
    # 真ん中
    if k % 2 == 0:
        ans += max(0, min(u, k) - max(d, - k) + 1)

print(ans)
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?