CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:kaurip
Submission time:2019-10-01 12:39:09 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:20:11: error: '::main' must return 'int'
 long main() {
           ^
input/code.cpp: In function 'int main()':
input/code.cpp:32:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(long j = 0; j < strings[i].length(); j++) {
                   ~~^~~~~~~~~~~~~~~~~~~~~

Code

#include <iostream>
#include <unordered_map>
#include <string>

using namespace std;

long long fact(long n) 
{ 
	long long res = 1; 
	for (long i = 2; i <= n; i++) 
		res = res * i; 
	return res; 
}

long long nCr(long n, long r) 
{
	return fact(n) / (fact(r) * fact(n - r)); 
} 

long main() {
	long n;
	cin >> n;
	string strings[n];
	for(long i = 0; i < n; i++) {
		cin >> strings[i];
	}
	
	unordered_map<string,long> total;

	for(long i = 0; i < n; i++) {
		unordered_map<char, long> used;
		for(long j = 0; j < strings[i].length(); j++) {
			if(used.count(strings[i][j])) {
				strings[i][j] = used[strings[i][j]];
			} else {
				used[strings[i][j]] = (char)j;
				strings[i][j] = (char)j;
			}
		}
		if(total.count(strings[i])) {
			total[strings[i]]++;
		} else {
			total[strings[i]] = 1;
		}
	}

	long long pairs = 0;

	for(pair<string,long> entry : total) {
		pairs += nCr(entry.second,2);
		//cout << entry.first << ": " << entry.second << endl;
	}

	cout << pairs;

	return 0;
}