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
    • February Long Contest
    • January CookOff
    • January Long Contest
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • 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
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » January 2010 (Contest XII) » Jawbreaker

Jawbreaker

Problem code: LX

  • All Submissions

All submissions for this problem are available.

Jawbreaker is a one-person game. You start with a square of dimension n*n, composed of small colored stones. One move consists of indicating one stone. Then, the maximal possible connected group of stones the of the same color, containing the indicated stone, is destroyed. The destroyed rocks disappear, and all rocks which have empty space below them drop to a lower row. If any column is left empty, rocks that are to the right of it are shifted accordingly to the left. When a group of k stones is destroyed, you score k2points. Your task is to maximize the total score.

Input

First, 50 <= n <= 100, the size of the starting board. Then, n lines follow, n characters long each, containing a description of the board, with up, down, left, right oriented just as we see it on a computer screen (upper rows first, left columns first). The color of each stone is described by one character, from '0' to '9'.

Output

First, output t, the length of answer. The following t pairs of integers are a sequence of moves. Each pair i,j defines one move, i being the 0-based number of a column (column 0 is the one most to the left), and j being the 0-based number of a row (row 0 is the lowest one).

Example

Input:
3
202
202
110
Output:
3
0 0
2 0
1 1
Moves:
202
202
110

..2
202
200

...
22.
22.
Score:
22+32+42

Tests

The size of the tests will be chosen uniformly between 50 and 100, and then the number of colors will be chosen uniformly between 4 and 10. The colors of the rocks are chosen independently at random.


Date: 2009-12-30
Time limit: 1

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.

1 second is too tight for the

pr0ton @ 2 Jan 2010 04:55 PM

1 second is too tight for the tiebreaker isnt it ?

I thought all future tiebreakers would have >= 5 secs.

I really feel that I'm

izulin @ 3 Jan 2010 03:17 AM

I really feel that I'm justified - input data are really small.

is there no option to delete

sumit.guha @ 3 Jan 2010 10:22 AM

is there no option to delete a commnt ??? :(

Sumit, you are not supposed

KungfuPanda @ 3 Jan 2010 10:30 AM

Sumit, you are not supposed to post ur code in the comments section. Read FAQ section for any complier issues. Admins, please remove the code from above comment.

Are the stones with same

seda @ 3 Jan 2010 04:50 PM

Are the stones with same color that have one common point (diagonally positioned) considered "connected group of stones"???

The example does not explain that either.

My solution which only prints

sppraveen @ 4 Jan 2010 12:23 AM

My solution which only prints 0 0 - It does only  this move. This takes 2.36 seconds. Any reason for this behavior.

Admin, What does wrong answer

sppraveen @ 4 Jan 2010 01:48 AM

Admin,

What does wrong answer mean in the context of this problem.

Wrong answer means your

triplem @ 4 Jan 2010 02:38 AM

Wrong answer means your output is invalid.

sorry - squares are connected

izulin @ 4 Jan 2010 06:36 AM

sorry - squares are connected if they share edge

@admin i read the faq and

sumit.guha @ 4 Jan 2010 03:31 PM

@admin

i read the faq and then tried to delete but there was no delete option.

Thanks fror deleting it

 

can you please tell me what is wrong with my piece of code???

No, this is a contest. You

triplem @ 4 Jan 2010 03:47 PM

No, this is a contest. You won't be given hints as to what you have done wrong until perhaps after the contest.

Is there an optimum solution

vikrantsingh02 @ 6 Jan 2010 12:24 PM

Is there an optimum solution for each and every test case possible,

and hence there should be same score of all the solutions?

What is to be done to get my solution accepted?

The aim of a challenge

triplem @ 6 Jan 2010 12:34 PM

The aim of a challenge problem is to score as highly as possible; achieving the optimal solution shouldn't be possible. All you need to do to get accepted is to output a value sequence of moves. Wrong answer means you are choosing a square that does not have a stone in it.

Hey...i'v a doubt. when some

bansal.prateek @ 7 Jan 2010 09:49 AM

Hey...i'v a doubt.

when some rocks dissapear and some rocks have some empty space beneath them then they fall to a "lower" level or the "lowest" level possible...

like in the case below

 

0 0 0

0 1 1

0 0 1

0 1 1

1 1 1

 

the output will be...

.......

0 0 0

0

0 0

0

 

or...

 

.......

0

0

0 0

0 0 0

 

and I hav a similar doubt about the column shift...

plz help me....

They drop as far as possible.

triplem @ 7 Jan 2010 10:28 AM

They drop as far as possible.

thanx....and what about the

bansal.prateek @ 7 Jan 2010 10:57 AM

thanx....and what about the sideway shift...do the shift to the leftmost position possible or just to one left position...

1 0 1 0 1

0 0 0 0 0

 

the output will be

.........

1 1...1

or

.........

1 1 1...

 

thanx in advance...

Same thing, All empty columns

triplem @ 7 Jan 2010 11:04 AM

Same thing, All empty columns are removed.

in that case the table

bansal.prateek @ 7 Jan 2010 11:50 AM

in that case the table shown(in the example in given question) after first move is wrong....

No it isn't. There aren't any

triplem @ 7 Jan 2010 12:33 PM

No it isn't. There aren't any empty columns, so nothing moves left.

The sample moves don't look

pieguy @ 8 Jan 2010 03:54 AM

The sample moves don't look right in a non-monospace font.  After the first move, the "2" in the top row is still all the way on the right:

..2
202
200

anyone know html tag for

izulin @ 10 Jan 2010 03:31 AM

anyone know html tag for fixed-size font?

Use <code> (with br tags in

triplem @ 10 Jan 2010 03:43 AM

Use <code> (with br tags in it).

..2
202
200

can any stone be connected

prodigyaj @ 10 Jan 2010 11:34 AM

can any stone be connected diagonally , basically is it 8 point connection or 4 point connection ?

That has already been

triplem @ 10 Jan 2010 12:51 PM

That has already been answered.

ok ! got it , thanks !!

prodigyaj @ 10 Jan 2010 01:02 PM

ok ! got it , thanks !!

The relative scores displayed

triplem @ 13 Jan 2010 02:06 AM

The relative scores displayed in the My/All submissions page appear to be incorrect (eg it is saying 0.999 rather than 0.98, etc).

my score at score board is

white_king @ 13 Jan 2010 08:04 AM

my score at score board is .961, but in my submission page it is 0.99. can you explain what is the problem?

I just mentioned that in the

triplem @ 13 Jan 2010 08:08 AM

I just mentioned that in the comment above yours :P The scoreboard is correct, the submission page is incorrect.

you = admin :P i did not

white_king @ 13 Jan 2010 04:55 PM

you = admin :P i did not refer to you, i just wanted to strengthen ur comment :)

can anybody explain me the

ankansetia @ 13 Jan 2010 09:36 PM

can anybody explain me the output in the above example plz?????

Nice, Pratik.

triplem @ 14 Jan 2010 12:56 PM

Nice, Pratik.

pieguy: a) Congrats. b) How

