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 » October 2009 (Contest IX) » Forces in the crystal

Forces in the crystal

Problem code: HX

  • All Submissions

All submissions for this problem are available.

The time limit for the large test cases for this problem has been upped to 15 seconds.

Suppose that we have a crystalline triangular grid of atoms. Atoms are arranged on a regular grid, and each atom has six neighbors (unless it lies on the boundary of crystal). Each atom has an electric charge of q, and can be polarized in only one of two directions: up or down (the laws of physics in Byteland are somewhat surprising!). If two atoms are neighbors and share the same polarization, then a destructive force against the crystal occurs, whose value is equal to q1*q2. We can choose the polarization for each atom, and we would like to minimize total force working against the crystal, i.e., the sum of values of all the individual forces.

Input

First, 1000 <= n <= 2000, the size of input. Then n lines with n numbers in each follow. In the x-th line, 1 <=  x <= n, the y-th number, 1 <=  y <= n, is the charge of the atom with coordinates in the crystal equal to (x,y) if x is odd, (x,y+1/2) otherwise. For any atom at coordinates (x,y), the coordinates of the neighbors are assumed to be the following (as long as they appear in the crystal): (x-1,y-1/2),(x-1,y+1/2),(x,y-1),(x,y+1),(x+1,y-1/2),(x+1,y+1/2). Each charge q is in the range 0.1 <= q <= 1.

Output

For each atom given at input, output 0 or 1 depending on whether the polarization of the atom should be directed up or down.

Score

The score of your program is equal to the value of the force acting on the crystal. The program is tested multiple times for different data sets, and the results are averaged.

Example

Input:
3
1 2 3
4 5 6
7 8 9

Output:
0 0 0
0 0 0
0 0 1

Score:
269 = (1*2+1*4+2*3+2*5+2*4+3*6+3*5+4*5+4*7+4*8+5*6+5*8+7*8)


Date: 2009-09-22
Time limit: 10

s
Source limit: 50000
Languages: C C99 strict C++ 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 CAML CLPS PRLG WSPC BF ICK JS


  • Submit

Comments

  • Login or Register to post a comment.

"Each charge q is in the

micky1488 @ 1 Oct 2009 08:53 PM

"Each charge q is in the range 0.1 q 1"

does this mean the elements of the input matrix will lie between 0.1 and 1

but in the example they are >=1

plz explain

I think Soumya is correct --

ashutoshmehra @ 2 Oct 2009 12:52 PM
I think Soumya is correct -- either we should have 1 <= q <= 10 (going by the example), or the example is incorrect.

The example is incorrect. The

admin @ 2 Oct 2009 01:03 PM

The example is incorrect. The problem statement is fine.

A couple quick questions

ploh @ 4 Oct 2009 08:22 AM

A couple quick questions (sorry if these are answered elsewhere -- I spent some time browsing around the website but couldn't find the info):

1. Will submissions be rejudged with a different test set after the contest period ends or will the results on Oct 11 hold?

2. Which submission(s) count for the final score?

3. How many digits of precision are used in the input?

heyi did not underctand this

marutinaidu @ 4 Oct 2009 01:28 PM

heyi did not underctand this question itself

@Ploh There won't be any

admin @ 4 Oct 2009 06:33 PM

@Ploh There won't be any rejudge. Your best submission counts. You can't assume anything about the digits of precision used in the input :)

 

@kmn could you be more specific as to what you don't understand ?

@Po-Ru Loh   ad. 3: few

izulin @ 4 Oct 2009 06:49 PM

@Po-Ru Loh

 

ad. 3: few digits

Thanks for the quick

ploh @ 5 Oct 2009 12:21 AM

Thanks for the quick response!

admins can u take a look at

srinivas @ 5 Oct 2009 01:13 AM

admins can u take a look at my latest time limit exceeded submission for this problem?

Just a doubt, Is my program really running for ten seconds or is there a small mistake in the judge regarding that?

If it is running, Can you make it lot bigger? like 100 seconds or something so that it provides scope for better algorithms to be used?

There is no mistake in the

admin @ 5 Oct 2009 02:50 PM

There is no mistake in the judge :) We can't increase the time limit in the middle of the contest.

Hello, I am new to

msjaiswal @ 6 Oct 2009 06:15 PM

Hello, I am new to codechef.

What is score used is for?

 

Is this possible to find a polyniomial time solution to this problem

or

we are expected to find some solution such that lesser the score, better will be my solution?

Yes, the lesser the score,

admin @ 6 Oct 2009 06:30 PM

Yes, the lesser the score, the higher the points you get.

My submission times out even

keshav_57 @ 7 Oct 2009 03:54 PM

My submission times out even though I'm, only using scanf() and printf() for input and output (and 10^6 additions).

The time limit for the large

admin @ 7 Oct 2009 04:52 PM

The time limit for the large test cases has been upped to 15 seconds.

hen n lines with n numbers in

Shanky @ 7 Oct 2009 05:18 PM

hen n lines with n numbers in each follow. In the x-th line, 1 <=  x <= n, the y-th number, 1 <=  y <= n, is the charge of the atom with coordinates in the crystal equal to (x,y) if x is odd, (x,y+1/2) otherwise. This sounds unclear....could you just elaborate it!!

It was unclear to me also

dwitkowski @ 7 Oct 2009 10:43 PM

It was unclear to me also until I actually graphed it, then it makes sense, but then, I'm almost entirely a visual person.

