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;
}
825 - Walking on the Safe Side
Moderator: Board moderators
Re: 825 - Walking on the Safe Side
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";
}
}
#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
last line of output should be an empty line
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 825 - Walking on the Safe Side
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.
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!
-
- New poster
- Posts: 1
- Joined: Mon Jul 14, 2014 10:15 pm
Re: 825 - Walking on the Safe Side
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
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 825 - Walking on the Safe Side
The outputs of two consecutive cases will be separated by a blank line.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 2
- Joined: Thu Nov 27, 2014 3:46 pm
Re: 825 - Walking on the Safe Side
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
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.
Re: 825 - Walking on the Safe Side
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
-
- New poster
- Posts: 2
- Joined: Thu Nov 27, 2014 3:46 pm
Re: 825 - Walking on the Safe Side
you 're right (Y)
thanks
thanks