Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f5c495

Browse files
authoredOct 17, 2019
Create Palindrome pairs using bitmasks.cpp
1 parent 898c90a commit 6f5c495

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
 

‎Palindrome pairs using bitmasks.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Finding pairs of strings such that they can form a palindrome after concatenation and ordering
2+
#include <bits/stdc++.h>
3+
#include <ext/rope>
4+
using namespace std;
5+
using namespace __gnu_cxx;
6+
7+
using ci = const int;
8+
using ld = long double;
9+
using llint = long long;
10+
using ullint = unsigned long long;
11+
using pii = pair <int,int>;
12+
using pcc = pair <char,char>;
13+
using pss = pair <string,string>;
14+
using vi = vector <int>;
15+
using vb = vector <bool>;
16+
using vii = vi::iterator;
17+
18+
#define INF (1<<30)
19+
#define MOD 1000000007
20+
#define mt make_tuple
21+
#define all(c) c.begin(), c.end()
22+
#define ms(name,val) memset(name, val, sizeof name)
23+
#define np nullptr
24+
25+
26+
int main()
27+
{
28+
ios_base::sync_with_stdio(0);
29+
//cin.tie(0);
30+
31+
int n;
32+
cin >> n;
33+
map <llint,int> cnt;
34+
llint ans = 0;
35+
36+
for (int t1 = 0; t1 < n; ++t1)
37+
{
38+
llint mask = 0;
39+
string s;
40+
cin >> s;
41+
42+
for (char c: s)
43+
mask ^= (1LL<<(c-'a'));
44+
45+
ans += cnt[mask];
46+
47+
for (int t2 = 0; t2 < 63; ++t2)
48+
{
49+
llint tmp = mask^(1LL<<t2);
50+
ans += cnt[tmp];
51+
}
52+
53+
++cnt[mask];
54+
}
55+
56+
cout << ans << '\n';
57+
58+
59+
return 0;
60+
}

0 commit comments

Comments
 (0)
Please sign in to comment.