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 » 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.


Author: admin
Date Added: 30-12-2009
Time Limit: 1 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.

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 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