Submission details
Task:Anagrams
Sender:MrAurela
Submission time:2020-09-26 14:13:50 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#10.58 sdetails
#22.78 sdetails
#31.24 sdetails
#42.80 sdetails
#5--details
#6ACCEPTED2.86 sdetails
#7ACCEPTED0.02 sdetails
#8ACCEPTED0.02 sdetails
#9ACCEPTED0.02 sdetails

Code

n = int(input())

groups = {}
alones = {}
alphabet = {
    "a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
    "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
    "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
    "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
    "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25
}

base = 26
modulo = 100000007

for i in range(n):
    word = input()

    
    h = 0
    for c in word:
        h = h + base**alphabet[c] % modulo

    if h not in alones:
        alones[h] = word
    else:
        if h not in groups:
            groups[h] = [alones[h]]
        groups[h].append(word)

print(len(groups))
for group, elements in groups.items():
    print(len(elements))
    print("\n".join(elements))

Test details

Test 1

Verdict:

input
68760
aakkonen
aakkosellinen
aakkosellisesti
aakkosellisuus
...

correct output
3076
2
haaraantua
raahaantua
2
...

user output
3083
2
aikanaan
ainakaan
2
...
Truncated

Test 2

Verdict:

input
370099
a
aa
aaa
aah
...

correct output
30178
2
basiparachromatin
marsipobranchiata
2
...

user output
30297
2
abdali
abidal
2
...
Truncated

Test 3

Verdict:

input
100000
cnhmuewgnum
dxkmhzhetnmxadtcy
hfjqwavsiguwpludsketibe
xwxolrmvkz
...

correct output
0

user output
5
2
ogbfbexnkbih
opjlezu
2
...
Truncated

Test 4

Verdict:

input
400000
vlcsa
eltwde
wdcwwkubs
tmuxbirj
...

correct output
0

user output
172
2
hvpko
eixpdxkqd
2
...
Truncated

Test 5

Verdict:

input
400000
ebhfigdacjlk
aecfdijlhkgb
jfekhbidacgl
cehajbidfklg
...

correct output
1
400000
abcdeighjlfk
abcdeiglhfjk
abcdfkilejgh
...

user output
(empty)

Test 6

Verdict: ACCEPTED

input
400000
cbaabghadefb
hbbgfaeabdac
abaedcbgfbha
hcfadbbbeaag
...

correct output
1
400000
aaabbbcfegdh
aaabbbcfghed
aaabbbdcgfhe
...

user output
1
400000
cbaabghadefb
hbbgfaeabdac
abaedcbgfbha
...
Truncated

Test 7

Verdict: ACCEPTED

input
1
a

correct output
0

user output
0

Test 8

Verdict: ACCEPTED

input
2
ab
ba

correct output
1
2
ab
ba

user output
1
2
ab
ba

Test 9

Verdict: ACCEPTED

input
2
aa
ab

correct output
0

user output
0