Page 3 of 3

getting WA 825

Posted: Tue Jan 25, 2011 10:45 pm
by amin__
hello dear friends,
what is the bug in my code???
I have failed to find out...please help me...
getting wrong answer mercilessly :(

#include<cstdio>
#include<cstring>

long long mem[1000][1000];
int main()
{

int w,n,i,k,j,C,l,linef;
char str[10000],subs[10000];
scanf("%d",&C);
getchar();
linef=0;
while(C--)
{
if(linef) printf("\n");
linef=1;

scanf("%d%d",&w,&n);
//for(i=0;i<w;i++) for(j=0;j<n;j++) mem[j]=0;


mem[0][0]=1;
/*for(i=0;i<w;i++)
{
for(j=0;j<n;j++)
{
if(i==0)
mem[j]=0;
if(j==0)
mem[j]=0;
if(i&&j) mem[j]=0;
}
}*/

getchar();
for(i=0;i<w;i++)
{

gets(str);
//puts(str);

int len=strlen(str);
int howmany=0;
k=0;
for(j=0;j<len;j++)
{
if(str[j]==' ' || j==len-1)
{
if(j==len-1) subs[k++]=str[j];
subs[k]='\0';
//puts(subs);
k=0;
int sublen=strlen(subs);
int num=0;
int p=1;
for(l=sublen-1;l>=0;l--)
{
num+=(p*(subs[l]-'0'));
}
if(howmany>=1) mem[num-1]=-1;
//printf("%d\n",num);
howmany++;
}
else
{
subs[k++]=str[j];
}
}



}

for(i=1;i<n;i++)
{
if(mem[0]!=-1)
mem[0]=mem[0][i-1];
}
for(i=1;i<w;i++)
{
if(mem[0]!=-1)
mem[0]=mem[i-1][0];
}

//mem[0][0]=1;

for(i=1;i<w;i++)
{
for(j=1;j<n;j++)
{
if(mem[j]!=-1)
{
if(mem[i-1][j]==-1 && mem[i][j-1]==-1)
{
mem[i][j]=-1;
}
else if(mem[i-1][j]==-1)
{
mem[i][j]=mem[i][j-1];
}
else if(mem[i][j-1]==-1)
{
mem[i][j]=mem[i-1][j];
}
else
{
mem[i][j]=mem[i][j-1]+mem[i-1][j];
}
}
}
}



if(mem[w-1][n-1]==-1) printf("0\n");
//else if(mem[w-1][n-1]==0) printf("1\n");
else
printf("%lld\n",mem[w-1][n-1]);
//getchar();

for(i=0;i<w;i++)
{
for(j=0;j<n;j++)
{
mem[i][j]=0;
}
}

}
return 0;
}

Re: 825 - Walking on the Safe Side

Posted: Wed Mar 30, 2011 8:38 am
by rmaggon
This is my code... I am getting WA but my code is sattisfying all the test cases given in one of the post on this ques....plz help me out
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int table[200][200]={};
char str[200];
int dx,dy;
int ans=0;
void cal(int x,int y)
{
if(x==dx&&y==dy)
{
ans++;
return;
}
if(table[x][y+1]==0&&y<dy)
{

cal(x,y+1);
}
if(table[x+1][y]==0&&x<dx)
{

cal(x+1,y);
}
}
void Reset() {
int i, j;
for(i = 0; i<=dx; i++)
{
for(j = 0; j<=dy; j++)
{
table[j] = 0;
}
}
}

void ReadCase() {
int i, j;
char *p;
gets(str);
cin>>dx>>dy;
Reset();
for(i = 0; i<=dx; i++) {
gets(str);
p = strtok(str," ");
p = strtok(NULL, " ");
while(p) {
j = atoi(p);
table[i-1][j-1] = 1;
p = strtok(NULL, " ");
}
}
dx--;
dy--;
}
int main()
{
int t;
cin>>t;
while(t--)
{
ans=0;
ReadCase();
cal(0,0);
cout<<ans;
if(t!=0)
cout<<"\n\n\n";
}
}

Re: 825 - Walking on the Safe Side

Posted: Mon Jul 02, 2012 10:28 pm
by SyFy
last line of output should be an empty line :evil:

Re: 825 - Walking on the Safe Side

Posted: Wed Oct 09, 2013 11:01 pm
by brianfry713
In the judge's input:
W <= 100, N <= 100
There is always a safe path of length W + N - 1
Intersection 1 1 and W N are always safe.

Re: 825 - Walking on the Safe Side

Posted: Mon Jul 14, 2014 10:19 pm
by MohammedAnsary
This is my code for the problem and I get WA no Idea why :/

Edit: code removed after AC, wasn't printing a new line between last 2 outputs

Re: 825 - Walking on the Safe Side

Posted: Tue Jul 15, 2014 8:18 pm
by brianfry713
The outputs of two consecutive cases will be separated by a blank line.

Re: 825 - Walking on the Safe Side

Posted: Thu Nov 27, 2014 3:52 pm
by AhmedMohsen
i don't know what's wrong with my code :(
i need some help
code removed after getting AC, the mistake was in input parsing

Re: 825 - Walking on the Safe Side

Posted: Thu Nov 27, 2014 6:37 pm
by lighted
Try stringstream for input parsing

Re: 825 - Walking on the Safe Side

Posted: Thu Nov 27, 2014 9:03 pm
by AhmedMohsen
you 're right (Y)
thanks :D