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 » Sat Jan 10, 2004 2:32 pm

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 » Sun Jan 11, 2004 6:41 pm

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 » Mon Jan 12, 2004 3:32 am

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

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

Re: You were right!!

Post by malf » Sun Sep 05, 2004 12:10 am

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 » Thu Sep 23, 2004 7:44 am

#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 » Thu Sep 23, 2004 7:56 am

[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 » Thu Sep 23, 2004 8:02 am

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 » Thu Sep 23, 2004 8:21 am

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 » Thu Sep 23, 2004 8:26 am

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]

User avatar
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 » Tue Apr 26, 2005 12:10 am

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.

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

wrong input reading...

Post by sohel » Wed Apr 27, 2005 6:58 am

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.

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

Post by sahand » Wed Apr 27, 2005 3:35 pm

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 » Thu Feb 16, 2006 6:06 am

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 » Thu Feb 16, 2006 1:19 pm

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 » Tue Jun 12, 2007 9:47 pm

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)”