abc089_c - March
09 Dec 2020 — Tags: counting — URLMantain count of strings that start with one of “MARCH” letters. Count all possible triplets.
Time complexity: $O(1)$
Memory complexity: $O(n)$
Click to show code.
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(void)
{
ios::sync_with_stdio(false), cin.tie(NULL);
const string march = "MARCH";
array<ll, 5> cnt;
fill(begin(cnt), end(cnt), 0);
int n;
cin >> n;
while (n--)
{
string s;
cin >> s;
if (auto it = find(begin(march), end(march), s[0]); it != end(march))
cnt[distance(begin(march), it)]++;
}
ll ans = 0;
for (int i = 0; i < 3; ++i)
for (int j = i + 1; j < 4; ++j)
for (int k = j + 1; k < 5; ++k)
ans += cnt[i] * cnt[j] * cnt[k];
cout << ans << endl;
return 0;
}