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
    • May Cook-Off
    • May Long 2012
    • April Cook-Off
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » April 2010 Contest » Flood

Flood

Problem code: FLOOD

  • All Submissions

All submissions for this problem are available.

Each year in the rainy season, the LCD province in Byteland is flooded with water. The province has the form of a rectangular land divded into unit cells of M lines and N columns. Some cells are flooded and some cells are not. Each flooded cell has a water depth level which is a positive integer.

Because of flood, the land is divided into several islands, each island consists of the cells that can move around one another but cannot move to cells in different islands. The people can move between two non flooded cells if these cells have at least one common point.

To improve the transportation quality during the flooding season, the LCD's goverment decides to raise some flooded cells to become non flooded cells so that after the process, the people are able to travel between any two non flooded cells.

To make a flooded cell whose water depth level is D become non flooded, the workers need to put in D units of clay.

The government wants to achieve the goal using the fewest units of clay possible.

Input

The first line contains t, the number of test cases (about 20), each test case has the following form.

The first line contains two number M and N (1 <= M, N <= 200).

Each line in the next M lines contain N numbers describing the status of each cell in the land. If a cell is not flooded, the corresponding number is -1 while if it is flooded the corresponding number is the cell's water depth level.

Output

For each test case, output the result in the following format.

The first line contains T, the number of units of clay used.

The second line contains a number S which is the number of flooded cells needed to raise.

Each line in the next S lines contains two numbers representing the row and column index (1-based) of a raised cell.

Scoring

For each test case, your program's score is equal to T/H in which H is the number of units of clays to raise all the flooded cell.

Example

Input
1

3 3
-1 10 -1
10 2 10
-1 10 -1

Output
2
1
2 2

This output will give score to be 2 / (10 + 10 + 2 + 10 + 10) = 1/ 21


Date: 2010-03-19
Time limit: 7

s
Source limit: 50000
Languages: C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK JS


  • Submit

Comments

  • Login or Register to post a comment.

"people are able to travel

madmaxwell @ 3 Apr 2010 02:30 AM

"people are able to travel between any two non flooded cells."

If there are 4 islands, do they need to form a connected graph (6 bridges) or only be connected to one another (4 bridges)?

Testing shows the second

jcomeau_ictx @ 3 Apr 2010 07:32 AM

Testing shows the second input line to be blank. Is the data corrupted, or the problem statement incorrect?

There is a chance that I'm wrong, but I've done numerous tests to prove this before complaining.

How are the test cases

pieguy @ 3 Apr 2010 08:40 AM

How are the test cases generated, if I may ask?  The problem also doesn't specify a bound on water depth.

Verified that 2nd line is

jcomeau_ictx @ 3 Apr 2010 10:01 AM

Verified that 2nd line is blank.

Hi, There should be a blank

writerAPR10 @ 3 Apr 2010 11:24 PM

Hi,

There should be a blank line after the number of test cases. The sample input should read:

1
3 3
-1 10 -1
10  2 10
-1 10 -1

It will be updated by the admins soon. I'm sorry for the inconvenient.

I would like to know how the

triplem @ 4 Apr 2010 02:54 PM

I would like to know how the input is generated as well.

Will ask the writer to reply

admin @ 4 Apr 2010 04:15 PM

Will ask the writer to reply as soon as I get in touch with him :)

Hi Stephen, The test cases

writerAPR10 @ 4 Apr 2010 08:00 PM

Hi Stephen,

The test cases are generated randomly, with a few handmade special cases. That's all I can say.

 

As you may guess by

writerAPR10 @ 4 Apr 2010 08:01 PM

As you may guess by submitting a naive solution, there are 22 test cases.

My algo is working absolutely

sankalp91 @ 4 Apr 2010 08:40 PM

My algo is working absolutely fine on test cases containing 200*200 cells.....still getting runtime error sigsegv!

I don't know why...

ok...now it worked but it's

sankalp91 @ 4 Apr 2010 08:58 PM

ok...now it worked

but it's showing 1pts in submission list while in the rank list it's only 0.595 pts....why??

admin plzz reply

The 1pts is incorrect. I

writerAPR10 @ 4 Apr 2010 11:17 PM

The 1pts is incorrect. I believe your point is 18.919801/ 22 (max points). Admins will look at the issue.

We still need more info on

triplem @ 5 Apr 2010 02:41 AM

We still need more info on how the input is generated; that is a vital bit of information in challenge problems (as discussed many times in the past, until Codechef started providing it every time).

Randomly how? Do you use a fixed proportion of -1 squares, and then choose random numbers between 1 and x for the remainder? If so, what proportions are used, and what is x?

Without input generation information, challenge problems become a matter of randomly guessing what the author had in mind, which isn't good. (Hand picked cases aren't normally a good idea for the same reason - if they aren't random, someone can guess how you picked them and hardcode that case into their code).

Okay, I'll try to give you a

writerAPR10 @ 5 Apr 2010 07:52 PM
Okay, I'll try to give you a more detailed answer soon.

Here's some information on

writerAPR10 @ 6 Apr 2010 12:09 AM

Here's some information on how the test case is generated:

