CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » December 2011 Long Contest » Robot Movings

Robot Movings

Problem code: MOVES

  • All Submissions

All submissions for this problem are available.

Given a square table sized NxN (3 ? N ? 5,000; rows and columns are indexed from 1) with a robot on it. The robot has a mission of moving from cell (1, 1) to cell (N, N) using only the directions "right" or "down". You are requested to find the number of different ways for the robot using exactly K turns (we define a "turn" as a right move followed immediately by a down move, or a down move followed immediately by a right move; 0 < K < 2N-2).

Input

There are several test cases (5,000 at most), each consisting of a single line containing two positive integers N, K.
The input is ended with N = K = 0.

Output

For each test case, output on a line an integer which is the result calculated. The number of ways may be very large, so compute the answer modulo 1,000,000,007.

Example

Input:
4 2
4 3
5 3
0 0

Output:
4
8
18

Explanation for the first sample test case: 4 ways are RRDDDR, RDDDRR, DRRRDD, DDRRRD ('R' or 'D' represents a right or down move respectively).


Author: anhdq
Date Added: 22-08-2011
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Thanks for explanation !

byblos @ 1 Dec 2011 03:34 PM
Thanks for explanation !

wait... does time limit

ksun48 @ 1 Dec 2011 06:10 PM
wait... does time limit exceeded mean you get it right but took too long? or could it mean you get it wrong and took too long

It takes 228 ms for my code

phantom11 @ 1 Dec 2011 06:26 PM
It takes 228 ms for my code to do some pre-calculations and then O(1) time per test case.Still getting TLE...Is everything fine with compiler

Now I have reduced the

phantom11 @ 1 Dec 2011 11:35 PM
Now I have reduced the precomputation time to 120 ms and it still gives me TLE..

@phantom11 can U plz tell me

sawank @ 2 Dec 2011 12:37 AM
@phantom11 can U plz tell me how do U calculate the computation time?

@sawank :In java use

phantom11 @ 2 Dec 2011 01:35 AM
@sawank :In java use System.currentTimeMillis() at the start and end of some loop to find the computational time of the loop and then take their difffernce

@phantom11: same problem here

piotrekg2 @ 2 Dec 2011 04:25 AM
@phantom11: same problem here :/

@ phantom test your program

tru3liar @ 2 Dec 2011 01:34 PM
@ phantom test your program by taking huge numbers as input.

@phantom11: Please refrain

gennady_adm @ 2 Dec 2011 04:27 PM
@phantom11: Please refrain from discussing any actual algorithms you used in solving the problem.

The problem says exactly k

chandu_333 @ 2 Dec 2011 06:04 PM
The problem says exactly k turns i.e right immediately followed by down or down immediately followed by right.For the first case doesnt follow that how?.Can anyone say

Will RDR count as 2 turns or

sanchit_h @ 2 Dec 2011 09:31 PM
Will RDR count as 2 turns or 1 turn ?

@sanchit 2

tj91 @ 2 Dec 2011 09:36 PM
@sanchit 2

will RDRD count as 2 turns or

nathanmelfoy @ 3 Dec 2011 01:37 AM
will RDRD count as 2 turns or 3 turns?

@nathanmelfoy: 3

cyberax @ 3 Dec 2011 05:42 AM
@nathanmelfoy: 3 turns. finally got AC. to those who wonder how to do it properly : never give up improving the efficiency of your code. it will work sooner or later.

what is Runtime Error:

avinash1 @ 3 Dec 2011 01:51 PM
what is Runtime Error: SIGKILL. it is not mentioned in FAQ

@abdukodir: Please do not

admin @ 3 Dec 2011 03:18 PM

@abdukodir: Please do not discuss input outputs during a contest. You may be banned if you do not stop doing this.

I used try and catch for

tru3liar @ 3 Dec 2011 08:41 PM
I used try and catch for IOException ...still NZEC error...ADMINS can YOU respond?

:@:@:@

rajneesh2k10 @ 5 Dec 2011 05:19 PM
:@:@:@

Sir, I submitted with correct

lallu1 @ 5 Dec 2011 06:35 PM
Sir, I submitted with correct logic but why my answer is coming wrong??

Sir, please see the last one.

lallu1 @ 5 Dec 2011 06:46 PM
Sir, please see the last one.

i'm a newbie,plz hlp cudn't

kp25 @ 5 Dec 2011 07:11 PM
i'm a newbie,plz hlp cudn't get the last statement, compute the answer modulo 1000000007 what does it mean..??

sir, please tell me what test

lallu1 @ 5 Dec 2011 08:09 PM
sir, please tell me what test case i am failing or there is some error related to the compiler i am using??

is there anyone(admin) who

lallu1 @ 5 Dec 2011 11:31 PM
is there anyone(admin) who can see what I have done.

@admin : a "turn" is a right

gaurav_saxena2000 @ 6 Dec 2011 10:00 AM
@admin : a "turn" is a right followed by a down or a down followed by a right what's the difference between them, also then how could explanation of first test case constitute of consecutive D or R.

cant find where i am

moody @ 7 Dec 2011 12:17 AM
cant find where i am wrong...its frustating!!!

there is one more way in 1st

ankit08 @ 7 Dec 2011 03:44 PM
there is one more way in 1st sample input RRDRDD

@kp25 - it means

ridder @ 7 Dec 2011 05:19 PM
@kp25 - it means answer%1000000007

why is python giving tle??

amr8 @ 7 Dec 2011 07:49 PM
why is python giving tle??

dono y getting TLE here while

dabbcomputers @ 7 Dec 2011 10:40 PM
dono y getting TLE here while it running on ideone only in 0.61s for 5000 random testcases...?

I am getting the answer for

pranjalsahu @ 8 Dec 2011 12:40 AM
I am getting the answer for given samples but on submit it is still giving wrong answer...can someone point out any critical case ...specially in case of even number of turns. Or can someone give few more samples with their correct answers.

same..i dont know why

amr8 @ 8 Dec 2011 03:21 PM
same..i dont know why tle!?!?!?

Isnt the time limit to fast

pseudopenggy @ 8 Dec 2011 05:30 PM
Isnt the time limit to fast for java users? I am using biginteger and an improved inputreader but still getting TLE.

is there any file containing

akashm @ 8 Dec 2011 07:52 PM
is there any file containing the test cases or do we have to take values through standard input... because when i am testing my java code on my computer the values returned are right but in this it is always showing wrong answer and not giving a hint about the problem

what should be minimum

dabbcomputers @ 8 Dec 2011 11:57 PM
what should be minimum complexity to crack this problem....? my code's complexity is just O(5000*2500) but getting TLE... :(

@dabbcomputers: O(5000*2500)

cyberax @ 9 Dec 2011 02:37 AM
@dabbcomputers: O(5000*2500) ~ O(1). and solving it in O(1) can't give you TLE. for sure.

there must be some prblm in

dabbcomputers @ 9 Dec 2011 12:49 PM
there must be some prblm in compiler a simple java code with complxity 500*500 showing TLE...

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com