ABC memorandum [ABC163 C --managementr] (Python)

Problem statement

We have a company with $ N $ employees, each of whom is assigned a $ 1, ..., N $ employee number. All employees, except those with employee number 1, have just $ 1 $ in direct reports with a lower employee number than you. When $ X $ is a direct boss of $ Y $, $ Y $ is said to be a direct report of $ X $. Employee number $ i $ is given the employee number of the employee's direct supervisor is $ A_i $. Find out how many direct reports each employee has.

Constraints

2≤N≤2×10^5 1≤A_i

ABC163 C - managementr

solution

Find out how many elements of A are input, and output those values in order.

import collections

N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)

for i in range(1, N + 1):
  print(c[i])

collections.Counter You can find the number of each element in the array by using the Counter class of the collections library.

l = [1,1,2,2,2,3,4,4]
c = collections.Counter(l)

print(c)
# Counter({1: 2, 2: 3, 3: 1, 4: 2})

Recommended Posts

ABC memorandum [ABC163 C --managementr] (Python)
ABC memorandum [ABC159 C --Maximum Volume] (Python)
ABC memorandum [ABC161 C --Replacing Integer] (Python)
ABC memorandum [ABC158 C --Tax Increase] (Python)
ABC memorandum [ABC157 C --Guess The Number] (Python)
ABC147 C --HonestOrUnkind2 [Python]
ABC memorandum [ABC160 C --Traveling Salesman around Lake] (Python)
ABC163 C problem with python3
ABC188 C problem with python3
ABC187 C problem with python
Python memorandum
Python Memorandum 2
Python memorandum
python memorandum
python memorandum
Python memorandum
python memorandum
Python memorandum
Solve ABC163 A ~ C with Python
Solve ABC168 A ~ C with Python
Solve ABC036 A ~ C in Python
Solved AtCoder ABC 114 C-755 with Python3
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
ABC128 A, B, C commentary (python)
Solve ABC158 A ~ C with Python
ABC126 A, B, C Explanation (python)
Solve ABC037 A ~ C in Python
Beginner ABC154 (Python)
Beginner ABC156 (Python)
Python basics memorandum
Python pathlib memorandum
Python memorandum (algorithm)
AtCoder ABC 174 Python
Algorithm in Python (ABC 146 C Binary Search
AtCoder ABC187 Python
AtCoder ABC188 Python
Beginner ABC155 (Python)
python C ++ notes
python, openFrameworks (c ++)
Beginner ABC157 (Python)
Python memorandum [links]
AtCoder ABC 175 Python
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
Python memorandum numbering variables
Python C / C ++ Extension Pattern-Pointer
python memorandum (sequential update)
Python memorandum (personal bookmark)
Next Python in C
Python basic memorandum part 2
Solve ABC169 in Python
C API in Python 3
[Python] Iterative processing_Personal memorandum
Memorandum @ Python OR Seminar
python memorandum super basic
Solve Atcoder ABC176 (A, B, C, E) in Python
Extend python in C ++ (Boost.NumPy)
AtCoder ABC 177 Python (A ~ E)
Effective Python Learning Memorandum Day 15 [15/100]
Solve AtCoder ABC166 with python
[AtCoder explanation] Control ABC180 A, B, C problems with Python!