825 - Walking on the Safe Side

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

Moderator: Board moderators

amin__
New poster
Posts: 10
Joined: Thu Jul 01, 2010 10:44 am

getting WA 825

Post by amin__ » Tue Jan 25, 2011 10:45 pm

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;
}

rmaggon
New poster
Posts: 1
Joined: Wed Mar 30, 2011 8:34 am

Re: 825 - Walking on the Safe Side

Post by rmaggon » Wed Mar 30, 2011 8:38 am

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";
}
}

SyFy
New poster
Posts: 13
Joined: Tue Jun 19, 2012 12:16 pm
Location: Russia, Vladimir
Contact:

Re: 825 - Walking on the Safe Side

Post by SyFy » Mon Jul 02, 2012 10:28 pm

last line of output should be an empty line :evil:

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 825 - Walking on the Safe Side

Post by brianfry713 » Wed Oct 09, 2013 11:01 pm

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.
Check input and AC output for thousands of problems on uDebug!

MohammedAnsary
New poster
Posts: 1
Joined: Mon Jul 14, 2014 10:15 pm

Re: 825 - Walking on the Safe Side

Post by MohammedAnsary » Mon Jul 14, 2014 10:19 pm

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
Last edited by MohammedAnsary on Wed Jul 16, 2014 3:26 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 825 - Walking on the Safe Side

Post by brianfry713 » Tue Jul 15, 2014 8:18 pm

The outputs of two consecutive cases will be separated by a blank line.
Check input and AC output for thousands of problems on uDebug!

AhmedMohsen
New poster
Posts: 2
Joined: Thu Nov 27, 2014 3:46 pm

Re: 825 - Walking on the Safe Side

Post by AhmedMohsen » Thu Nov 27, 2014 3:52 pm

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
Last edited by AhmedMohsen on Thu Nov 27, 2014 9:02 pm, edited 2 times in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 825 - Walking on the Safe Side

Post by lighted » Thu Nov 27, 2014 6:37 pm

Try stringstream for input parsing
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

AhmedMohsen
New poster
Posts: 2
Joined: Thu Nov 27, 2014 3:46 pm

Re: 825 - Walking on the Safe Side

Post by AhmedMohsen » Thu Nov 27, 2014 9:03 pm

you 're right (Y)
thanks :D

Post Reply

Return to “Volume 8 (800-899)”