

Need help in problem [Palindrome Pairs]
source link: http://codeforces.com/blog/entry/109100
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Hello CF family, I attempted to solve the Palindrome Pair
problem last night. I had to look at the editorial and then the solution to the problem after failing several times. I attempted in O(N2) and received TLE in the 9th TC.
void solve()
{
int n;
cin >> n;
vector<string> v(n);
loop(n)
{
cin >> v[i];
}
map<pair<string, string>, bool> store;
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j =i+1; j < n; j++)
{
if (i != j)
{
string a = v[i];
string b = v[j];
// if (store.count({a, b}) == 0 or store.count({b,a})==0)
// {
if (isPalin((a + b)))
{
ans++;
}
else
{
map<char, int> m;
loop(a.size())
{
m[a[i]]++;
}
loop(b.size())
{
m[b[i]]++;
}
int cnt = 0;
for (auto x : m)
{
if (x.second % 2 != 0)
{
cnt++;
}
}
if (cnt <= 1)
ans++;
}
// }
// store[{a, b}] = true;
// store[{b, a}] = true;
}
}
}
// ans /= 2;
cout << ans << '\n';
// debug(store);
}
But I didn't catch the idea of using the bit mask here, nor did I get the problem's editorial. So I'm seeking for someone to help me with this problem.
Thanks ( in advance )
Recommend
-
8
Leetcode Solutions (153 Part Series) This is part of a series of Leetcode solution explanations (
-
5
turzo_sawroop's blog
-
6
Need Help for one dp Problem. Need Help for one dp Problem.
-
7
Need help for a DP problem Need help for a DP problem...
-
7
Posted 2 years agoUpdated 2 months agoLeetCode /
-
13
Lucky Pairs - A possible new problem Back to General discussions forum
-
8
[Golang] Largest Palindrome Product - Problem 4 - Project Euler April 24, 2017
-
7
Palindrome Frog - A possible New Problem Back to General discussions forum...
-
7
coderbolt's blog [Help] Finding lo...
-
2
Next Palindrome - A possible New Problem Back to General discussions forum
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK