All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
Given a list of strings S[ 1..N ], you need to count how many ordered pairs of strings are awesome. Given two integers i and j, such that 1 ≤ i, j ≤ n and i ≠ j, an ordered pair ( S[ i ], S[ j ] ) is called awesome if and only if concatenating S[ i ] and S[ j ] gives a palindrome.
The first line contains an integer T denoting the total number of test cases.
In each test case, the first line contains an integer N denoting the total number of strings.
Then, there are N strings, each in a separate line. They only consist of lower case characters.
For each test case, output a single line containing the answer.
- 1 <= T <= 5
- 1 <= N <= 10^6
- Sum of lengths of N strings <= 10^6
In each test case,
Input: 1 3 a ab abb Output: 2
ab|a and abb|a
|Tags||cook63, medium-hard, palindrome, rolling-hash, shangjingbo, strings, trie|
|Time Limit:||3 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.