0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

トヨタシステムズプログラミングコンテスト2024(AtCoder Beginner Contest 377)の解答等の速報的まとめ

A問題

配列に入れてソートして確認

A
print("Yes" if sorted(list(input())) == ["A", "B", "C"] else "No")

B問題

横方向で#がない行の数$\times$縦方向で#がない列の数

B
s = [input()for _ in range(8)]

r = 0
c = [True] * 8
for i in range(8):
    if "#" not in s[i]:
        r += 1
    for j in range(8):
        if s[i][j] == "#":
            c[j] = False

print(r * sum(c))

C問題

各ナイトがいけるマスの数を調べて、マスの総数から引く

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

for _ in range(m):
    a, b = map(int, input().split())
    s.add((a, b))
    for i, j in [(2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1)]:
        if 1 <= a + i <= n and 1 <= b + j <= n:
            s.add((a + i, b + j))

print(n ** 2 - len(s))

D問題

各区間の左端を固定して右端をどこまで伸ばせられるかを順番に計算する
前計算で各座標を左端とする区間のうち最初にいずれかの区間を含む右端の座標を求めておく

D
n, m = map(int, input().split())
data = [tuple(map(int, input().split())) for _ in range(n)]

INF = float("inf")
lst = [INF] * (m + 1)

for l, r in data:
    lst[l] = min(lst[l], r)

for i in range(m - 1, -1, -1):
    lst[i] = min(lst[i], lst[i + 1])

ans = 0
for i in range(1, m + 1):
    if lst[i] < INF:
        ans += lst[i] - i
    else:
        ans += m - i + 1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?