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?

[ABC472] ABC 472のA~C問題をPythonで解説

0
Posted at

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

A問題

  • "A" or not
A.py
"""
<方針>
- `"A"` or not
"""
S = input()

ans = []

for s in S:
  if(s == "A"):
    ans.append("A")
  else:
    ans.append(".")

print("".join(ans))

B問題

  • もう全部のパターンをやろうぜ。
B.py
"""
<方針>
- もう全部のパターンをやろうぜ。
"""
N = int(input())
L = list(map(int, input().split()))

ans = float("inf")

for i in range(N):
  tmp = abs(sum(L[:i+1])-sum(L[i+1:]))
  ans = min(ans, tmp)

print(ans)

C問題

方針

  • シミュレーションしますか。

前提

  • C問題あたりで,TLEになる人は,制約条件を見る癖をつけよう.
  • AB問題では,基本的に制約条件を見ずにやっても解ける.
  • しかし,C問題以降では,制約条件を見ないと必ずTLEすると思っても良い.
  • 詳しい話は私の352回の記事C問題の解説に記したので,是非参照してほしい.
C.py
"""
<方針>
- シミュレーションしますか。
"""
N, M, K = map(int, input().split())
A = list(map(int, input().split()))

su = 0
for i in range(N):
  
  if (i >= M):
    su -= A[i-M]
    
  if ((su + A[i]) <= K):
    su += A[i]
    print("Yes")
  else:
    A[i] = 0
    print("No")

補足

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

筆者について

その他

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

最後に一言

  • 紙を使う。
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?