Page 2 of 4

....:(

Posted: Fri Sep 21, 2007 6:37 pm
by Fuad Hassan EWU
jan vai at first i actually misunderstood the problem. now i edited my code and consider your input-output. it gives me right, bt i am still getting WA!!!!!where is the bug?

Posted: Fri Sep 21, 2007 7:09 pm
by Jan
What if y is not a perfect square? Just generate a case with 26 characters where the first 25 form a magic square palindrome. Hope it helps.

...<

Posted: Fri Sep 21, 2007 7:56 pm
by Fuad Hassan EWU
hmm if y is not perfect square then the output will be the second sample output. thanks jan vai

11221 Magic Square Pallindrome. Wrong Answer

Posted: Sun Mar 23, 2008 10:26 pm
by naffi
got AC.

Re: 11221 - Magic square palindromes

Posted: Tue May 06, 2008 7:11 am
by amr saqr
Could anyone tell me why am i getting TLE please ???!! :(
here is my code, and thanx in advance :oops:

Code: Select all

Code Removed After AC

Re: 11221 - Magic square palindromes

Posted: Wed May 07, 2008 8:56 am
by snail.123
Amr Saqr,

I don't know why you got TLE, but your code got AC with 0.040s after the following block is deleted.

Code: Select all

             if (flag)
             {
                check="";
                for (int s=input.size()-1;s>=input.size()-root;s--)
                   for (int t=s;t>=0;t-=root)
                      check+=input[t];
                if (input!=check)
                   flag=false;
             }

Re: 11221 - Magic square palindromes

Posted: Wed May 07, 2008 10:52 pm
by amr saqr
Thanx so much snail,
I've already found my mistake, it was in these lines of code

Code: Select all

for (int s=input.size()-1;s>=input.size()-root;s--)
                   for (int t=s;t>=0;t-=root)
After a long time of debugging :D, i figured out that input.size() method returns unsigned integral type so when i assign this value to signed integer (s) it's converted to unsigned, the same mistake happens also when i assign the value of (s) to (t), so (t) never reaches a negative value which makes it break the loop,
it keeps going to its UINT_MAX and it falls in an infinite loop in some certain buggy test cases,
and thanx again.

Re: 11221 - Magic square palindromes

Posted: Thu May 08, 2008 1:01 am
by snail.123
I was suspecting the same thing, but the problem states that 0<length(L)<10000, which should not be big enough to make s into a negative value. I am still confused.

Re: 11221 - Magic square palindromes

Posted: Thu May 08, 2008 1:38 am
by amr saqr
Me too :oops: ,
anyway, as long as we're gettin Accepted, nothing else matters :D

Re: 11221 - Magic square palindromes

Posted: Wed Dec 10, 2008 11:43 am
by empo
At last i got accepted..
Just putting all char in a squar dimension array..if possible then checking this 2d array ...should be mirror from both diagonals....

Re: 11221 - Magic square palindromes

Posted: Fri Jun 12, 2009 4:32 am
by codemaster
getting wa...........
#include <stdio.h>
#include <string.h>
#include <math.h>
char in[10000];
char help[10000];
char check[10000][10000];
int main()
{
int ts;
scanf("%d",&ts);
int cs=0;
while(ts)
{
cs++;
int flag=1;
ts--;
fflush(stdin);
gets(in);

int lenin=strlen(in);
int lenhelp=0;
for(int i=0;i<lenin;i++)
{
if(in>='a' && in<='z')
help[lenhelp++]=in;

}
// printf("%d\n",lenhelp);
double ck=sqrt(lenhelp);
int chk=ck;
if(ck-chk>0)
flag=0;
if(flag)
for(int i=0,k=0;i<chk;i++)
{
for(int j=0;j<chk;j++)
{
check[j]=help[k++];
}
}


if(flag)
for(int i=0,k=0;i<chk;i++)
for(int j=0;j<chk;j++)
if(check[j]!=help[k++])
{
flag=0;
break;
}
if(flag)
for(int i=chk-1,k=0;i>=0;i--)
for(int j=chk-1;j>=0;j--)
if(check[j]!=help[k++])
{
flag=0;
break;
}
if(flag)
for(int i=chk-1,k=0;i>=0;i--)
for(int j=chk-1;j>=0;j--)
if(check[j]!=help[k++])
{
flag=0;
break;
}




if(flag)
printf("Case #%d:\n%d\n",cs,chk);
else
printf("Case #%d:\nNo magic :(\n",cs);






}
return 0;

}





Re: 11221 - Magic square palindromes

Posted: Sat Jun 13, 2009 2:26 pm
by codemaster
someone pls help!!!

Re: 11221 - Magic square palindromes

Posted: Fri Sep 30, 2011 11:36 pm
by rahian
U have to check whether it is palindromes or not...

Re: 11221 - Magic square palindromes

Posted: Tue Jan 03, 2012 1:11 am
by kashius
help why WA ? :(

Code: Select all

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define TAM 10002

char word[TAM], str[TAM], A[TAM], B[TAM], C[TAM], D[TAM];
char square[TAM][TAM];

bool palindromo(int len){
    for(int i = 0, j = len-1 ; i < len && j>=0 ; ++i, j--){
        if( A[i]!=A[j] || B[i]!=B[j] || C[i]!=C[j] || D[i]!=D[j]
           || A[i]!=B[i] || A[i]!=C[i] || A[i]!=D[i])
            return false;
    }
    return true;
}


int main(){
    int i, ii, t, k, len_str;
    bool flag ;
    scanf("%d", &t);
    for(int tt = 1; tt <= t; tt++){
        fflush(stdin);
        gets(word);
        i = 0, len_str = 0;
        for(; i < strlen(word); ++i){
                if(word[i] >= 'a' && word[i] <= 'z'){
                    str[len_str] = word[i];
                    len_str++;
                }
        }
        printf("Case #%d:\n", tt);
        flag = true;
        k = (int)sqrt((double)len_str);
        if(  k*k  != len_str  ){
            printf("No magic :(\n");
        }
        else{
            for(int i = 0 ; i < len_str; ++i){
                square[i/k][i%k] = str[i];
            }

            int pos = 0;
            for(int i = 0; i < k; ++i){
                for(int j = 0; j < k ; ++j){
                    A[pos] = square[i][j];
                    pos++;
                }
            }

            pos = 0;
            for(int i = 0; i < k; ++i){
                for(int j = 0; j < k ; ++j){
                    B[pos] = square[j][i];
                    pos++;
                }
            }

            pos = 0;
            for(int i = k-1; i >= 0; --i){
                for(int j = k-1; j >= 0 ; --j){
                    C[pos] = square[i][j];
                    pos++;
                }
            }

            pos = 0;
            for(int i = k-1; i >= 0; --i){
                for(int j = k-1; j >= 0 ; --j){
                    D[pos] = square[j][i];
                    pos++;
                }
            }        
            palindromo(len_str) == true ?  printf("%d\n", k) : printf("No magic :(\n");

        }
    }
    return 0;
}

Re: 11221 - Magic square palindromes

Posted: Fri Jan 13, 2012 2:06 am
by brianfry713
The way you're reading in the input won't work. After the scanf of T, the first call to gets() is going to return an empty string. Try reading or redirecting your input from a file.