Submission details
Task:Anagrams
Sender:phid
Submission time:2020-09-26 15:17:12 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#10.08 sdetails
#20.46 sdetails
#3ACCEPTED0.15 sdetails
#4ACCEPTED0.36 sdetails
#5ACCEPTED0.78 sdetails
#6ACCEPTED0.77 sdetails
#7ACCEPTED0.01 sdetails
#8ACCEPTED0.01 sdetails
#9ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:30:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (long int i = 0; i < v.size() - 1; i++) {
                          ~~^~~~~~~~~~~~~~
input/code.cpp:47:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (i < count.size())
                ~~^~~~~~~~~~~~~~
input/code.cpp:54:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 while (count[i] == 0 && i < count.size()) i++;
                                         ~~^~~~~~~~~~~~~~

Code

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

using namespace std;

int main() {
    long int n;
    cin >> n;
    vector<pair<string, string>> v; // (sorted, orginal)
    string st;
    
    for (long int i = 0; i < n; i++) {
        cin >> st;
        string sttmp = st;
        sort(sttmp.begin(), sttmp.end());
        v.push_back(pair<string, string>(sttmp, st));
    }

    sort(v.begin(), v.end(),[] (const auto &a, const auto &b)
    {
        return a.first < b.first;
    }); 
    
    
    vector<int> count(v.size() + 1, 0);
    n = 0;
    
    for (long int i = 0; i < v.size() - 1; i++) {
        if (v[i].first == v[i+1].first)
        {
            if (count[i] == 0)
            {
                count[i] = 1;
                n++;
            }
            count[i + 1] = count[i] + 1;
        }
    }
    
    cout << n << endl;
    
    if (n > 0)
    {
        long int i = 0, s = 0;
        while (i < count.size())
        {
            if (count[i] != 0) i++;
            else
            {
                cout << count[i - 1] << endl;
                for (int j = s; j < i; j++) cout << v[j].second << endl;
                while (count[i] == 0 && i < count.size()) i++;
                s = i;
            }
        }
    }
    return 0;
}

Test details

Test 1

Verdict:

input
68760
aakkonen
aakkosellinen
aakkosellisesti
aakkosellisuus
...

correct output
3076
2
haaraantua
raahaantua
2
...

user output
3076
0
2
raahaantua
haaraantua
...
Truncated

Test 2

Verdict:

input
370099
a
aa
aaa
aah
...

correct output
30178
2
basiparachromatin
marsipobranchiata
2
...

user output
30178
0
2
basiparachromatin
marsipobranchiata
...
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
ihdbalcfjgek
eblifdcgjhak
dkcflgheiajb
...
Truncated

Test 6

Verdict: ACCEPTED

input
400000
cbaabghadefb
hbbgfaeabdac
abaedcbgfbha
hcfadbbbeaag
...

correct output
1
400000
aaabbbcfegdh
aaabbbcfghed
aaabbbdcgfhe
...

user output
1
400000
gbbaadaechbf
hgdafacbaebb
bbadhfacabge
...
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