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 » Practice(medium) » Buttons

Buttons

Problem code: BUTTONS

  • Submit
  • All Submissions

Each cell of an N x N grid is either a 0 or a 1. You are given two such N x N grids, the initial grid and the final grid. There is a button against each row and each column of the initial N x N grid. Pressing a row-button toggles the values of all the cells in that row, and pressing a column-button toggles the values of all the cells in that column. You are required to find the minimum number of button presses required to transform the grid from the initial configuration to the final configuration, and the buttons that must be pressed in order to make this transformation.
Edit: When the initial and the final configurations are the same, print "0".

Input

The first line contains t, the number of test cases (about 10). Then t test cases follow.

Each test case has the following form:
* The first line contains n, the size of the board (1 ≤ n ≤ 1000).
* n lines follow. The ith line contains n space separated integers representing the ith row of the initial grid. Each integer is either a 0 or a 1.
* n lines follow, representing the final grid, in the same format as above.

Output

For each test case, output the number of row-button presses, followed by the row buttons that must be pressed. Print the number of column-button presses next, followed by 0-indexed indices of the column buttons that must be pressed. The total number of button presses must be minimized.
Output "-1" if it is impossible to achieve the final configuration from the initial configuration. If there is more than one solution, print any one of them.

Example

Input:
1
3
0 0 0
1 1 0
1 1 0
1 1 0
1 1 1
1 1 1

Output:
1
0 
1
2 


Author: admin
Date Added: 17-07-2009
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, 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.

atulbansal1111 @ 23 Jul 2009 12:54 AM

dfdfdfdfdfdf

admin 2 @ 23 Jul 2009 12:59 AM

Please don't spam the comments section.

atulbansal128 @ 24 Jul 2009 06:34 AM

I am getting correct answer on my machine. but cant clear the online judge.

admin 2 @ 24 Jul 2009 05:52 PM

The test cases are correct. You need to recheck your algorithm if you are getting a WA on the judge

nlsh82 @ 14 Aug 2009 11:28 PM

Test Cases:
4
6
0 0 0 0 0 0
1 1 1 1 1 1
1 1 1 1 1 1
0 0 0 0 0 0
0 0 0 0 0 0
1 1 1 1 1 1
0 0 1 0 1 0
0 0 1 0 1 1
1 1 0 1 0 0
1 1 0 1 0 0
0 0 1 0 1 1
0 0 1 0 1 1
3
0 0 0
1 1 0
1 1 0
1 1 1
1 1 0
1 1 0
3
0 0 0
1 1 0
1 1 0
1 1 0
1 1 1
1 1 1
4
1 0 1 0
1 1 1 1
0 1 1 0
0 0 0 1
0 0 0 0
1 0 1 0
1 1 0 0
0 1 0 0

Output:
-1
1
0
0
1
0
1
2
2
0
2
2
1
3

Its working for my test cases but giving WA on codechef. Can you confirm that output / format is correct ?

wizard @ 17 Aug 2009 04:51 AM

How should the output be when there are multiple test cases? I mean the way @nish82 specifies or should there be a blank line between two results?

What about results where only the row button needs to be pressed and there wouldn't be any column button pressed?

wizard @ 17 Aug 2009 05:19 AM

One more question, what should the output be when the initial and final grid are the same? Should it be "-1" or 0\n0 ?

nlsh82 @ 17 Aug 2009 07:44 PM

The output is one at each line ... the comment doesnt' preserve the formatting.

I too have doubt about result when (1) initial and final grid is same ... should result be 0 \n 0\n (2) initial and final grid is 1's complement of each other ... in this case pressing either all row button or all column button will give answer .... what does codechef expects ? (3) What should be output syntax fo multiple test cases ?

admin 2 @ 17 Aug 2009 09:07 PM

@Nischal Shetty: The answers for two consecutive cases must be separated by a "\n". There is no blank line required to be printed between them. When the initial and the final grids are the same, the answer is 0.

admin 2 @ 17 Aug 2009 09:09 PM

@nlsh82: From the problem statement: "If there is more than one solution, print any one of them." Answers to two consecutive test cases must be separated by a "\n".

wizard @ 17 Aug 2009 10:32 PM

@nish82

Complement is fine, you can print any one of the result since they've said when there are multiple solutions you can print any one.

As for the rest, let's hope the admin comes to our rescue ;)

myprasanna @ 17 Aug 2009 11:59 PM

@Admin: The problem statement must be fixed to incorporate your comment.
"When the initial and the final grids are the same, the answer is 0."

This explains why no body (but me), got it accepted.

admin 2 @ 18 Aug 2009 07:00 AM

@Prasanna S: When the initial and the final board configurations are the same, it is possible to reach the final board state from the initial, using 0 moves. It is evident from the problem statement that 0 is the expected answer, and not -1, which must be printed only if it is impossible to reach the final state from the initial.

myprasanna @ 18 Aug 2009 07:14 AM

@Admin: The problem is that people end up printing "0\n0\n" for that test case - while you are expecting "0\n"; Please check your test data.

Why would anyone ever print

triplem @ 18 Aug 2009 07:21 AM
Why would anyone ever print 0\n0\n? The problem statement tells you to write the number of button pushes, followed by a list of the buttons to push. If the answer was to push button 0, you would write 1\n0\n. If you don't push any buttons, you would definitely not print out a second 0; you aren't pushing button 0.. The problem statement is clear as is.

bit confused .... can admin

nlsh82 @ 18 Aug 2009 12:06 PM
bit confused .... can admin confirm the output required if my button press are following? Test case 1: row {2} col {nil} Test case 2: row{nil} col {2} Test case 3: row{nil} col {nil} 1 2 0 0 1 2 0

I second @nish82's comment

wizard @ 18 Aug 2009 12:32 PM
I second @nish82's comment above.. can you plz tell the output for the above result plzz..

@ Stephen Merriman The

abhithekid @ 18 Aug 2009 02:37 PM
@ Stephen Merriman The problem's output format says, "For each test case, output the number of row-button presses, followed by the row buttons that must be pressed. Print the number of column-button presses next, followed by 0-indexed indices of the column buttons that must be pressed." So, if the current configuration and desired configuration are the same, I would, going by the output description, print: 0 -> the number of row buttons to be pressed, then 0 lines containing the indices of the row buttons to be pressed. 0 -> the number of column buttons to be pressed, and then 0 lines containing the indices of the column buttons to be pressed.

@Abhilash I completely agree

