11221 - Magic square palindromes.
Moderator: Board moderators
-
- New poster
- Posts: 38
- Joined: Tue Jul 17, 2007 3:21 pm
- Location: East West University
....:(
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?
Eagle er moto daana meley urbo
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.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 38
- Joined: Tue Jul 17, 2007 3:21 pm
- Location: East West University
...<
hmm if y is not perfect square then the output will be the second sample output. thanks jan vai
Eagle er moto daana meley urbo
11221 Magic Square Pallindrome. Wrong Answer
got AC.
Last edited by naffi on Mon Sep 08, 2008 5:02 pm, edited 2 times in total.
Re: 11221 - Magic square palindromes
Could anyone tell me why am i getting TLE please ???!!
here is my code, and thanx in advance

here is my code, and thanx in advance

Code: Select all
Code Removed After AC
Last edited by amr saqr on Wed May 07, 2008 10:53 pm, edited 1 time in total.
C++ Is The Best.
Re: 11221 - Magic square palindromes
Amr Saqr,
I don't know why you got TLE, but your code got AC with 0.040s after the following block is deleted.
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
Thanx so much snail,
I've already found my mistake, it was in these lines of code
After a long time of debugging
, 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.
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)

it keeps going to its UINT_MAX and it falls in an infinite loop in some certain buggy test cases,
and thanx again.
C++ Is The Best.
Re: 11221 - Magic square palindromes
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
Me too
,
anyway, as long as we're gettin Accepted, nothing else matters

anyway, as long as we're gettin Accepted, nothing else matters

C++ Is The Best.
Re: 11221 - Magic square palindromes
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....
Just putting all char in a squar dimension array..if possible then checking this 2d array ...should be mirror from both diagonals....
"Accepted" is my passion but RTE is my weakness.....
-
- New poster
- Posts: 2
- Joined: Fri Jun 12, 2009 4:14 am
Re: 11221 - Magic square palindromes
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;
}
-
- New poster
- Posts: 2
- Joined: Fri Jun 12, 2009 4:14 am
Re: 11221 - Magic square palindromes
someone pls help!!!
Re: 11221 - Magic square palindromes
U have to check whether it is palindromes or not...
Re: 11221 - Magic square palindromes
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11221 - Magic square palindromes
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.
Check input and AC output for thousands of problems on uDebug!