LoginSignup
0
0

More than 1 year has passed since last update.

ABC163 C - management から学んだ

Last updated at Posted at 2021-09-18

ABC163_1.png

続いてサンプル。

ABC163_2.png
ABC163_3.png
ABC163_4.png

社員番号の数だけ配列を用意してみるか。
Ai で call された社員番号のセルを 1 ずつインクリメントすれば良いのでは?

management.py
N = int(input())
A = list(map(int,input().split()))
lis = [0]*(N+1)

for i in range(2,N+1):#計算量 ほぼ O(N)
    lis[A[i-2]] += 1

for i in range(1,len(lis)):#計算量 O(N)
    print(lis[i])

#計算量の合計 O(2N)。 間に合う
#131ms

再チャレンジ。
出来たけどおもろい記述があったのでパクってみました。

abc163c.py
def solv():
    N = int(input())
    A = list(map(int,input().split()))
    memo = [0]*N
    for a in A:
        memo[a-1] += 1
    print("\n".join(map(str,memo)))#<=パクった
    #for ans in memo: #<=パクる前の記述
    #    print(ans)
solv()#111ms

各要素を文字に変換して
かつ、間に改行の記述を挟むことで
for を省略している。素晴らしい。

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