Submission details
Task:Anagrams
Sender:kkivimaki
Submission time:2020-09-26 13:33:09 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.14 sdetails
#20.74 sdetails
#30.35 sdetails
#40.76 sdetails
#50.73 sdetails
#60.73 sdetails
#7ACCEPTED0.01 sdetails
#80.01 sdetails
#9ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:27:10: warning: unused variable 'hashes' [-Wunused-variable]
     int *hashes = new int[n];
          ^~~~~~

Code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int h(std::string s) {
    int m = 0;
    int t = 1;
    for (auto c: s) {
        m += c*t;
        t *= 26;
    }
    return m;
}

bool comp(string s1, string s2) {
    return h(s1) < h(s2);
}

int main() {
    int n;

    cin >> n;

    vector<string> sanat = vector<string>();
    int *hashes = new int[n];


    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sanat.push_back(s);
    }

    sort(sanat.begin(), sanat.end(), comp);

    int v0 = h(sanat[0]);
    int m = 0;
    int s = 0;

    for (int i = 1; i < n; i++) {
        int v = h(sanat[i]); 
        if (v != v0) {
            v0 = v;
            s = 0;
        } else {
            if (!s) {
                s = 1;
                m += 1;
            }
        }
    }

    cout << m << endl;

    v0 = h(sanat[0]);
    int f = 1;
    for (int i = 1; i < n; i++) {
        int v = h(sanat[i]); 
        if (v != v0) {
            v0 = v;
            if (f > 1) {
                cout << f << endl;
                for (int j = i - f; j < i; j++)
                    cout << sanat[j] << endl;
            }
            f = 1;
        } else {
            f += 1;
        }
    }
    if (f > 1) {
        cout << f << endl;
        for (int j = n - f; j < n; j++)
            cout << sanat[j] << endl;
    }

    return 0;
}

Test details

Test 1

Verdict:

input
68760
aakkonen
aakkosellinen
aakkosellisesti
aakkosellisuus
...

correct output
3076
2
haaraantua
raahaantua
2
...

user output
0

Test 2

Verdict:

input
370099
a
aa
aaa
aah
...

correct output
30178
2
basiparachromatin
marsipobranchiata
2
...

user output
16
2
bunkhouse
noncausatively
2
...
Truncated

Test 3

Verdict:

input
100000
cnhmuewgnum
dxkmhzhetnmxadtcy
hfjqwavsiguwpludsketibe
xwxolrmvkz
...

correct output
0

user output
1
2
mzejthnnrecalvkku
wgxwastnnrtdcifumji

Test 4

Verdict:

input
400000
vlcsa
eltwde
wdcwwkubs
tmuxbirj
...

correct output
0

user output
9
2
pdllxaydsosp
ziibibbj
2
...
Truncated

Test 5

Verdict:

input
400000
ebhfigdacjlk
aecfdijlhkgb
jfekhbidacgl
cehajbidfklg
...

correct output
1
400000
abcdeighjlfk
abcdeiglhfjk
abcdfkilejgh
...

user output
22
2
lhdajgkficeb
dfgaibejlchk
2
...
Truncated

Test 6

Verdict:

input
400000
cbaabghadefb
hbbgfaeabdac
abaedcbgfbha
hcfadbbbeaag
...

correct output
1
400000
aaabbbcfegdh
aaabbbcfghed
aaabbbdcgfhe
...

user output
17
2
aabbacdghefb
egdcfbababha
2
...
Truncated

Test 7

Verdict: ACCEPTED

input
1
a

correct output
0

user output
0

Test 8

Verdict:

input
2
ab
ba

correct output
1
2
ab
ba

user output
0

Test 9

Verdict: ACCEPTED

input
2
aa
ab

correct output
0

user output
0