triplem @ 15 Jan 2010 03:00 PM

pieguy:

a) Congrats.

b) How on EARTH did you do that in 0.21 seconds?

Yes, I'm wondering about that

innocentboy @ 15 Jan 2010 03:46 PM

Yes, I'm wondering about that too. And he made only 6 submissions which means any test data based optimizations were not done. Just Brilliant work!

I think pieguy is a person

ashutoshmehra @ 15 Jan 2010 03:53 PM

I think pieguy is a person from the future ;-) Seriously, amazing work pieguy!

And Ajay, Stephen, Pratik, Josh, s.max, and Tomasz and all other algorithmic overlords did pretty well too!

Performing hundreds of

pieguy @ 15 Jan 2010 04:50 PM

Performing hundreds of submissions is no substitute for writing a better algorithm.  And although I know I could get better results by tailoring my solution to the server's specific test data, I think that defeats the purpose of the competition.  As for the 0.21 seconds, I suppose that was a bit of showboating, as I did have a algorithm that took advantage of the extra time for a 1-2% increase in score.

 

My algorithm:

Call A the most abundant colour and B the next most abundant (in my code I relabel them 0 and 1, respectively).

Step 1: remove some of colour B in such a way that all of colour A will be connected in step 3

Step 2: remove all colours except for A and B

Step 3: all of colour A is connected, remove colour A

Step 4: only colour B remains, remove it

Hm, nothing completely

triplem @ 16 Jan 2010 02:29 AM

Hm, nothing completely extraordinary then. I did something similar, though spent a lot of extra time maximising the score before only colours A + B left. Just couldn't work out a work a way of connecting A without removing too many Bs. I guess my problem was that I swapped step 1 and 2, which perhaps meant too many Bs were removed later.

I swapped step 1 and 2 as

innocentboy @ 16 Jan 2010 04:16 AM

I swapped step 1 and 2 as well.

My algorithm to connect A when only A,B were left: In each iteration I mark all components of color A, and remove the component of B which has neighbors in most number of different components of A. I break the ties by choosing the smallest component of B if there are multiple options.

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.

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