Task: | Anagrams |
Sender: | dawidwozny7 |
Submission time: | 2020-09-26 14:12:07 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.29 s | details |
#2 | ACCEPTED | 0.66 s | details |
#3 | ACCEPTED | 0.36 s | details |
#4 | ACCEPTED | 0.56 s | details |
#5 | ACCEPTED | 1.13 s | details |
#6 | ACCEPTED | 1.13 s | details |
#7 | ACCEPTED | 0.21 s | details |
#8 | ACCEPTED | 0.21 s | details |
#9 | ACCEPTED | 0.21 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:64:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int j=0;j<res[i].size();++j){ ~^~~~~~~~~~~~~~
Code
#include <bits/stdc++.h> using namespace std; pair<string,string> tab2[4000100]; vector<string> res[4000100]; int main() { int n; string s; cin >> n; for(int i=0; i<n;++i){ cin >> s; tab2[i].first=s; tab2[i].second=s; sort(tab2[i].first.begin(),tab2[i].first.end()); } sort(tab2,tab2+n); /*for( int i=0;i<n;++i) { cout << tab2[i].first << " , " << tab2[i].second << endl; }*/ int groups=0; int group_count=1; res[0].push_back(tab2[0].second); string prev=tab2[0].first; for(int i=1; i<n-1; ++i){ if(tab2[i].first==prev){ group_count++; res[groups].push_back(tab2[i].second); }else{ if(group_count>1){ groups++; prev=tab2[i].first; res[groups].push_back(tab2[i].second); group_count=1; }else{ res[groups].pop_back(); res[groups].push_back(tab2[i].second); group_count=1; prev=tab2[i].first; } } } if(n>1){ if(tab2[n-1].first==prev){ group_count++; res[groups].push_back(tab2[n-1].second); groups++; }else{ if(group_count>1){ groups++; }else{ res[groups].pop_back(); } } } cout << groups << endl; for(int i=0; i<groups;i++) { cout << res[i].size() << endl; for(int j=0;j<res[i].size();++j){ cout << res[i][j] << endl; } } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
68760 aakkonen aakkosellinen aakkosellisesti aakkosellisuus ... |
correct output |
---|
3076 2 haaraantua raahaantua 2 ... |
user output |
---|
3076 2 haaraantua raahaantua 2 ... Truncated |
Test 2
Verdict: ACCEPTED
input |
---|
370099 a aa aaa aah ... |
correct output |
---|
30178 2 basiparachromatin marsipobranchiata 2 ... |
user output |
---|
30178 2 basiparachromatin marsipobranchiata 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 abcdeighjlfk abcdeiglhfjk abcdfkilejgh ... Truncated |
Test 6
Verdict: ACCEPTED
input |
---|
400000 cbaabghadefb hbbgfaeabdac abaedcbgfbha hcfadbbbeaag ... |
correct output |
---|
1 400000 aaabbbcfegdh aaabbbcfghed aaabbbdcgfhe ... |
user output |
---|
1 400000 aaabbbcfegdh aaabbbcfghed aaabbbdcgfhe ... 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 |