Submission details
Task:Anagrams
Sender:MrAurela
Submission time:2020-09-26 14:33:41 +0300
Language:Python3 (CPython3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.35 sdetails
#2ACCEPTED1.63 sdetails
#3ACCEPTED0.71 sdetails
#4ACCEPTED1.65 sdetails
#5ACCEPTED1.91 sdetails
#6ACCEPTED1.85 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
}
primes = [
    2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
    73, 79, 83, 89, 97, 101
]

modulo = 2**63-1

for i in range(n):
    word = input()
    
    h = 1
    for c in word:
        h = h * primes[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: ACCEPTED

input
68760
aakkonen
aakkosellinen
aakkosellisesti
aakkosellisuus
...

correct output
3076
2
haaraantua
raahaantua
2
...

user output
3076
2
aikanaan
ainakaan
2
...
Truncated

Test 2

Verdict: ACCEPTED

input
370099
a
aa
aaa
aah
...

correct output
30178
2
basiparachromatin
marsipobranchiata
2
...

user output
30178
2
abdali
abidal
2
...
Truncated

Test 3

Verdict: ACCEPTED

input
100000
cnhmuewgnum
dxkmhzhetnmxadtcy
hfjqwavsiguwpludsketibe
xwxolrmvkz
...

correct output
0

user output
0

Test 4

Verdict: ACCEPTED

input
400000
vlcsa
eltwde
wdcwwkubs
tmuxbirj
...

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
400000
ebhfigdacjlk
aecfdijlhkgb
jfekhbidacgl
cehajbidfklg
...

correct output
1
400000
abcdeighjlfk
abcdeiglhfjk
abcdfkilejgh
...

user output
1
400000
ebhfigdacjlk
aecfdijlhkgb
jfekhbidacgl
...
Truncated

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