wizard @ 18 Aug 2009 03:09 PM
@Abhilash I completely agree with you. The output to be 0 (and not 0n0) baffles me! So according to that, if a row or column isn't pressed at all then it shouldn't be part of the output! How would one ever know where the result of the first test case ends and the second one starts! (You can try @nish82's test cases, if 0 is not included for a row or column when its "nil" then how does one know when the Test Case 1 result ends and Test Case 2 result starts)

Oops, sorry, I misread the

triplem @ 18 Aug 2009 04:36 PM
Oops, sorry, I misread the problem myself. I would output two zeros as well.

 hi, how should be the output

vaidyanathan_s @ 29 Aug 2009 04:11 PM

 hi,

how should be the output if more than two buttons in a row/column are pressed ?

like:-

000

110

110

 to 

000

001

001

 

What will be the expected o/p ? the 2nd and 3rd rows have toggled.. so should the output be -

2

1 2

0

0

(or)

2

1

2

0

0

@Prasanna S: You are right.

admin @ 31 Aug 2009 03:22 PM

@Prasanna S: You are right. The problem statement has been fixed.

@Vaidyanathan S: Both will get accepted.

@CodechefDrupal->@Vaidyanatha

imransk @ 31 Aug 2009 09:17 PM

@CodechefDrupal->@Vaidyanathan:

Drupal,

Though there are no column toggles, why do we print 0 0 in the above post by Vaidyanathan?

Is it not enough to print just a zero  as

2

1

2

0

0  ( Is this zero necessary to successfully submit the problem?)

I am wondering if 0 is a

anithab @ 22 Sep 2009 11:12 PM

I am wondering if 0 is a valid input for number of testcases ? Similar case for board size. My dumb prog gives a segv there! ( and ofcourse I am going to correct it)

sorry, did not check that

anithab @ 22 Sep 2009 11:19 PM

sorry, did not check that board size lies between 1 and 1000. BTW I am assuming that number of testcases can be 0/-1/...

@Codechef Admin : Please

porsh @ 1 Oct 2009 12:55 AM

@Codechef Admin : Please compare my two solutions with ids#99931 & #99925. One has been judged as wrong answer while the other as right. However, according to me both are correct.

The difference between the codes are the line numbers 34 to 36. This part of the code just toggles the first column and first row respectively if the first element of the matrix needs to be toggled.

But, this should hardly make any difference because in both the cases, the solutions would remain the same except when the total number of toggling is exactly N, for which there would be two possible solutions and as the problem statement states that any solution with minimum total toggling would be judged as correct, both solutions should have been judged as correct.

I have tested against several

manochanikunj @ 1 Oct 2009 08:14 AM

I have tested against several test cases (boundary ones included) and I think my algorithm is correct. However, I can't seem to get a success response whenever I submit my solution.

Am I missing some important test case?

Well.. is there a way I can find out if I am missing some test case? Or as @Shishir Mittal suggests above, I am not printing the list of buttons in the sequence that the CodeCheck is expecting. How can I be sure?

How can I get a sample list of test cases?

The judge is definitely

triplem @ 1 Oct 2009 10:22 AM

The judge is definitely faulty. I only got accepted after sorting the output, ie printing the list of row buttons and the list of column buttons in increasing order. Doesn't say that anywhere in the statement, so you could try that.

If say the row button presses

kub31t @ 2 Oct 2009 05:52 AM

If say the row button presses is 1 2 and there are no column button presses required, so which of the following ways of presenting output would be accepted ?

Case (I)

2

1

2

0

Case (II)

2

1

2

0

0

Case (III)

2

1 2

0

Case (IV)

2

1 2

0

0

When intial and final

ujjwalkmr @ 8 Oct 2009 11:24 PM

When intial and final configuration are same , out put is 0.

When there is no row button press, output is 0 followed by column button presses.

 

if i have following output i can make different opinion.

0
0
1
1
0

1st:

0   #initial final same
--
0   #initial final same
--
1   #1 row button pressed
1
0   #0 column button pressed

2nd:

0   #initial final same
--
0   #0 row button pressed
1   #1 column button pressed
1
--
0   #initial final same


How do the judge find out the correct one ....

I am very confused..Please help.

@Ujjwal: The former would be

admin @ 9 Oct 2009 03:28 PM

@Ujjwal: The former would be the judge's interpretation.

@kub31t: Case I and Case III will get accepted.

@Aniruddha: So how to

ujjwalkmr @ 9 Oct 2009 07:28 PM

@Aniruddha: So how to represent the later case ?

I mean how to represent if

ujjwalkmr @ 10 Oct 2009 12:13 PM

I mean how to represent if there is no row button to press and only column buttons ? Please reply .

@Ujjwal: There is no test

admin @ 12 Oct 2009 12:49 PM

@Ujjwal: There is no test case where such a situation happens. If no button needs to pressed, print "0". If no row button needs to pressed and 2 column buttons need to be pressed, print "0 2 column_button_1 column_button_2". If no column button needs to pressed and a row button needs to pressed, print "1 row_button 0".

I am uploading a file called

pranav.modi @ 8 Nov 2009 12:48 PM

I am uploading a file called Buttons.java but it returns an error -  Class Buttons is public, should be declared in a file named Buttons.java. What could be the problem here? btw, it works fine in my IDE(Eclipse)

The class name should be

flying_ant @ 8 Nov 2009 01:46 PM

The class name should be 'Main' , upload a file Main.java or copy/paste code and change class name to 'Main' before submitting. Refer  FAQ

After pasting the test cases,

pranav.modi @ 10 Nov 2009 06:16 PM

After pasting the test cases, my program needs a carriage return to proceed. Thats how the sample program works too, so i dont think it should be a problem. Is it?

But i've checked every conceivable test case, still getting WA. You really should give the failed test case......

2 questions : like in

prodigyaj @ 20 Nov 2009 07:49 AM

2 questions :

like in nlsh82's last case , if u interchange the rows and colum number u would still end up getting the same answer , so will that be accepted ?

if say theres a solution rows = 3 and cols = 2 but u can also get rows = 2 and cols = 3 , again which is accepted ?

im getting correct results

manoj_jindal @ 28 Nov 2009 02:46 PM

im getting correct results but judge is giving WA. Can somebody give me more testcases ?

Make some up yourself. Easy

triplem @ 29 Nov 2009 04:04 PM

Make some up yourself. Easy to make up a huge number of small ones that can be checked with brute force.

Dear Admin, The judge is

arun88m @ 1 Dec 2009 01:03 AM

Dear Admin,

The judge is faulty. Even though its mentioned in the problem that all the possible solutions are accepted. Its accepting only one solution out of the two solutions obtained when the number of toggles equals n. It has to be corrected.

Hi "nlsh82 - 14th Aug,2009

murthykavali @ 7 Dec 2009 04:42 PM

Hi "nlsh82 - 14th Aug,2009 23:28:14."

Even in my case it was saying WrongAnswer Initially.

Point is for the below test case there are two outputs

one you mentioned above..(which is WA according to judge,logically both are correct)

2
0
2
2
1
3

So try to print the other answer like below..

1
4
1 0 1 0
1 1 1 1
0 1 1 0
0 0 0 1
0 0 0 0
1 0 1 0
1 1 0 0
0 1 0 0
2
1
3
2
0
2

 

Thanks

Murthy Kavali

i m still wondering , i m

prodigyaj @ 7 Dec 2009 09:16 PM

i m still wondering , i m getting all the answers same as "mlsh82's" test cases except the last one for which i m getting output as "murthy" mentioned in that format. Still getting wrong answer , i m sure my doubts about the algo should be shaken away if these test cases are giving me the answers as mentioned. So still seems to be some judging issues !!

Hi Admins, I am even facing

progfool @ 18 Dec 2009 07:56 AM

Hi Admins,

I am even facing the same problem as faced by others. I guess, the problem statement doesn't correctly specify the output format that would be accepted by the Judge. If you can, please can you elaborate on what is the exact output format accepted by the judge.

The issues being:

1. What to print when the initial and final state are same?

2. If there are multiple solutions, can we print any? Coz I guess the judge isnt configured to accept all possible solutions.

 

Regards,

Vivek

I too think checker is faulty

imrankane2005 @ 29 Dec 2009 11:11 PM

I too think checker is faulty it's accepting only one possible solution out of other's correct one possible

Admin I am getting the output

bharatj @ 30 Dec 2009 02:00 PM

Admin

I am getting the output for all the cases givem by nish82. But as Murty mentioned, for this test case

1
4
1 0 1 0
1 1 1 1
0 1 1 0
0 0 0 1
0 0 0 0
1 0 1 0
1 1 0 0
0 1 0 0

i am getting the output

2
0
2
2
1
3

which is also correct. But still i am getting WA by judge. Judge wants this answer

2
1
3
2
0
2

both are right. then y is the previous output a WA? Please help

It only means the judge

bharatj @ 30 Dec 2009 02:07 PM

It only means the judge accepts solutions done by only one specific logic and rejects other logic even though the answer may be right. Any help is apprecitated. thank you.

Yeah, it's already known as

triplem @ 30 Dec 2009 03:30 PM

Yeah, it's already known as per several earlier comments that the judge is incorrect. Hopefully they'll fix it sometime; other than that, you'll just have to try another problem.

Works fine on my pc...dnt knw

ishandoshi @ 27 Jan 2010 12:18 AM

Works fine on my pc...dnt knw hw it went wrong out here :(

I have tried all possible

amitmgkvp @ 21 Mar 2010 01:06 AM

I have tried all possible ways accordiing to the problem statements and above comments, still getting 'WA'. This is soooooo discouraging .............

plz make it more clear..

piyushbajaj @ 31 Mar 2010 01:40 AM

plz make it more clear..

@admin please mention that

madhav_iiith @ 22 Apr 2010 04:41 AM

@admin please mention that rows indices and column indices are in increasing order in the o/p which resulted in wrong answer many  times.

@admin Help!! I have tried so

kushal154 @ 9 May 2010 04:22 PM

@admin Help!! I have tried so many test cases and everytime it seems to work fine. Could you please give me the test case that is failing? If it is because of faulty judge, atleast let us know if you are going to fix it. I couldn't see any response from you since 12th Oct.

After trying all the possible

arunabh2k @ 29 May 2010 05:24 AM
After trying all the possible combinations for output, these are the stuff one should do for this problem:
1. If total number of moves are 0 then just print 0 for that case.
2. If for eg changing n number of rows bring same result as changing n number of columns, changing n number of columns will be judged correct in current judging.
@Admin, please delete this once you are done with modifying the problem statement.

cheers
Arunabh

it's an easy one!

goharshady @ 22 Aug 2010 04:44 PM

it's an easy one!

@admin:I've done the same as

Geniusguy @ 12 Sep 2010 04:15 PM

@admin:I've done the same as Arunabh Trivedi is saying in the above comment. .  . . .Bt it's still nt working :( :(

can u please suggest me what to do. . ? ?

@admin plz hv a look at my

Geniusguy @ 13 Sep 2010 06:58 PM

@admin plz hv a look at my solution. . .

http://discussed.codechef.com/showthread.php?t=1238

@admin : ???????????????????

Geniusguy @ 14 Sep 2010 07:52 PM

@admin : ???????????????????

@stephen: can u please check

Geniusguy @ 17 Sep 2010 01:11 PM

@stephen: can u please check my soltion ? ? ??

http://discussed.codechef.com/showthread.php?t=1238

 

Many of you might be

chakradarraju @ 16 Oct 2010 06:58 AM

Many of you might be struggling even with the logic right, you might have missed out some simple case....

make sure that you take care of both '0 change' case....

that was the last case which took me so long to figure out....

@Adim, As rightly pointed out

vikeshkhanna @ 26 Nov 2010 09:12 PM

@Adim,

As rightly pointed out by someone, the judge does not accept both the correct answers when the number of toggles equals 'n'. It only accepts one of the two correct answers.

@Admin, As rightly pointed

vikeshkhanna @ 26 Nov 2010 09:14 PM

@Admin,

As rightly pointed out by someone, the judge does not accept both the correct answers when the number of toggles equals 'n'. It only accepts one of the two correct answers.

@Admin- Please Check ur

tranquility @ 19 Dec 2010 12:40 PM

@Admin- Please Check ur Judge..!!

can anyone tell that do we

iiit @ 19 Jan 2011 03:58 AM

can anyone tell that do we have to first press a series of row buttons and then a series of column buttons

respond as soon as possible

can anyone tell that do we

iiit @ 19 Jan 2011 03:58 AM

can anyone tell that do we have to first press a series of row buttons and then a series of column buttons

respond as soon as possible

@garima- key press order

tranquility @ 23 Jan 2011 03:19 AM

@garima- key press order doesn't matter.

Seems the problem of judge

thechamp @ 28 Jan 2011 03:33 PM

Seems the problem of judge has not been rectified yet. Apart from above problems, judge has problem with "bool" datatype in C. it gives compilation error for my http://www.codechef.com/viewsolution/436697 solution but when i changed all my bools to int, it ran without error but asusual WA. kindly rectify the matter

There's no such thing as bool

triplem @ 29 Jan 2011 01:46 AM

There's no such thing as bool in C.. that's nothing to do with Codechef.

i can't submit my solution.

an0maly @ 4 Feb 2011 08:04 PM

i can't submit my solution. somethin's wrong with the 'submit' page :(

Thanks stephen, I later had

thechamp @ 8 Feb 2011 03:03 AM

Thanks stephen, I later had understood that fact. but the problem of WA persists, most probably because of incorrect judge. can someone confirm if judge is still faulty or was it rectified.

There is some problem for

vishal_dhiman @ 12 Mar 2011 02:37 PM

There is some problem for sure.

Any one with the correct answer please run your code for this input and please give back the output.

5
30
0 0 1 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0
0 0 1 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0
0 0 1 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0
1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1 0 1 1
1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1 0 1 1
0 0 1 0 1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 1 1 1
1 1 0 0 0 1 0 1 1 1
1 1 0 0 0 1 0 1 1 1
0 0 1 1 1 0 1 0 0 0
1 1 0 1 0 0 0 0 1 0
0 0 1 0 1 1 1 1 0 1
1 1 0 1 0 0 0 0 1 0
0 0 1 0 1 1 1 1 0 1
1 1 0 1 0 0 0 0 1 0
0 0 1 0 1 1 1 1 0 1
0 0 1 0 1 1 1 1 0 1
1 1 0 1 0 0 0 0 1 0
1 1 0 1 0 0 0 0 1 0
1 1 0 1 0 0 0 0 1 0

i will be very thankful..

:)

autocrat @ 30 Jun 2011 01:49 AM
:)

I

tranquility @ 13 Sep 2011 03:25 AM
I get. 18 0 1 3 6 8 10 11 13 15 17 18 19 20 21 22 26 27 29 10 2 4 6 8 9 13 17 19 21 25 14 5 9 10 13 14 15 16 17 18 21 23 25 27 29 12 0 5 9 17 20 21 22 23 25 26 27 29 2 1 2 0 1 2 3 2 3 4 4 1 4 6 9 4 3 5 7 9

I think the question has some

chaitu2289 @ 11 Nov 2011 12:01 PM
I think the question has some mistake. The online judge is not accepting any solution. When a problem can be solved with toggling all rows and can also be solved by toggling all columns then the online judge is accepting only the solution with toggling of columns.

Can someone else with a

ankitdbst @ 2 Jan 2012 10:41 PM
Can someone else with a correct answer print the output of @vishal_dhiman's test inputs to verify.

My output is exactly the same

twamilton @ 21 Jan 2012 11:36 PM
My output is exactly the same as @tranquility, though I am getting a WA

can someone provide hint ,How

bharatv @ 16 Feb 2012 04:42 PM
can someone provide hint ,How do i start solving the problem

My program is printing

manishpatel @ 13 Apr 2012 12:45 AM
My program is printing correct output for all the test cases listed here and i have also kept in mind that if no of toogles is equal then print column one. But its still showing wrong anwser. Can someone suggest me some tricky case with output .

Finally got accepted :) here

manishpatel @ 17 Apr 2012 10:35 AM
Finally got accepted :) here are some test cases for those getting wrong ans. 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 0 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 1 0 1 0 1 1 1 1 0 1 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 0 1 0 0 and the answers are: 0 2 0 4 1 0 2 1 3 2 0 2

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

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