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 » July 2011 Long Contest » Trial of Doom

Trial of Doom

Problem code: YALOP

  • All Submissions

All submissions for this problem are available.

Johnny has reached the final trial on the Path of Doom. This is the hardest one. He entered a large room. The floor of the room is divided into square cells of the same size. There are n rows and m columns of cells. Each cell can be either red or blue. We can consider that the walls of the room are parallel south-north direction and west-east direction and that Johnny has entered the room in the north-western corner. So now he is standing in the north-western cell of the room. The exit is in the south-eastern corner. Johnny can make steps in each of the eight directions moving to adjacent cells. He has to reach the exit. But when he goes out of the room all the cells in the room should be blue, otherwise he fails the trial (If Johnny goes out he can't step back again). The colors of the cells change after each step Johnny makes. When he steps on the next cell this cell and the cells to its north, south, east and west change color: from blue to red and from red to blue. Johnny can't ever step on two cells at once or he fails the trial. Also just jumping on the cell he is standing on now will have no effect on the color of cells. Currently some cells in the room may be red. Johnny made a look over the room and he wonders if it's even possible to pass the trial at all or the trial master is playing a trick on him. Help him find this out.

Input

The first line of input is the number of test cases. Then each of the test cases follows. The test case starts with two number n and m - the sizes of the room. The next line contains number k - the amount of red cells in the room. Next k lines consist of two numbers each x, y - the row number and column number of the following red cell. The rows are numbered from 1 to n from north to south and columns are numbered from 1 to m from west to east. So Johnny starts at cell (1, 1) and have to reach cell (n, m). The coordinates of all of the red cells will be different. The rest of the cells are blue.

Constraints

1 <= t <= 50
1 <= n, m <= 109
min(n, m) < 40
0 <= k <= min(m*n, 10000)
1 <= x <= n
1 <= y <= m

Output

For each test case print "YES" (quotes for clarity) if Johnny can reach the south-eastern cell and go out of the room with all cells being blue and "NO" (quotes for clarity) otherwise.

Example

Input:
3
2 2
0
2 2
4
1 1
1 2
2 1
2 2
4 4
1
1 1

Output:
YES
YES
NO

Explanation

In the first test case Johnny can pass the trial making the following steps: South-east, North, West, East, West, South-east, out. In the second test case: East, West, South, East, out. It's impossible to pass the trial in the third test case.


Author: spooky
Date Added: 2-05-2011
Time Limit: 5 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.

The only way for Johnny to

pr0ton @ 3 Jul 2011 09:53 AM
The only way for Johnny to exit is via cell (n,m)? Can he also exit from cell (n-1, m) or (n, m-1) (since he can go along the diagonal edge)?

Nevermind.

pr0ton @ 3 Jul 2011 09:54 AM
Nevermind.

"In the second test case:

al13n @ 3 Jul 2011 02:38 PM
"In the second test case: East, West, South, East, out." I beleive this sequence will leave all cells unchanged, i.e. red. This is how I understand it (capital letter is where Johnny is currently): Rr rr bR rb Bb bb rb Br rr rR

In my previous comment there

al13n @ 3 Jul 2011 02:43 PM
In my previous comment there are supposed to be line breaks after all Rr-like lines.

@al13n: the cell Johnny steps

ivan_adm @ 3 Jul 2011 05:03 PM
@al13n: the cell Johnny steps on changes color as well.

Neither the first case nor

snanurag @ 4 Jul 2011 11:07 PM
Neither the first case nor the second seems to leave all the cells blue to me....

I think, in second case the

snanurag @ 4 Jul 2011 11:13 PM
I think, in second case the sequence would be something like this (against the comment of al13n).......... Rr rr --> bB br --> Rr bb --> bb Rb --> rb bR --> rr rb --> out

@sranurag If I am able to

shilp_adm @ 5 Jul 2011 06:50 PM
@sranurag If I am able to follow this notation, then the sequence would be something like this for the second case.. Rr rr (EAST) bB rb (WEST) Rr bb (SOUTH) br Rr (EAST) bb bB (OUT)

@shilp_adm I think, you are

snanurag @ 6 Jul 2011 01:53 AM
@shilp_adm I think, you are right. Thanks.

i think in d 3rd case johny

suman3majee9 @ 15 Jul 2011 07:04 PM
i think in d 3rd case johny can escape. rbbb bbbb bbbb bbbb -> rbbb brbb bbbb bbbb -> bbbb brbb bbbb bbbb in this way bbbb bbbb bbrb bbbb then bbbb bbbb bbbb bbbb out

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