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?

[ABC462] ABC 462のA~C問題をPythonで解説

0
Posted at

[ABC462] ABC 462(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

A問題

  • 正規表現で数字を選ぼう。
A.py
"""
<方針>
- 正規表現で数字を選ぼう。
"""
import re
# 入力
S = input()

# 数字だけを取得
ans = ""
for s in S:
  if(re.match("\d", s)):
    ans += s

# 出力
print(ans)

B問題

  • リストに渡した人を記録しておこう。
B.py
"""
<方針>
- リストに渡した人を記録しておこう。
"""
N = int(input())

# 渡した人を記録するリスト
BB = [[] for _ in range(N+1)]

# BB の構築
for i in range(N):
  K, *A = list(map(int, input().split()))
  for a in A:
    BB[a].append(i+1)

# 出力
for B in BB[1:]:
  print(len(B), *B)

C問題

方針

  • X でソートして、Y が値を下回った時だけをカウントしてけば良さそう。

前提

  • C問題あたりで,TLEになる人は,制約条件を見る癖をつけよう.
  • AB問題では,基本的に制約条件を見ずにやっても解ける.
  • しかし,C問題以降では,制約条件を見ないと必ずTLEすると思っても良い.
  • 詳しい話は私の352回の記事C問題の解説に記したので,是非参照してほしい.
C.py
"""
<方針>
- `X` でソートして、`Y` が値を下回った時だけをカウントしてけば良さそう。
"""
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

# カウント
ans = 0

# Yの最小値
miY = float("inf")

# Xでソート
XY.sort(key=lambda x:x[0])

# ソート順から見る
for _, y in XY:
  if(y < miY):
    ans += 1
  miY = min(miY, y)

print(ans)

補足

関係するリンク(参考文献など)

筆者について

その他

  • 間違いを含んでいる可能性があります.
  • 方針と言いつつ,方針ではない感想などを書いている場合があります.
  • A問題から解説がだんだん省略されます.
  • コードに書かれている解説の文言と,その上に書いてある解説の文言を変えている場合があります.

最後に一言

  • (APIとか使って投稿を楽にしてみた。うまく届いていますか?v3🥺)
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?