352 - The Seasonal War

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Tahseen Mohammad
Learning poster
Posts: 54
Joined: Sun Oct 28, 2001 2:00 am
Location: Bangladesh

Post 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.

duaxorms
New poster
Posts: 5
Joined: Sat Jul 05, 2003 7:53 am
Location: Korea
Contact:

Thanks~

Post 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... :(

duaxorms
New poster
Posts: 5
Joined: Sat Jul 05, 2003 7:53 am
Location: Korea
Contact:

Accept

Post by duaxorms »

problem is int boundary.
maximum dimension is 25. I lost this. :oops:

malf
New poster
Posts: 7
Joined: Tue Aug 17, 2004 5:43 pm

Re: You were right!!

Post 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
New poster
Posts: 7
Joined: Thu Sep 23, 2004 6:21 am

nq

Post 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]

nq
New poster
Posts: 7
Joined: Thu Sep 23, 2004 6:21 am

Post 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]

nq
New poster
Posts: 7
Joined: Thu Sep 23, 2004 6:21 am

Re: nq

Post 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]

nq
New poster
Posts: 7
Joined: Thu Sep 23, 2004 6:21 am

Post 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]

nq
New poster
Posts: 7
Joined: Thu Sep 23, 2004 6:21 am

Re: nq

Post 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]

sahand
New poster
Posts: 19
Joined: Sat Mar 12, 2005 5:56 pm
Location: Halifax, Nova Scotia, Canada
Contact:

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

Post 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!
Last edited by sahand on Wed Apr 27, 2005 3:35 pm, edited 1 time in total.

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

wrong input reading...

Post 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.

sahand
New poster
Posts: 19
Joined: Sat Mar 12, 2005 5:56 pm
Location: Halifax, Nova Scotia, Canada
Contact:

Post by sahand »

I got AC. Thanks! :D

makzanex
New poster
Posts: 2
Joined: Thu Feb 16, 2006 6:02 am

352 -WA Plesae help

Post 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.
Last edited by makzanex on Thu Feb 16, 2006 1:21 pm, edited 1 time in total.

makzanex
New poster
Posts: 2
Joined: Thu Feb 16, 2006 6:02 am

Post 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'.

SARKAR
New poster
Posts: 21
Joined: Tue May 22, 2007 4:18 pm

wa plzzzzzzzzzz help...

Post 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]

Post Reply

Return to “Volume 3 (300-399)”