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?

SMBCプログラミングコンテスト #1(AtCoder Beginner Contest 458)の解答等の速報的まとめ

A問題

スライスで取る

A
s = input()
n = int(input())
print(s[n:-n])

B問題

隣接するマスがあるか実際に調べる

B
def inner(x, y):
    return 0 <= x < h and 0 <= y < w


h, w = map(int, input().split())

ans = [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        ans[i][j] += inner(i - 1, j) + inner(i + 1, j) + inner(i, j - 1) + inner(i, j + 1)

for a_i in ans:
    print(*a_i)

C問題

各$C$を中心とする文字列のパターンは端までの文字数$+1$と一致する

C
s = input()

ans = 0
n = len(s)
for i, s_i in enumerate(s):
    if s_i == "C":
        ans += min(i + 1, n - i)

print(ans)

D問題

中央値以上を持つSortedListとそれ未満をもつSortedListを用意する。
未満のほうから最大値を1つと$A_i, B_i$を中央値以上のリストに入れて小さいほうから3番目が新たな中央値となる

D
from sortedcontainers import SortedList


x = int(input())
s = SortedList([x])
mini = SortedList()

for i in range(int(input())):
    a_i, b_i = map(int, input().split())
    s.add(a_i)
    s.add(b_i)
    if mini:
        m = mini.pop()
        s.add(m)
        x = s.pop(0)
        mini.add(x)
    x = s.pop(0)
    mini.add(x)
    print(s[0])
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?