Page 1 of 2

926 - Walking Around Wisely

Posted: Mon Oct 23, 2006 4:11 am
by joeluchoa
I' ve got WA and don't see my error!

This is my code:

Code: Select all

Removed after AC
Can somebody help me?

Posted: Mon Oct 23, 2006 5:38 pm
by joeluchoa
I've got AC now! :D

SOME I/O, please:

Posted: Sat Oct 28, 2006 6:36 pm
by nymo

Code: Select all

input:
====
4
3
1 1
3 3
2
2 3 S
2 2 W
3
1 1
3 3
0
3
1 1
1 1
0
30
1 1
30 30
0
my output is:

Code: Select all

3
6
1
51542064 /* This output is wrong due to 32-bit integer */
is it correct? I am getting WA. Can somebody post some more IO and check mine??? please. thanks :)

Posted: Sat Oct 28, 2006 7:34 pm
by Jan
My accepted code returns
Output:

Code: Select all

3
6
1
30067266499541040
So, use 64-bit int.

Posted: Sat Oct 28, 2006 8:09 pm
by nymo
to Jan, now I 've used long long and get the same result as you provided. but still WA. can you provide some more IO?

Posted: Sat Oct 28, 2006 9:50 pm
by Jan
You can try the following i/o set
Input:

Code: Select all

3
3
1 1
3 3
3
2 3 S
2 2 W
1 1 E
3
2 1
2 3
0
10
5 5
8 6
3
5 5 N
5 6 E
8 5 E
Output:

Code: Select all

1
1
3
Hope it helps.

Thanks Jan

Posted: Sat Oct 28, 2006 10:12 pm
by nymo
Thanks Jan, got ACC, there was small mistake in the initialization part. :oops:

Posted: Tue Nov 13, 2007 4:28 pm
by shakil
Why WA????

Code: Select all

#include<stdio.h>
long long sa[39][39],A[39][39][3],i,j,x,y,X,Y,a,b,test,n,m;
char temp[10];


int main()
{

scanf("%lld",&test);

while(test--)
{

scanf("%lld",&n);
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
{sa[i][j]=0;
 for(a=0;a<2;a++)
	 A[i][j][a]=0;
}

scanf("%lld",&x);
scanf("%lld",&y);
sa[x][y]=1;
scanf("%lld",&X);
scanf("%lld",&Y);
//scanf("%I64d %I64d",&X,&Y);

scanf("%lld",&m);
for(i=0;i<m;i++)
{
scanf("%lld %lld %s",&a,&b,temp);
if(temp[0]=='S')
A[a-1][b][0]=1;
else if(temp[0]=='W')
A[a][b-1][1]=1;
else if(temp[0]=='E')
A[a][b][1]=1;
else if(temp[0]=='N')
A[a][b][0]=1;

}


for(i=x;i<=X;i++)
for(j=y;j<=Y;j++)
if(sa[i][j]!=0)
{
if(A[i][j][0]==0)
sa[i+1][j]+=sa[i][j];
if(A[i][j][1]==0)
sa[i][j+1]+=sa[i][j];
}
printf("%lld\n",sa[X][Y]);

}


return 0;
}

Re: 926 - Walking Around Wisely

Posted: Thu Jun 05, 2008 8:24 pm
by howardcheng
I can't figure out what is wrong with my code (keeps getting WA). It's been a while since I have done these problems. Help please? Thanks.

Code: Select all

#include <stdio.h>
#include <assert.h>

#define MAX_N 30

int main(void)
{
  int C, N, Ax, Ay, Bx, By, W;
  int x, y;

  /* whether an intersection is blocked from W or S */
  int blockW[MAX_N+1][MAX_N+1], blockS[MAX_N+1][MAX_N+1];
  char dir;

  unsigned long long ways[MAX_N+1][MAX_N+1];

  scanf("%d", &C);
  while (C-- > 0) {
    scanf("%d %d %d %d %d", &N, &Ax, &Ay, &Bx, &By);
    
    assert(1 < N && N <= 30 && Ax <= Bx && Ay <= By);
    for (x = 1; x <= N; x++) {
      for (y = 1; y <= N; y++) {
	blockW[x][y] = blockS[x][y] = 0;
      }
    }
    scanf("%d", &W);
    while (W-- > 0) {
      scanf("%d %d %c", &x, &y, &dir);
      switch (dir) {
      case 'N':
	blockS[x][y+1] = 1;
	break;
      case 'S':
	blockS[x][y] = 1;
	break;
      case 'E':
	blockW[x+1][y] = 1;
	break;
      case 'W':
	blockW[x][y] = 1;
	break;
      default:
	assert(0);
      }
    }

    ways[Ax][Ay] = 1;
    for (y = Ay+1; y <= By; y++) {
      ways[Ax][y] = !blockS[Ax][y]; 
    }

    for (x = Ax+1; x <= Bx; x++) {
      for (y = Ay; y <= By; y++) {
	ways[x][y] = (blockW[x][y]) ? 0 : ways[x-1][y];
	if (y > Ay && !blockS[x][y]) {
	  ways[x][y] += ways[x][y-1];
	}
      }
    }

    printf("%lld\n", ways[Bx][By]);
  }

  return 0;
}


Re: 926 - Walking Around Wisely

Posted: Thu Jun 05, 2008 11:13 pm
by Jan
The identifier for 'unsigned long long' is '%llu'. Hope it helps.

Re: 926 - Walking Around Wisely

Posted: Thu Jun 05, 2008 11:26 pm
by howardcheng
Yes, of course. Too long since I have done C programming :(

Re: 926 - Walking Around Wisely

Posted: Fri Jun 06, 2008 9:46 am
by howardcheng
Still WA.

Re: 926 - Walking Around Wisely

Posted: Wed Jul 09, 2008 4:20 am
by joy
try this:

Code: Select all

1
3
1 1
3 3
2
2 3 S
3 2 W

Re: 926 - Walking Around Wisely

Posted: Wed Jul 09, 2008 5:39 pm
by howardcheng
My program gives "2" for the above input, which is correct as far as I can tell.

Re: 926 - Walking Around Wisely

Posted: Fri Aug 26, 2011 8:17 am
by Shafaet_du
Jan vai's i/o giving me segment fault in my ac code.