ROBOTGRI - Robots on a grid

no tags 

You have recently made a grid traversing robot that can
nd its way from the top left corner of a grid to the
bottom right corner. However, you had forgotten all your
AI programming skills, so you only programmed your robot
to go rightwards and downwards (that's after all where the
goal is). You have placed your robot on a grid with some
obstacles, and you sit and observe. However, after a while
you get tired of observing it getting stuck, and ask yourself
\How many paths are there from the start position to the
goal position?", and \If there are none, could the robot have
made it to the goal if it could walk upwards and leftwards?"
So you decide to write a program that, given a grid of
size n x n with some obstacles marked on it where the robot
cannot walk, counts the di erent ways the robot could go
from the top left corner s to the bottom right t, and if none,
tests if it were possible if it could walk up and left as well.
However, your program does not handle very large numbers, so the answer should be
given modulo 2^31 - 1.


On the rst line is one integer, 1 < n <= 1000. Then follows n lines, each with n characters,
where each character is one of '.' and '#', where '.' is to be interpreted as a walkable
tile and '#' as a non-walkable tile. There will never be a wall at s, and there will never
be a wall at t.


Output one line with the number of di erent paths starting in s and ending in t (modulo
2^31 - 1) or THE GAME IS A LIE if you cannot go from s to t going only rightwards and
downwards but you can if you are allowed to go left and up as well, or INCONCEIVABLE if
there simply is no path from s to t.


..... Output: 6

hide comments
Aditya Gourav: 2013-03-25 21:19:13

wa in 21st test case

Rocker3011: 2012-11-21 21:13:54

how does this modulo thing works? i need to do modulo each time i do something on my code? because i get tons of WA and i think it is because of that -__-

edit: yeah i knew it... btw watch out for overflows before the mod.. costed me that many WA (good combo problem :D )

Last edit: 2012-11-21 21:50:49
ɥsǝןǝǝu: 2012-10-15 15:31:19

finally TLE....

TLE: 2012-09-25 05:44:57

what about 18th test case,i m getting WA in 18th case...

♘Prabhat: 2012-08-27 18:41:10

finally AC.....

Aradhya: 2012-08-26 10:54:15

finally AC :) and ultimate problem if u want to learn bfs :D

LeppyR64: 2012-01-29 06:20:30

The answer for the sample input is definitely 6.

Nishant: 2011-12-31 13:46:49

can anyone plz explain the example ... there are 32 different ways of reaching from s to t in the given example ....

Edit: Not following the rules there aren't.

Last edit: 2012-01-29 06:20:56
LeppyR64: 2011-10-29 17:17:21

Two classic problems in one. Very nice, simple problem.

Added by:Krzysztof Lewko
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Nordic programming contest