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?

AtCoder Beginner ContestをPythonで取り組んだ振り返り(ABC451 A,B)

0
Posted at

どうもこんにちは!

スケジュールの都合で1か月ぶりの参加となりました。
今回は2完でBまで。
久しぶりだからということにしたいです
C問題は高さごとの本数を辞書で記録して伐採の際に更新とするとTLE。辞書をサーチせずに処理する方法が考えきれずでした。

問題と公式の解説のリンク

問題は以下のリンクから。

A - illegal -

問題

与えられた文字列の長さが5の倍数かどうかを判定する問題。

考え方とコード

受け取った文字列をlen関数で長さを取得し、if文で判定。

print("Yes" if len(input()) % 5 == 0 else "No")

B - Personnel Change -

問題

n人がそれぞれ1つの部門に所属していると、各人ごとに現在の部門と次に所属する部門が与えられます。
これらをもとに各部門ごとに次の所属人数から現在の所属人数を引いた値を出力する問題。

考え方とコード

各部門の差分がわかればよいので、各部門の初期値を0とし、現在の部門は-1,次の部門を+1するというのを各人ごとに処理して最終結果を出力すればOKです。

n,m = map(int,input().split())
s = [0] * m
for _ in range(n):
    a,b = map(int,input().split())
    s[a-1] -= 1
    s[b-1] += 1
for i in range(m):
    print(s[i])

ではでは。

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?