In the example, 1 is at coordinates 1,1, 2 is at 1,2 and 3 is at 1,3. Since x in this case is odd, you can plot them just as they appear. For line 2 (x = 2) since x is even you would plot points 2, 1.5 for 4, 2, 2.5 for 5, and 3, 3.5 for 6, basically adding .5 to each y coordinate just as the problem states.

Do this for the next line following the same rule depending on whether x is even or odd. Graph it and you should have no problems moving on.

Are all of the testcases

jdmetz @ 8 Oct 2009 01:09 AM

Are all of the testcases randomly generated with all q randomly and uniformly distributed between 0.1 and 1.0, or were some generated with a non-uniform distribution?

Hi Anirudha, I am printing

saeed @ 8 Oct 2009 02:05 AM

Hi Anirudha,

I am printing some garbage in my soln 105186, but judge is still saying right answer. Not getting the reason.

Why was the time limit

triplem @ 8 Oct 2009 02:22 AM

Why was the time limit changed so late in the contest? I really think that was a bad idea, as everyone would have submitted based on a 10 second time limit, as most programs on these sorts of problems have the time limit coded into the program. I now have to go back and resubmit all of my earlier submissions, which I can't even do because I can't view my submission via the 'My Submissions' page.

Can the time limit please be changed back?

Also, what constitutes a

jdmetz @ 8 Oct 2009 02:33 AM

Also, what constitutes a "large" test case?  Is the time limit still 10 seconds below some cutoff value of N and 15 seconds above it?

I agree with Stephen

stolis @ 8 Oct 2009 02:52 AM

I agree with Stephen absolutely. I also consider it to be a very poor practice to change the rules in the middle of the contest.

Hello all, We received a lot

admin @ 8 Oct 2009 02:04 PM

Hello all,

We received a lot of complaints regarding the fact that the time limit was too strict and solutions which accepted input using scanf() and printed values using printf() were getting TLEd. The time limit was changed to address this fact.

@Josh We can't give out specific information regarding either the distribution or  the values of N.

@Saeeudding We will check this out. My first reaction is that the judge solution considers any non zero value to be 1.

@Stephen Sorry about that. The link will be put up soon on the MySubmissions page. However, the solutions are infact available to you via the all submissions page. In the mean while, you can download your solutions by changing the submission id. Rest assured, this will be the first issue on our to-do list.

@Jan Stola Sorry about not changing the time limit sooner. We try to keep the contest as error free as possible. Such issues however do crop up time and again. Having promised last time that we will try to keep the time limits as lenient as possible, it seemed wrong on our part to not do something about what was being reported to us.

We will try our best to see that such things do not happen in the future.

@Stephen This is now fixed.

admin @ 8 Oct 2009 02:34 PM

@Stephen This is now fixed. You can see the link on the My Submissions page.

Well, I'm afraid this is

triplem @ 8 Oct 2009 02:51 PM

Well, I'm afraid this is still rather ridiculous, and very unfair on anyone who submitted before the time limit was changed - it has ruined this contest for me. I'm very disappointed that you aren't going to change it. The last three contests all had the same problem with time limits and this was made clear to you after the contest ended, so this really should have been fixed a long time before the contest started.

At the very least it is necesssary to answer what Josh asked about what a 'large' test case, otherwise you will just get a massive number of submissions by everyone trying to figure out which cases have a time limit of 15 seconds.

 

 

We made sure that the time

admin @ 8 Oct 2009 03:21 PM

We made sure that the time limits for the other problems are as lenient as possible. The challenge problem managed to slip by as we did not think that Input / Output would be an issue for it. However, as there was still time, we thought it would be better to make amends when we could rather than continue with the low time limits. We are sorry if you feel that this contest is ruined, but would strongly encourage you to continue participating in the current contest as there is a lot of time left for it to end :) Sorry for the goof-up.

@admin: at what value of n

guptaanil2k1 @ 9 Oct 2009 10:30 AM

@admin: at what value of n test case will be considered to be large?

 

The current contest

triplem @ 11 Oct 2009 01:33 AM

The current contest scoreboard is rounding the scores for this problem so that even if one score is slightly more than another, they are being given equal places on the leaderboard. (For example, I'm currently tied with bcloud on 5.999 even though we have different scores for the challenge problem). Will the true results be based on the exact scores, and if so, can the leaderboard be fixed?

@admin: what is the exact

ron @ 11 Oct 2009 06:43 AM

@admin:

what is the exact format of INPUT numbers.

if charge q is .5,

what will be the format - .5 or 0.5 ?

and what about for value 1 ?

@Surendra I do not think that

keshav_57 @ 11 Oct 2009 10:03 AM

@Surendra

I do not think that that makes much of a difference. It is not hard to deal with it.

However, I do believe that every q has exactly one digit before decimal.

I do not have any sort of a

keshav_57 @ 11 Oct 2009 10:04 AM

I do not have any sort of a confirmation, but that is how I expect it to be (with a probability of 99.999%.

@Keshav: Thanx for reply. But

ron @ 11 Oct 2009 11:17 AM

@Keshav:

Thanx for reply.

But I don't think so. I am getting RunTimeError for a specific format.

@Admin:

Please, specify the input format

@Surendra You are ridicoulus,

izulin @ 12 Oct 2009 04:46 PM

@Surendra

You are ridicoulus, input is specified - it's floating point number!

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