Skip to content

Instantly share code, notes, and snippets.

@uchidama
Last active July 6, 2021 15:29
Show Gist options
  • Save uchidama/32c80031b35c17402ba792d46abad852 to your computer and use it in GitHub Desktop.
Save uchidama/32c80031b35c17402ba792d46abad852 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 089 [ C - March ] https://atcoder.jp/contests/abc089/tasks/abc089_c
'''
[問題]
https://atcoder.jp/contests/abc089/tasks/abc089_c
[参考]
Python defaultdict の使い方
https://qiita.com/xza/items/72a1b07fcf64d1f4bdb7
Pythonで階乗、順列・組み合わせを計算、生成
https://note.nkmk.me/python-math-factorial-permutations-combinations/
'''
import sys
from collections import defaultdict
import itertools
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ
input = sys.stdin.readline
INF = 2 ** 63 - 1
N = int(input())
# defaultdictに、頭文字ごとの単語数を保存
D = defaultdict(int)
for _ in range(N):
S = input()
D[S[0]] += 1
# M,A,R,C,Hから3つ選ぶ組み合わせを生成。それぞれの頭文字数で掛け算して組み合わせ数を出してansに足していく
ans = 0
A = ['M','A','R','C','H']
for c in itertools.combinations(A, 3):
ans += D[c[0]]*D[c[1]]*D[c[2]]
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment