A12141 | Palindrome Pairs
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so she came up with a more interesting one and she needs your help to solve it:
You are given an array of strings which consist of only small letters of the alphabet. Your task is to find how many palindrome pairs are there in the array. A palindrome pair is a pair of strings such that the following condition holds: at least one permutation of the concatenation of the two strings is a palindrome. In other words, if you have two strings, let's say "aab" and "abcac", and you concatenate them into "aababcac", we have to check if there exists a permutation of this new string such that it is a palindrome (in this case there exists the permutation "aabccbaa").
Two pairs are considered different if the strings are located on different indices. The pair of strings with indices $(i,j)$ is considered the same as the pair $(j,i)$ .
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so she came up with a more interesting one and she needs your help to solve it:
You are given an array of strings which consist of only small letters of the alphabet. Your task is to find how many palindrome pairs are there in the array. A palindrome pair is a pair of strings such that the following condition holds: at least one permutation of the concatenation of the two strings is a palindrome. In other words, if you have two strings, let's say "aab" and "abcac", and you concatenate them into "aababcac", we have to check if there exists a permutation of this new string such that it is a palindrome (in this case there exists the permutation "aabccbaa").
Two pairs are considered different if the strings are located on different indices. The pair of strings with indices $(i,j)$ is considered the same as the pair $(j,i)$ .
输入格式
The first line contains a positive integer $N$ ( $1 \le N \le 100\,000$ ), representing the length of the input array.
Eacg of the next $N$ lines contains a string (consisting of lowercase English letters from 'a' to 'z') — an element of the input array.
The total number of characters in the input array will be less than $1\,000\,000$ .
Eacg of the next $N$ lines contains a string (consisting of lowercase English letters from 'a' to 'z') — an element of the input array.
The total number of characters in the input array will be less than $1\,000\,000$ .
输出格式
Output one number, representing how many palindrome pairs there are in the array.
输入输出样例
输入 #1
3 aa bb cd
输出 #1
1
输入 #2
6 aab abcac dffe ed aa aade
输出 #2
6
The first example:
1. aa $+$ bb $\to$ abba.
The second example:
1. aab $+$ abcac $=$ aababcac $\to$ aabccbaa
2. aab $+$ aa $=$ aabaa
3. abcac $+$ aa $=$ abcacaa $\to$ aacbcaa
4. dffe $+$ ed $=$ dffeed $\to$ fdeedf
5. dffe $+$ aade $=$ dffeaade $\to$ adfaafde
6. ed $+$ aade $=$ edaade $\to$ aeddea
1. aa $+$ bb $\to$ abba.
The second example:
1. aab $+$ abcac $=$ aababcac $\to$ aabccbaa
2. aab $+$ aa $=$ aabaa
3. abcac $+$ aa $=$ abcacaa $\to$ aacbcaa
4. dffe $+$ ed $=$ dffeed $\to$ fdeedf
5. dffe $+$ aade $=$ dffeaade $\to$ adfaafde
6. ed $+$ aade $=$ edaade $\to$ aeddea
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted