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 » May 2010 Contest » Lights Out

Lights Out

Problem code: DORADM01

  • All Submissions

All submissions for this problem are available.

Johnny is playing Lights Out, an electronic game consisting of an NxN grid of lights. Initially, each light may be on or off. Pressing a light will toggle it and the lights non-diagonally adjacent to it.

The object of the game is to try and get all the lights turned off. It is not always possible, and what's more, Johnny's game is faulty. Pressing some lights has no effect. (They can still be turned on and off if they are next to working lights.)

Help Johnny write a program that checks whether a puzzle can be solved or not, given the initial description of the grid and the positions of the faulty lights.

Input

The first line contains a number t (about 10), the number of test cases. Each test case has the following form:

The first line contains two numbers N and K (2 <= N <= 200, 0 <= K <= N). Each line in the next N lines contains N characters '0' or '1' representing the initial state of the grid. '1' denotes a light that is on and '0' a light that is off.

Each line in the next K lines contains 2 integers, i and j (1 <= i, j <= N), representing the row and column of a faulty light. Rows are numbered from the top and columns from the left.

Output

For each test case, print YES if there is a solution, otherwise print NO.

Example

Input:
2

3 1
010
111
010
2 2

4 2
1110
1110
1001
1101
2 2
4 3

Output:
NO
YES


Author: MichaelD
Date Added: 9-04-2010
Time Limit: 2 - 4 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, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Can anyone please explain the

blackBird @ 2 May 2010 01:05 AM

Can anyone please explain the following line ....

Pressing some lights has no effect. (They can still be turned on and off if they are next to working lights.) ...

What part of that sentence

triplem @ 2 May 2010 04:26 AM

What part of that sentence don't you understand? Pushing a broken light does nothing.

Can anyone tell me whether

mstriguna @ 4 May 2010 09:57 PM

Can anyone tell me whether input passed is through standard input or a text file called in.txt? I have read in two different locations which said me that the input is given in standard input format and then through the command java test < in.txt > out.txt.

Which one I should be using to test the program for this competition?

Please let me know asap.

Thanks in advance.

My program seems to be

Amlesh @ 5 May 2010 02:59 AM

My program seems to be running into a runtime error when I submit. However, it works fine at my house. Please help.

The FAQ clearly says it will

triplem @ 5 May 2010 03:00 AM

The FAQ clearly says it will be from standard input/output. The other line you are quoting was a method of testing your code locally without having to enter input at the command prompt all the time.

what's the memory limitation

pigoneand @ 6 May 2010 05:40 AM

what's the memory limitation of this problem?

@Amlesh Jayakumar: have you

anhdq_adm @ 6 May 2010 06:14 AM

@Amlesh Jayakumar: have you tried all cases of test?

@Yihe Zhu: there's no memory limit for these problems :-)

Is there any way to improve

codegambler @ 6 May 2010 01:05 PM

Is there any way to improve overall rank if so many people have same points. OR it is randon only?

1>Pressing the fault light

codegambler @ 7 May 2010 10:29 AM

1>Pressing the fault light has no effect. But can it toggle if pressing neighbour light?

2>if next mean any light neighbour to light?

A non-faulty light toggles

triplem @ 7 May 2010 10:34 AM

A non-faulty light toggles all adjacent lights, regardless of whether those adjacent lights are faulty or not.

Help!I can not understand the

liubiaoyong @ 7 May 2010 08:53 PM

Help!
I can not understand the following sentense.

"Pressing a light will toggle it and the lights non-diagonally adjacent to it. "

if the lights' status are:
111
111
111

and, press (2,2),

which one will I get ?

a)
101
010
101

b)
101
000
101

c) if other ? please type it.

It is crearly mentioned in

codegambler @ 7 May 2010 11:26 PM

It is crearly mentioned in the statement you had copy pasted.

@liubiaoyong - u will get (b)

shettynamit @ 8 May 2010 10:56 AM

@liubiaoyong - u will get (b)

@admin I am getting ":(

sam6230i @ 9 May 2010 09:39 PM

@admin

I am getting ":( internal error occurred in the system" after submitting the solution. Kindly help.

Same with me!!!!

shadow @ 9 May 2010 10:33 PM

Same with me!!!!

I have a question about it:

vdmedragon @ 10 May 2010 01:32 AM

I have a question about it: "They can still be turned on and off if they are next to working lights."

That means if someone press a faulty light , it does not affect adjacent  lights ; or if someone press a working light, it does not affect a faulty adjacent light?

I have read the statements

vdmedragon @ 10 May 2010 02:24 AM

I have read the statements again and that means: pressing faulty button has no affect to nearby buttons; and pressing working buttons have affect to the faulty buttons? It is right?

Working lights affect

Tool @ 10 May 2010 02:26 AM

Working lights affect adjacent faulty lights. Faulty lights do nothing.

I also keep getting ":(

lukash2k @ 10 May 2010 05:04 AM

I also keep getting ":( internal error occurred in the system"  when I try to submit a solution! It's happening since couple of hours.

When will the internal error

vdmedragon @ 10 May 2010 09:24 AM

When will the internal error disappear? I hate it. It is so annoying.

I wonder how people had

shadow @ 11 May 2010 10:12 PM

I wonder how people had solved this question in 0.25 sec!!!!

 

Hats off to them!!!!

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