CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:pants64
Submission time:2019-10-01 19:58:20 +0300
Language:C++ (C++17)
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 <vector>
#include <string>
#include <unordered_map>
#include <cstdint>

using std::cout, std::cin, std::vector, std::string;

struct Hash
{
	size_t operator()(const std::vector<uint8_t>& vec) const
	{
	    std::hash<uint8_t> hasher;
	    size_t seed = 0;

	    for (int i : vec)
	    {
	        seed ^= hasher(i) + 0x0959f0d8 + (seed << 6) + (seed >> 2);
	    }
	    return seed;
	}
};

vector<uint8_t> Convert(const string& str)
{
	vector<uint8_t> line (str.length(), 0);

	uint8_t max = 0;
	for (unsigned i = 0; i < str.length(); i++)
	{
		bool found = false;
		for (unsigned j = 0; j < i; j++)
		{
			if (str[j] == str[i])
			{
				line[i] = line[j];
				found = true;

				if (max < line[i]) max = line[i];

				break;
			}
		}
		if (!found) line[i] = max++;
	}
	return line;
}

int main()
{
	int n;
	cin >> n;

	std::unordered_map <vector<uint8_t>, int, Hash> lines;

	for (int i = 0; i < n; i++)
	{
		string input;
		cin >> input;

		lines[Convert(input)]++;
	}

	int num = 0; 
    for (auto it=lines.begin(); it!=lines.end(); it++) 
    { 
        int count = it->second; 
        num += (count * (count - 1)) / 2; 
    } 

	cout << num << "\n";
}

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