javacoder1's blog

By javacoder1, history, 9 years ago, In English

Hey i am getting wrong answer on amazing maze http://www.spoj.com/problems/DCEPC701/

my code http://ideone.com/B62iqc I am unable to find the error.Hope someone help me.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 years ago, # |
Rev. 4   Vote: I like it +3 Vote: I do not like it

http://ideone.com/yOiFFG

I think, answer shouldn't be 0 there

UPD: changed this:

           if(nm[nx][ny]=='#' && temp.dist+1>=arr[nx][ny])
            pq.push(mp(temp.dist+1,nx,ny));
           if(nm[nx][ny]=='.')
            pq.push(mp(temp.dist+1,nx,ny));

to this:

           if(nm[nx][ny]=='#')
           {
	    if (temp.dist+1>=arr[nx][ny])
            pq.push(mp(temp.dist+1,nx,ny));
            else
            pq.push(mp(arr[nx][ny],nx,ny));
      	   } else

           if(nm[nx][ny]=='.')
            pq.push(mp(temp.dist+1,nx,ny));

and got AC.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can i get your AC CODE. Also plaese explain in brief the changes?

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      http://ideone.com/mcT8Kx

      Let's watch on example

      ..#..

      0 0 100 0 0

      When your code comes to (0,1) temp.dist is equal to 1, so u can't go to (0,2) in your code, because temp.dist+1 < arr[nx][ny].

      But you have to go to it, when time will be equal to 100, so we have to push mp(arr[nx][ny],nx,ny) in that case.