این مسابقه در تاریخ پنج شنبه ۱۴ دی به صورت حضوری در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار شد.

H- Palindromic Match


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Ehsan has been invited to Ramtin’s birthday party, where he knows there will be a lot of drinks, food, and games to socialize with friends. Ramtin has a lot of games to play with, but as a good computer teacher, his games are mostly designed to test how good his students are at problem-solving. Often, in these games, one is required to be able to find a solution to a problem and to be quick in doing it.

For fairness sake, Ramtin let Ehsan pick today’s game, and so they all started playing. At the beginning of the game, there is a black box from which every participant randomly picks a string sis_i Once every one of the nn participants has chosen their string, they have to try to pair them up with each other’s string, attempting to create palindromes while doing so.

More specifically, they can choose any sis_i and sjs_j(iji \neq j) and attempt to concatenate them to make a palindrome string. The winner of the game is the fastest person who finds the exact number of ways they can create a palindrome string among all possible pairs.

Help Ehsan win the game by writing an algorithm that, given nn unique strings, calculates the number of ways a palindrome string can be constructed!

input🔗

The first line contains one integer nn, the number of players. Each of the next nn lines contains a string sis_i, the string chosen by the ii-th player.

2n1042 \leq n \leq 10^4 1si6001 \leq |s_i| \leq 600

  • Each string is unique
  • Each string is always formed by lowercase English letters

output🔗

You need to write a single line containing the number of ways we can create a palindrome string.

example🔗

sample input 1🔗

5
abcd
dcba
lls
s
sssll
Plain text

sample output 1🔗

4
Plain text

sample input 2🔗

3
bat
tab
cat
Plain text

sample output 2🔗

2
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.