CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:jusola
Submission time:2019-10-02 21:46:01 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.01 sdetails
#40.01 sdetails
#50.01 sdetails
#60.01 sdetails

Code

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <stdio.h>
#include <string.h>

using namespace std;

const string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

char alphabetArr[54];




/*
bool isPair(const string a = 0, const string b = 0) {
	std::unordered_map<char, char> mapA;
	std::unordered_map<char, char> mapB;

	std::unordered_map<char, char>::iterator it;

	char arrA[50];
	char arrB[50];

	string newA;
	string newB;

	strcpy(arrA, a.c_str());
	strcpy(arrB, b.c_str());

	for (int i = 0; i < (int)a.size(); i++) {
		if (mapA.find(arrA[i]) != mapA.end()) {
			newA = newA + std::string(1, mapA.find(arrA[i])->second);
		}
		else {
			newA = newA + std::string(1, alphabetArr[(int)mapA.size()]);
			mapA.insert(std::pair<char, char>(arrA[i], alphabetArr[(int)mapA.size()]));

		}

	}

	for (int i = 0; i < (int)b.size(); i++) {
		if (mapB.find(arrB[i]) != mapB.end()) {
			newB = newB + std::string(1, mapB.find(arrB[i])->second);
		}
		else {
			newB = newB + std::string(1, alphabetArr[(int)mapB.size()]);
			mapB.insert(std::pair<char, char>(arrB[i], alphabetArr[(int)mapB.size()]));

		}

	}
	return (newA == newB);
}
*/

string toFormat(const string in) {
	std::unordered_map<char, char> mapStr;

	std::unordered_map<char, char>::iterator it;

	char arrStr[50];

	string newStr;

	strcpy(arrStr, in.c_str());

	for (int i = 0; i < (int)in.size(); i++) {
		if (mapStr.find(arrStr[i]) != mapStr.end()) {
			newStr = newStr + std::string(1, mapStr.find(arrStr[i])->second);
		}
		else {
			newStr = newStr + std::string(1, alphabetArr[(int)mapStr.size()]);
			mapStr.insert(std::pair<char, char>(arrStr[i], alphabetArr[(int)mapStr.size()]));

		}

	}

	return newStr;
}

int main() {
	int num;
	int amount = 0;
	strcpy(alphabetArr, alphabet.c_str());
	string arr[10000];
	string newArr[10000];
	std::unordered_map<string, int> CountSame;
	cin >> num;

	for (int i = 0; i < num; i++) {
		cin >> arr[i];
	}
	for (int i = 0; i < num; i++) {
		newArr[i] = toFormat(arr[i]);
		if (CountSame.find(newArr[i]) != CountSame.end()) {
			CountSame[newArr[i]] = CountSame.find(newArr[i])->second+1;
		}
		else {
			CountSame[newArr[i]] = 1;
		}
	};

	for (std::unordered_map<string, int>::iterator it = CountSame.begin(); it != CountSame.end(); ++it)
	{
		amount += (it->second * (it->second - 1))/2;
	}

	cout << amount;
	return 0;
}

Test details

Test 1

Verdict:

input
1

correct output

user output
0

Test 2

Verdict:

input
2

correct output
1 2 
2 1 

user output
1

Test 3

Verdict:

input
5

correct output
1 2 3 4 5 
2 1 4 3 6 
3 4 1 2 7 
4 3 2 1 8 
5 6 7 8 1 

user output
10

Test 4

Verdict:

input
42

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
861

Test 5

Verdict:

input
99

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
4851

Test 6

Verdict:

input
100

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
4950