| Task: | Anagrams |
| Sender: | kkivimaki |
| Submission time: | 2020-09-26 15:25:17 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.57 s | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | WRONG ANSWER | 1.60 s | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | TIME LIMIT EXCEEDED | -- | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | WRONG ANSWER | 0.01 s | details |
| #8 | WRONG ANSWER | 0.01 s | details |
| #9 | WRONG ANSWER | 0.01 s | details |
Compiler report
input/code.cpp: In function 'long long unsigned int h(std::__cxx11::string)':
input/code.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < s.length(); i++) {
~~^~~~~~~~~~~~Code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD ((long long)(1) << (long long)(28))
unsigned long long h(std::string s) {
sort(s.begin(), s.end());
unsigned long long m = 0;
unsigned long long t = 1;
for(int i = 0; i < s.length(); i++) {
int c = s[i];
m = (m + (c -97)*t) % MOD;
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>();
for (int i = 0; i < n; i++) {
string s;
cin >> s;
sanat.push_back(s);
}
for (int i = 0; i < n; i++) {
cout << sanat[i] << " " << h(sanat[i]) << endl;
}
sort(sanat.begin(), sanat.end(), comp);
unsigned long long v0 = h(sanat[0]);
int m = 0;
int s = 0;
for (int i = 1; i < n; i++) {
unsigned long long 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++) {
unsigned long long 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: WRONG ANSWER
| input |
|---|
| 68760 aakkonen aakkosellinen aakkosellisesti aakkosellisuus ... |
| correct output |
|---|
| 3076 2 haaraantua raahaantua 2 ... |
| user output |
|---|
| aakkonen 119465760 aakkosellinen 251098352 aakkosellisesti 46676784 aakkosellisuus 5914864 ... Truncated |
Test 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 370099 a aa aaa aah ... |
| correct output |
|---|
| 30178 2 basiparachromatin marsipobranchiata 2 ... |
| user output |
|---|
| (empty) |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 cnhmuewgnum dxkmhzhetnmxadtcy hfjqwavsiguwpludsketibe xwxolrmvkz ... |
| correct output |
|---|
| 0 |
| user output |
|---|
| cnhmuewgnum 247318234 dxkmhzhetnmxadtcy 24569976 hfjqwavsiguwpludsketibe 695449... Truncated |
Test 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 400000 vlcsa eltwde wdcwwkubs tmuxbirj ... |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 400000 ebhfigdacjlk aecfdijlhkgb jfekhbidacgl cehajbidfklg ... |
| correct output |
|---|
| 1 400000 abcdeighjlfk abcdeiglhfjk abcdfkilejgh ... |
| user output |
|---|
| (empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 400000 cbaabghadefb hbbgfaeabdac abaedcbgfbha hcfadbbbeaag ... |
| correct output |
|---|
| 1 400000 aaabbbcfegdh aaabbbcfghed aaabbbdcgfhe ... |
| user output |
|---|
| (empty) |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 1 a |
| correct output |
|---|
| 0 |
| user output |
|---|
| a 0 0 |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 2 ab ba |
| correct output |
|---|
| 1 2 ab ba |
| user output |
|---|
| ab 26 ba 26 1 2 ab ... |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 2 aa ab |
| correct output |
|---|
| 0 |
| user output |
|---|
| aa 0 ab 26 0 |
