CSES - E4590 2018 6 - Results
Submission details
Task:Anagrams
Sender:natalia
Submission time:2018-10-20 15:58:21 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1UNKNOWN--details
#2UNKNOWN--details
#3UNKNOWN--details
#4UNKNOWN--details
#5UNKNOWN--details
#6UNKNOWN--details
#7UNKNOWN--details
#8UNKNOWN--details
#9UNKNOWN--details

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
	unsigned int n;
	string str;

	cin >> n;
	vector<string> words;
	vector<pair<int,int> > hashes;

	for(unsigned int i = 0; i < n; i++){
		cin >> str;
		words.push_back(str);
		pair<int,int> p (0, i);
		for(unsigned int j = 0; j < str.length(); j++){
			p.first += (str[j] - 'A' + 1) * 36;
		}
		hashes.push_back(p);
	}

	sort(hashes.begin(), hashes.end());
/*
	for(unsigned int i = 0; i < n; i++){
		cout << hashes[i].first << "," << hashes[i].second << "\n";
	}
*/

	int total = 0;

	for(unsigned int i = 0; i < n - 1;){
		int j = i + 1;
		if(hashes[i].first == hashes[j].first){
			total++;
		}
		while(hashes[i].first == hashes[j].first) j++;	
		i = j;
	}

	cout << total << "\n";

	int prev = -1;
	int counter = 1;
	for(unsigned int i = 0; i < n; i++){
		if(hashes[i].first == prev){
			counter++;
		} else if(counter > 1){
			cout << counter << "\n";
			for(int j = 1; j <= counter; j++){
				cout << words[hashes[i - j].second] << "\n";
			}
			counter = 1;
		}
		prev = hashes[i].first;
	}

	if(counter > 1){
		cout << counter << "\n";
		for(int j = 1; j <= counter; j++){
			cout << words[hashes[n - j].second] << "\n";
		}
	}

	return 0;
}

Test details

Test 1

Verdict: UNKNOWN

input
68760
aakkonen
aakkosellinen
aakkosellisesti
aakkosellisuus
...

correct output
3076
2
haaraantua
raahaantua
2
...

user output
(not available)

Test 2

Verdict: UNKNOWN

input
370099
a
aa
aaa
aah
...

correct output
30178
2
basiparachromatin
marsipobranchiata
2
...

user output
(not available)

Test 3

Verdict: UNKNOWN

input
100000
cnhmuewgnum
dxkmhzhetnmxadtcy
hfjqwavsiguwpludsketibe
xwxolrmvkz
...

correct output
0

user output
(not available)

Test 4

Verdict: UNKNOWN

input
400000
vlcsa
eltwde
wdcwwkubs
tmuxbirj
...

correct output
0

user output
(not available)

Test 5

Verdict: UNKNOWN

input
400000
ebhfigdacjlk
aecfdijlhkgb
jfekhbidacgl
cehajbidfklg
...

correct output
1
400000
abcdeighjlfk
abcdeiglhfjk
abcdfkilejgh
...

user output
(not available)

Test 6

Verdict: UNKNOWN

input
400000
cbaabghadefb
hbbgfaeabdac
abaedcbgfbha
hcfadbbbeaag
...

correct output
1
400000
aaabbbcfegdh
aaabbbcfghed
aaabbbdcgfhe
...

user output
(not available)

Test 7

Verdict: UNKNOWN

input
1
a

correct output
0

user output
(not available)

Test 8

Verdict: UNKNOWN

input
2
ab
ba

correct output
1
2
ab
ba

user output
(not available)

Test 9

Verdict: UNKNOWN

input
2
aa
ab

correct output
0

user output
(not available)