## 11221 - Magic square palindromes.

Moderator: Board moderators

mmfrb
New poster
Posts: 13
Joined: Thu Aug 30, 2012 3:21 pm

### Re: 11221 - Magic square palindromes

Why do I keep getting RE? Some1 help please!

Code: Select all

``REMOVED AFTER AC``
Last edited by mmfrb on Thu Aug 30, 2012 10:51 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11221 - Magic square palindromes

A line is up to 9,999 characters long.
Check input and AC output for thousands of problems on uDebug!

mmfrb
New poster
Posts: 13
Joined: Thu Aug 30, 2012 3:21 pm

### Re: 11221 - Magic square palindromes

Wow, I did not expect that kind of mistake... but i didn't have any idea a line could reach this size, now I got AC. Thank you very much!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11221 - Magic square palindromes

It's in the problem statement.
Check input and AC output for thousands of problems on uDebug!

macbon
New poster
Posts: 2
Joined: Sat Oct 06, 2012 7:27 pm

### Re: 11221 - Magic square palindromes

Problem statement is wrong. Maximum line length is 10000 not 9999!

gdisastery
New poster
Posts: 3
Joined: Sun Oct 07, 2012 11:06 pm

### Re: 11221 - Magic square palindromes

Input:

Code: Select all

``````2
:) ~ :D ~~~~ :))))))) :D :D :D
:P :P :P :P``````
AC Output:

Code: Select all

``````Case #1:
2
Case #2:
2``````

kirasan
New poster
Posts: 1
Joined: Sat Jun 15, 2013 6:04 pm

### Re: 11221 - Magic square palindromes

Someone can explain me why checking if it is palindrome is enough?
What happens if I have this sentence
"Sator mrepo tenet operm rotas"
Clearly it's palindrome, but reading up-bottom it's not the same as the original sentence.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11221 - Magic square palindromes

Case #1:
No magic

It is not enough just to check if it's a palindrome.

A magic square palindrome is a sentence whose characters can be divided in a K × K square table with the property that the original sentence can be read from the table in four different ways:

Start from the (1,1) cell, move right until the end of the line and than proceed to the next line.
Start from the (1,1) cell, move down until the end of the column and then proceed to the next column.
Start from the (K,K) cell, move left until the beginning of the line and then proceed to the previous line.
Start from the (K,K) cell, move up until the beginning of the column and then proceed to the previous column.
Check input and AC output for thousands of problems on uDebug!

thomp
New poster
Posts: 2
Joined: Wed Jun 19, 2013 9:58 am

### Re: 11221 - Magic square palindromes

No, I think kirasan is right. I spent far too long on this problem (you can see in the uHunt submission history) only to find that you get WA if you check for magic square palindromes, but you get AC if you only check that the input string is palindromic.

A separate issue: for some reason I get WA when I submit ANSI C code, but AC when I convert it to C++. Any ideas why this could be? The only thing I can think is that I'm not handling non-ASCII characters correctly but I haven't been able to write a test case that breaks the C version.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11221 - Magic square palindromes

Yes a simple check for a palindrome will get AC, but so will following the full problem statement and checking for a magic square palindrome. Your code must have had an issue with that, because mine gets AC either way.

There are some differences between the C and C++ compilers, I'd have to see your code to say why.
Check input and AC output for thousands of problems on uDebug!

thomp
New poster
Posts: 2
Joined: Wed Jun 19, 2013 9:58 am

### Re: 11221 - Magic square palindromes

Right you are, I wasn't identifying magic squares correctly. It's unfortunate that there's not a test case that is a palindrome but isn't a magic square palindrome.

rafid059
New poster
Posts: 13
Joined: Thu Feb 27, 2014 6:35 pm

### Re: 11221 - Magic square palindromes

"madam i'm adam" is a palindrome but not a square palindrome. I used this as an input at uvatoolkit.com and i got "no magic" for that.

Can someone explain why the following is a square palindrome? Do i ignore all the uppercases AND numbers AND punctuations?

sa!!!!!t,,or .ar.ep??o tenMHGJHet o())()( pe3286487325ra r{}o[]tas

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11221 - Magic square palindromes

There are no upper case letters in the judge's input.
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am

### Re: 11221 - Magic square palindromes

Code: Select all

``````Code removed after Accepted  :D  :D
``````
Last edited by Shahidul.CSE on Sat Aug 09, 2014 6:13 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
Email me: shahidul.cse.brur@gmail.com

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 11221 - Magic square palindromes

Shahidul.CSE wrote:Why WA? I tested all sample inputs on this topic. My code is always giving correct output.
Try:

Input

Code: Select all

``````2
b ex?e,)(me,!x?eb
)m!!vv m
``````
Output

Code: Select all

``````Case #1:
3
Case #2:
2
``````