AtCoder Beginners Contest 089[A to C]

Tasks

 

A. Grouping 2 … Simply print the result of the floor result

print(int(input())//3)

 

B. Hina Arare … As I use set(), I just need to add everything in this set. And print out the result to get the unique numbers of colors.

n = input()
s = set(input().split())

print("Four" if len(s) == 4 else "Three")

 

C. March … At the first sight, I thought I used regular expression to get the matching result. but soon realized it would be too slow in this case as N is a way big. Instead I use simple dictionary to store just the numbers of person whose name starts with any character in “MARCH”. With this, the cost would be N, and it should be completed within the necessary timeframe.

from itertools import combinations

n = int(input())
names = {"M":0, "A":0, "R":0, "C":0, "H":0}
# for each input, examine if it starts with specific character.
# No need to store the actual name as this problem doesn't require full name to output
for _ in range(n):
    name = input()
    if name[0] in names.keys():
        names[name[0]] += 1

patterns = list(combinations(names.keys(), 3))

count = 0
for pattern in patterns:
    count += names[pattern[0]] * names[pattern[1]] * names[pattern[2]]

print(count)