Submission details
Task:Anagrams
Sender:MrAurela
Submission time:2020-09-26 14:30:24 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#10.51 sdetails
#22.61 sdetails
#30.92 sdetails
#42.73 sdetails
#52.95 sdetails
#62.99 sdetails
#70.02 sdetails
#80.02 sdetails
#90.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
]

b = 37
modulo = 100000007

for i in range(n):
    word = input()
    
    h = 1
    for c in word:
        h = h * primes[alphabet[c]] % modulo

    print(h)
    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
74606200
12906429
27554734
88845921
97544734
...
Truncated

Test 2

Verdict:

input
370099
a
aa
aaa
aah
...

correct output
30178
2
basiparachromatin
marsipobranchiata
2
...

user output
2
4
8
76
5852
...
Truncated

Test 3

Verdict:

input
100000
cnhmuewgnum
dxkmhzhetnmxadtcy
hfjqwavsiguwpludsketibe
xwxolrmvkz
...

correct output
0

user output
43422719
58117327
82934537
33965204
12304562
...
Truncated

Test 4

Verdict:

input
400000
vlcsa
eltwde
wdcwwkubs
tmuxbirj
...

correct output
0

user output
1958410
84680720
65619132
11091192
46678381
...
Truncated

Test 5

Verdict:

input
400000
ebhfigdacjlk
aecfdijlhkgb
jfekhbidacgl
cehajbidfklg
...

correct output
1
400000
abcdeighjlfk
abcdeiglhfjk
abcdfkilejgh
...

user output
37615361
37615361
37615361
37615361
37615361
...
Truncated

Test 6

Verdict:

input
400000
cbaabghadefb
hbbgfaeabdac
abaedcbgfbha
hcfadbbbeaag
...

correct output
1
400000
aaabbbcfegdh
aaabbbcfghed
aaabbbdcgfhe
...

user output
49188819
49188819
49188819
49188819
49188819
...
Truncated

Test 7

Verdict:

input
1
a

correct output
0

user output
2
0

Test 8

Verdict:

input
2
ab
ba

correct output
1
2
ab
ba

user output
6
6
1
2
ab
...

Test 9

Verdict:

input
2
aa
ab

correct output
0

user output
4
6
0