- For each map, a distance P is handpicked. Then we generated some islands with minimum distance between each other at least P.

- The remaining flooded cells have depth randomly generated between (1,R) where R is a handpicked range varied for test cases.

I think that the info of how

writerAPR10 @ 6 Apr 2010 12:10 AM

I think that the info of how the test cases generated may help, but shouldn't help much, at least in this problem, a good program than can cover many cases can score well.

I'm not sure that this

writerAPR10 @ 6 Apr 2010 12:18 AM

I'm not sure that this information is necessary, but watch out for special cases in which there is an exact algorithm, for example when there are no more than two islands.

"each island consists of the

sppraveen @ 6 Apr 2010 04:31 PM

"each island consists of the cells that can move around one another but cannot move to cells in different islands" - what does this mean? cells move around means?

Basically it means each

writerAPR10 @ 6 Apr 2010 06:26 PM

Basically it means each island is a connected component of cells, if you like graph terminology.

Writer , I understood that

sppraveen @ 6 Apr 2010 07:28 PM

Writer , I understood that this is what implied but still the choice of words confused me. thanks

You're right, the wording is

writerAPR10 @ 6 Apr 2010 10:21 PM

You're right, the wording is a bit confusing. Apologize for that!

wirter, i have doubt Do our

idontknowisitim @ 6 Apr 2010 10:27 PM

wirter, i have doubt

Do our program output should exactly matching with actual output

as point depend on score

and score is T/H

please clear my doubt

@writer please reply

idontknowisitim @ 6 Apr 2010 10:37 PM

@writer

please reply

Of course your program needs

writerAPR10 @ 6 Apr 2010 11:32 PM

Of course your program needs not to output exactly with actual output. In fact, there's no "actual output".

Your program only needs to output any correct answer.

@writer can u plz clarify the

idontknowisitim @ 7 Apr 2010 09:13 PM

@writer

can u plz clarify the output format i m not getting it

do we have to leave one blank line after every test case output

So is there something wrong

cgy4ever @ 7 Apr 2010 10:25 PM

So is there something wrong with the scoring system?

My naive program got 1pt.

 

And I also want to know , can there be some change of DATAs?(Is this the final data?)

Technically you need to leave

writerAPR10 @ 8 Apr 2010 02:54 AM

Technically you need to leave one blank line after each case's output, but those which forgot should be still fine as the judge program won't take blank lines into account.

The test data is final.

we need to use the minimum

mandarjoshi @ 8 Apr 2010 07:47 PM

we need to use the minimum number of clay units, right? so the value of T has to be minimum. but the score is given by T/H which means, the more the value of T the higher the score. am i missing something?

i know i'll feel stupid when i read the answer!

No, you don't need to use the

akuegel @ 8 Apr 2010 08:04 PM

No, you don't need to use the minimum number of clay unit. You just need to print a solution which makes all islands connected (the fewer number of clay units you use, the better).

... And the word score in

akuegel @ 8 Apr 2010 08:07 PM

... And the word score in this problem is confusing. A lower score is better in this problem; you will get best_score / your_score points.

Hi, Adrian. But doesn't T/H

mandarjoshi @ 8 Apr 2010 08:20 PM

Hi, Adrian. But doesn't T/H indicate that my score will be higher for a higher value of T? Then how is it better to use fewer clay units? In the given test case, for instance, if I were to fill all cells with a water depth of 10, the value of T would be 40 and my score would be 40/42 which is greater than 1/21.

OK, understood. Thanks a lot!

mandarjoshi @ 8 Apr 2010 08:21 PM

OK, understood. Thanks a lot!

can second line of output

blitz @ 9 Apr 2010 07:54 PM

can second line of output become 0.

Can i know the maximum value

abhijith @ 10 Apr 2010 04:25 PM

Can i know the maximum value that depth can have ?

@ Writer ,Stephen Merriman

muke @ 10 Apr 2010 06:33 PM

@ Writer ,Stephen Merriman

can u please tell what is output format becoz i m getting wrong answer

as it is commented by Writer that

"Of course your program needs not to output exactly with actual output. In fact, there's no "actual output".

Your program only needs to output any correct answer."

please reply

The output format is clearly

triplem @ 11 Apr 2010 03:14 AM

The output format is clearly described in the problem. If you are getting wrong answer that means your answer is incorrect; ie you haven't connected all the islands.

can we output the index of

sankalp91 @ 11 Apr 2010 03:18 PM

can we output the index of the cells in any order?

Yes.

kunaljain @ 11 Apr 2010 03:26 PM

Yes.

@Admins Why is one of my

rosyish @ 13 Apr 2010 01:36 PM

@Admins

Why is one of my recent submissions in which is score 0.019 doesnt show in the list on the main page?

The whole thing itself is

abhijith @ 13 Apr 2010 02:20 PM

The whole thing itself is crapped up. I got 0.86 .. but it shows 0.838 in the Rank sheet !

The score on the my

triplem @ 13 Apr 2010 04:30 PM

The score on the my submissions page is incorrect (and has been for several contests). The one on the main contest scoreboard is correct.

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 computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various 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 judge accepts solutions in over 35+ programming languages. Online programming was 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 competitions 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 programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

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. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef 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