Page 2 of 4

Posted: Sat Jan 10, 2004 2:32 pm
by Tahseen Mohammad
You should get RTE for your code. But I've learned recently that
RTE's for slight invalid memory access often results in WA.

Check this out

Code: Select all

 int image[28][28] 
and

Code: Select all

 for (i = 0; i <= 28; ++i)
  for (j = 0; j <= 28; ++j)
   image[i][j] = 0;
You are accessing "image[28][28]" :( which is an invalid memroy
location.

Thanks~

Posted: Sun Jan 11, 2004 6:41 pm
by duaxorms
thank you. :lol: It's my mistake.
I correct code.
[cpp]
int image[27][27];

...

for(i=0; i < 27; i++)
for(int j=0; j < 27; j++)
image[j] = 0;
[/cpp]

but....still WA... :(

Accept

Posted: Mon Jan 12, 2004 3:32 am
by duaxorms
problem is int boundary.
maximum dimension is 25. I lost this. :oops:

Re: You were right!!

Posted: Sun Sep 05, 2004 12:10 am
by malf
marceh wrote:Hi!
I'm one of the judge administrators...I've checked problem #352 and you were right! There was an extra empty line at the end of the input! That's not an impossible test case, and it's not there on purpose.
Whenever you notice something like that, please mail us to problemset@acm.uva.es! I can't read the whole topics in here...
I've changed the input, and I'm rejudging all submissions...
Sorry about the mistake.
Carlos.
It's working now!!

nq

Posted: Thu Sep 23, 2004 7:44 am
by nq
#include<iostream.h>
#include<stdio.h>
#include<conio.h>

int len=0,count=0,index=0;
int arr[25][25];
int nof1[50];
void cal(int,int);
void count1(void);
void fileread(void);
void filewrite(void);
void disp(void);

void main()
{
clrscr();
fileread();
filewrite();
getch();
}
void count1()
{
for(int i=0;i<len;i++)
for(int j=0;j<len;j++)
{
if(arr[j]==1)
{
count++;
cal(i,j);
arr[j]=0;
}
}
nof1[index++]=count;
cout<<count<<endl;
count=0;
}
void fileread()
{
FILE *file;
int flag=1,line=0,i=-1,j=0,temp=0;
file=fopen("c:\\data.txt","r");
char c;
c=getc(file);
while(c != EOF)
{
if(flag)
{
len = c;
len-=48;
flag=0;
}
else
{
if(c=='\n')
{
line++;
i++;
j=0;
}
if(line > len )
{
count1();
flag=1;
line=0;
i=-1;
j=0;
}
else
{
if(c=='\n');
else
{
temp=c;
temp-=48;
arr[j]=temp;
j++;
}
}
}
c=getc(file);
}
fclose(file);
}
void filewrite()
{
FILE *file;
file=fopen("c:\\save.txt","w");
for(int i=0;i<index;i++)
{
int temp=nof1;
temp+=48;
char c=temp;
putc(c,file);
putc('\n',file);
}
fclose(file);
}
void cal(int ax,int ay)
{
if(ax<len-1)
{
if(arr[ax+1][ay]==1)
{
ax++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ay<len-1)
{
if(arr[ax][ay+1]==1)
{
ay++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ax<len-1&&ay<len-1)
{
if(arr[ax+1][ay+1]==1)
{
ax++;ay++;
arr[ax][ay]=0;
cal(ax,ay);
}
}
if(ax>0)
{
if(arr[ax-1][ay]==1)
{
ax--;
arr[ax][ay]=0;
cal(ax,ay);

}
}
if(ay>0)
{
if(arr[ax][ay-1]==1)
{
ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax<len-1&&ay>0)
{
if(arr[ax+1][ay-1]==1)
{
ax++;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay<len-1)
{
if(arr[ax-1][ay+1]==1)
{
ax--;ay++;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay>0)
{
if(arr[ax-1][ay-1]==1)
{
ax--;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
}
[cpp][/cpp]

Posted: Thu Sep 23, 2004 7:56 am
by nq
[cpp]
#include<iostream.h>
#include<stdio.h>
#include<conio.h>

int len=0,count=0,index=0;
int arr[25][25];
int nof1[50];
void cal(int,int);
void count1(void);
void fileread(void);
void filewrite(void);
void disp(void);

void main()
{
clrscr();
fileread();
filewrite();
getch();
}
void count1()
{
for(int i=0;i<len;i++)
for(int j=0;j<len;j++)
{
if(arr[j]==1)
{
count++;
cal(i,j);
arr[j]=0;
}
}
nof1[index++]=count;
cout<<count<<endl;
count=0;
}
void fileread()
{
FILE *file;
int flag=1,line=0,i=-1,j=0,temp=0;
file=fopen("c:\\data.txt","r");
char c;
c=getc(file);
while(c != EOF)
{
if(flag)
{
len = c;
len-=48;
flag=0;
}
else
{
if(c=='\n')
{
line++;
i++;
j=0;
}
if(line > len )
{
count1();
flag=1;
line=0;
i=-1;
j=0;
}
else
{
if(c=='\n');
else
{
temp=c;
temp-=48;
arr[j]=temp;
j++;
}
}
}
c=getc(file);
}
fclose(file);
}
void filewrite()
{
FILE *file;
file=fopen("c:\\save.txt","w");
for(int i=0;i<index;i++)
{
int temp=nof1;
temp+=48;
char c=temp;
putc(c,file);
putc('\n',file);
}
fclose(file);
}
void cal(int ax,int ay)
{
if(ax<len-1)
{
if(arr[ax+1][ay]==1)
{
ax++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ay<len-1)
{
if(arr[ax][ay+1]==1)
{
ay++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ax<len-1&&ay<len-1)
{
if(arr[ax+1][ay+1]==1)
{
ax++;ay++;
arr[ax][ay]=0;
cal(ax,ay);
}
}
if(ax>0)
{
if(arr[ax-1][ay]==1)
{
ax--;
arr[ax][ay]=0;
cal(ax,ay);

}
}
if(ay>0)
{
if(arr[ax][ay-1]==1)
{
ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax<len-1&&ay>0)
{
if(arr[ax+1][ay-1]==1)
{
ax++;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay<len-1)
{
if(arr[ax-1][ay+1]==1)
{
ax--;ay++;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay>0)
{
if(arr[ax-1][ay-1]==1)
{
ax--;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
}
[/cpp]

Re: nq

Posted: Thu Sep 23, 2004 8:02 am
by nq
nq wrote:#include<iostream.h>
#include<stdio.h>
#include<conio.h>

int len=0,count=0,index=0;
int arr[25][25];
int nof1[50];
void cal(int,int);
void count1(void);
void fileread(void);
void filewrite(void);
void disp(void);

void main()
{
clrscr();
fileread();
filewrite();
getch();
}
void count1()
{
for(int i=0;i<len;i++)
for(int j=0;j<len;j++)
{
if(arr[j]==1)
{
count++;
cal(i,j);
arr[j]=0;
}
}
nof1[index++]=count;
cout<<count<<endl;
count=0;
}
void fileread()
{
FILE *file;
int flag=1,line=0,i=-1,j=0,temp=0;
file=fopen("c:\\data.txt","r");
char c;
c=getc(file);
while(c != EOF)
{
if(flag)
{
len = c;
len-=48;
flag=0;
}
else
{
if(c=='\n')
{
line++;
i++;
j=0;
}
if(line > len )
{
count1();
flag=1;
line=0;
i=-1;
j=0;
}
else
{
if(c=='\n');
else
{
temp=c;
temp-=48;
arr[j]=temp;
j++;
}
}
}
c=getc(file);
}
fclose(file);
}
void filewrite()
{
FILE *file;
file=fopen("c:\\save.txt","w");
for(int i=0;i<index;i++)
{
int temp=nof1;
temp+=48;
char c=temp;
putc(c,file);
putc('\n',file);
}
fclose(file);
}
void cal(int ax,int ay)
{
if(ax<len-1)
{
if(arr[ax+1][ay]==1)
{
ax++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ay<len-1)
{
if(arr[ax][ay+1]==1)
{
ay++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ax<len-1&&ay<len-1)
{
if(arr[ax+1][ay+1]==1)
{
ax++;ay++;
arr[ax][ay]=0;
cal(ax,ay);
}
}
if(ax>0)
{
if(arr[ax-1][ay]==1)
{
ax--;
arr[ax][ay]=0;
cal(ax,ay);

}
}
if(ay>0)
{
if(arr[ax][ay-1]==1)
{
ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax<len-1&&ay>0)
{
if(arr[ax+1][ay-1]==1)
{
ax++;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay<len-1)
{
if(arr[ax-1][ay+1]==1)
{
ax--;ay++;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay>0)
{
if(arr[ax-1][ay-1]==1)
{
ax--;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
}
[cpp][/cpp]

Posted: Thu Sep 23, 2004 8:21 am
by nq
nq wrote:[cpp]
#include<iostream.h>
#include<stdio.h>
#include<conio.h>

int len=0,count=0,index=0;
int arr[25][25];
int nof1[50];
void cal(int,int);
void count1(void);
void fileread(void);
void filewrite(void);
void disp(void);

void main()
{
clrscr();
fileread();
filewrite();
getch();
}
void count1()
{
for(int i=0;i<len;i++)
for(int j=0;j<len;j++)
{
if(arr[j]==1)
{
count++;
cal(i,j);
arr[j]=0;
}
}
nof1[index++]=count;
cout<<count<<endl;
count=0;
}
void fileread()
{
FILE *file;
int flag=1,line=0,i=-1,j=0,temp=0;
file=fopen("c:\\data.txt","r");
char c;
c=getc(file);
while(c != EOF)
{
if(flag)
{
len = c;
len-=48;
flag=0;
}
else
{
if(c=='\n')
{
line++;
i++;
j=0;
}
if(line > len )
{
count1();
flag=1;
line=0;
i=-1;
j=0;
}
else
{
if(c=='\n');
else
{
temp=c;
temp-=48;
arr[j]=temp;
j++;
}
}
}
c=getc(file);
}
fclose(file);
}
void filewrite()
{
FILE *file;
file=fopen("c:\\save.txt","w");
for(int i=0;i<index;i++)
{
int temp=nof1;
temp+=48;
char c=temp;
putc(c,file);
putc('\n',file);
}
fclose(file);
}
void cal(int ax,int ay)
{
if(ax<len-1)
{
if(arr[ax+1][ay]==1)
{
ax++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ay<len-1)
{
if(arr[ax][ay+1]==1)
{
ay++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ax<len-1&&ay<len-1)
{
if(arr[ax+1][ay+1]==1)
{
ax++;ay++;
arr[ax][ay]=0;
cal(ax,ay);
}
}
if(ax>0)
{
if(arr[ax-1][ay]==1)
{
ax--;
arr[ax][ay]=0;
cal(ax,ay);

}
}
if(ay>0)
{
if(arr[ax][ay-1]==1)
{
ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax<len-1&&ay>0)
{
if(arr[ax+1][ay-1]==1)
{
ax++;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay<len-1)
{
if(arr[ax-1][ay+1]==1)
{
ax--;ay++;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay>0)
{
if(arr[ax-1][ay-1]==1)
{
ax--;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
}
[/cpp]

Re: nq

Posted: Thu Sep 23, 2004 8:26 am
by nq
nq wrote:#include<iostream.h>
#include<stdio.h>
#include<conio.h>

int len=0,count=0,index=0;
int arr[25][25];
int nof1[50];
void cal(int,int);
void count1(void);
void fileread(void);
void filewrite(void);
void disp(void);

void main()
{
clrscr();
fileread();
filewrite();
getch();
}
void count1()
{
for(int i=0;i<len;i++)
for(int j=0;j<len;j++)
{
if(arr[j]==1)
{
count++;
cal(i,j);
arr[j]=0;
}
}
nof1[index++]=count;
cout<<count<<endl;
count=0;
}
void fileread()
{
FILE *file;
int flag=1,line=0,i=-1,j=0,temp=0;
file=fopen("c:\\data.txt","r");
char c;
c=getc(file);
while(c != EOF)
{
if(flag)
{
len = c;
len-=48;
flag=0;
}
else
{
if(c=='\n')
{
line++;
i++;
j=0;
}
if(line > len )
{
count1();
flag=1;
line=0;
i=-1;
j=0;
}
else
{
if(c=='\n');
else
{
temp=c;
temp-=48;
arr[j]=temp;
j++;
}
}
}
c=getc(file);
}
fclose(file);
}
void filewrite()
{
FILE *file;
file=fopen("c:\\save.txt","w");
for(int i=0;i<index;i++)
{
int temp=nof1;
temp+=48;
char c=temp;
putc(c,file);
putc('\n',file);
}
fclose(file);
}
void cal(int ax,int ay)
{
if(ax<len-1)
{
if(arr[ax+1][ay]==1)
{
ax++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ay<len-1)
{
if(arr[ax][ay+1]==1)
{
ay++;
arr[ax][ay]=0;

cal(ax,ay);

}
}
if(ax<len-1&&ay<len-1)
{
if(arr[ax+1][ay+1]==1)
{
ax++;ay++;
arr[ax][ay]=0;
cal(ax,ay);
}
}
if(ax>0)
{
if(arr[ax-1][ay]==1)
{
ax--;
arr[ax][ay]=0;
cal(ax,ay);

}
}
if(ay>0)
{
if(arr[ax][ay-1]==1)
{
ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax<len-1&&ay>0)
{
if(arr[ax+1][ay-1]==1)
{
ax++;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay<len-1)
{
if(arr[ax-1][ay+1]==1)
{
ax--;ay++;
arr[ax][ay]=0;

cal(ax,ay);
}
}
if(ax>0&&ay>0)
{
if(arr[ax-1][ay-1]==1)
{
ax--;ay--;
arr[ax][ay]=0;

cal(ax,ay);
}
}
}
[cpp][/cpp]

352 - The Seasonal War - WA - Please help!!

Posted: Tue Apr 26, 2005 12:10 am
by sahand
Another problem that I keep getting WAs on without any good reason.
I checked all the sample input on the board but no luck!
Please help me!!

Code: Select all

code removed!

wrong input reading...

Posted: Wed Apr 27, 2005 6:58 am
by sohel
There is nothing wrong with your code..
.. it's perfectly alright.

.. but there is a problem in how you are reading the input.

Consider this part..

Code: Select all

while(cin) 
   {       
      cin>>n; 
      //
    }
With the above format, you are printing a garbage value after the very last case.

Change it to

Code: Select all

while(cin>>n) 
   {       
      //

    }
And you should get Ac.

Hope it helps.

Posted: Wed Apr 27, 2005 3:35 pm
by sahand
I got AC. Thanks! :D

352 -WA Plesae help

Posted: Thu Feb 16, 2006 6:06 am
by makzanex
I've tried all the test case for 352 on this board and I can get right answer. But I don't know why I keep WA while upload to online judge. Please help.
I use BFS first and now I am using DFS, I can pass the test cases in both algorithms but still can't pass the online judge.

Thank you very much.

Code: Select all

  code deleted.

Posted: Thu Feb 16, 2006 1:19 pm
by makzanex
I get AC at last. I changed the array from integer to char. That means I checked if it is 1 and now I check if it is '1'.

wa plzzzzzzzzzz help...

Posted: Tue Jun 12, 2007 9:47 pm
by SARKAR
i have passed many test cases it is working fine plzzzzzzzz tell wat the hell went wrong

orPROVIDE ME WITH SOME CRITICL TEST CASES

Code: Select all

code removed after ac
[b] :( [/b]