2
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?

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

2
Posted at

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

A問題

  • just do it
A.py
"""
<方針>
- just do it
"""
# 入力
A, B, C = map(int, input().split())

# 条件
if(A != B and B == C):
  # 出力
  print("Yes")
else:
  print("No")

B問題

  • 点対象となる相手方と同じ値かを考えよう.
B.py
"""
<方針>
- 点対象となる相手方と同じ値かを考えよう.
"""
H, W = map(int, input().split())
SS = [list(input()) for _ in range(H)]

ans = 0
for h in range(H): # 下
  for hh in range(h, H): # 上
    for w in range(W): # 左
      for ww in range(w, W): # 右
        ok = True # 同じ値かどうか
        for i in range(hh-h+1):
          for j in range(ww-w+1):
            # 点対象を満たさない十分条件
            if(SS[h+i][w+j] != SS[hh-i][ww-j]):
              ok = False
        if(ok):
          ans += 1

print(ans)

C問題

方針

  • なるべくたくさん数字を消せるやつから選べば良さそう.
  • 逆にいえば,小さい数字を残そう

前提

  • C問題あたりで,TLEになる人は,制約条件を見る癖をつけよう.
  • AB問題では,基本的に制約条件を見ずにやっても解ける.
  • しかし,C問題以降では,制約条件を見ないと必ずTLEすると思っても良い.
  • 詳しい話は私の352回の記事C問題の解説に記したので,是非参照してほしい.
C.py
"""
<方針>
- なるべくたくさん数字を消せるやつから選べば良さそう.
- 逆にいえば,小さい数字を残そう
"""
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))

# 同じ数字が何種類あるかカウント
di = defaultdict(int)
for a in A:
  di[a] += 1

# 同じ数字で合計和を考える
ls = []
for ke, va in di.items():
  ls.append(ke*va)

# ソートする.
ls.sort()

print(sum(ls[:-K]))

補足

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

筆者について

その他

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

最後に一言

  • 納得は全てに優先するぜ!
2
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
2
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?