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
    • 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 » August 2010 Challenge » Optimizing Production and Sales

Optimizing Production and Sales

Problem code: FACTORY

  • All Submissions

All submissions for this problem are available.

Your boss at the gadget company has recently asked you to help optimize operating costs. Your company is in charge of both manufacturing and selling their world-famous gadgets. Currently, there are a number of factories open in various locations around the world and each store receives their gadgets from precisely one factory.

Each factory has an associated operating cost and the cost of supplying a store from a factory is proportional to the distance between the store and factory. Your job is to close some factories and assign an open factory to each store. The cost of such an assignment is the sum of the factory operating costs of the open factories plus the total cost of assigning each store to a factory. Of course, your objective is to find a cheap solution.

To reiterate, each store must be supplied by exactly one open factory and each factory may supply any number of stores. The operating cost of the factory does not depend on how many stores it is supplying.

Input

The first line contains a single integer T ≤ 30 indicating the number of test cases to follow. The first line of each test case consists of two integers F and S, each between 1 and 100, where F is the number of factories and S is the number of stores. The next line contains F non-negative floating point values where the i'th value is the operating cost of factory i. The next S lines contain F non-negative floating point values where the i'th value on the j'th line is the cost of supplying store j with factory i.

Since the cost of supplying a store by a factory is proportional to the distance between the store and factory, you may assume that a sort of triangle inequality holds. Say d[j,i] is the cost of supplying store j from factory i. Then for any two stores j,j' and any two factories i,i' we have d[j,i] ≤ d[j,i'] + d[j',i'] + d[j',i]. To say it plainly, the shortest distance between store j and factory i is the direct route.

All floating point values are between 0 and 1000000 and contain at most two points of precision. Consecutive test cases are separated by a blank line including a blank line immediately preceding the first case.

Output

For each test case you are to output two lines. The first line consists of F values, each either 0 or 1. If the i'th value is 1 then factory i is open and if the i'th value is 0 then factory i is closed. The second line consists of S values, each between 1 and F. Here, the j'th value is the index of an open factory from which store j is supplied.

Example

Input:
2

3 3
1 2.5 3
3 1.7 1.5
1 2.1 1.2
2.1 1.4 2

2 3
0 15
4 0
4 0
4 0

Output:
1 0 1
3 1 1
1 0
1 1 1

Scoring

For each test case, let K be the cost of the solution that keeps all factories open and assigns each client to any nearest factory (i.e. the current cost of manufacturing and supplying gadgets before your, hopefully cheaper, solution is applied). We will compute the cost of your solution, say L, and assign a score of L/K to the test case (we guarantee K >= 1 for each test case). The final score is then the sum of the scores for each test case. The goal is, of course, to minimize the total score.

For example, the first test case has of K = (1 + 2.5 + 3) + (1.5 + 1 + 1.4) = 10.4 (the first set of parenthesis contains the cost of the factories and the second contains the cost of assigning stores to their cheapest factory). The output solution has L = (1 + 3) + (1.5 + 1 + 2.1) = 8.6. Therefore, the score for the first test case is 8.6/10.4 = 0.826923. Similarly, the second test case has K = (0 + 15) + (0 + 0 + 0) and the solution output has L = 0 + (4 + 4 + 4) = 12 so the score is 12/15 = 0.8.

Test Data

Some of the test data is hand-crafted to make certain heuristics perform poorly and some of the test data is randomly generated according to different distributions.


Author: friggstad
Date Added: 8-07-2010
Time Limit: 10 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.

In these types of problems,

bairathirahul @ 1 Aug 2010 10:35 PM

In these types of problems, is it necessary that the code should produce same output for sample test as it is mentioned here?

@admin: for the first test

dinemont @ 1 Aug 2010 10:44 PM

@admin:

for the first test case, isnt

1 1 0

2 1 2

a better soluton?

here the value of K will be k=(1 + 2.5)+(1.7 + 1 + 1.4) = 7.6

please xplain

It is a sample output, not

triplem @ 2 Aug 2010 02:57 AM

It is a sample output, not necessarily the best output. As long as your output is valid, it will be accepted.

You sure? In that case any

dinemont @ 2 Aug 2010 08:44 PM

You sure? In that case any solution should be right. But that doesn't seem the case.

we have to decrease the value

shivmitra @ 3 Aug 2010 12:07 AM

we have to decrease the value of L/K or we have to increase it???coz one of my solutions showed pt 28.08 and other one 6.8 so which one is better???

got it....we have to decrease

shivmitra @ 3 Aug 2010 12:25 AM

got it....we have to decrease it..

i have no idea why in the 1

RVA @ 4 Aug 2010 11:50 PM

i have no idea why in the 1 st test case 3rd factory was chosen.... is it just a sample output or the best output only tell me this....

I already did.. read the

triplem @ 5 Aug 2010 04:39 PM

I already did.. read the comments above yours.

@Stephen Merriman thanx for

RVA @ 6 Aug 2010 08:04 PM

@Stephen Merriman thanx for replying... : ^ )

@admin: Hi. I have a question

zhuxian @ 8 Aug 2010 08:30 PM

@admin:

Hi.

I have a question about ranking.

How will you deal with the situation that two or more contestants get the same point at this problem?

@zhuxian : The prizes will be

nadeemoidu @ 9 Aug 2010 03:40 PM

@zhuxian : The prizes will be shared. That has been the case earlier when no one could solve the tie breaker.

Which submission is counted

burdakovd @ 9 Aug 2010 08:50 PM

Which submission is counted for this problem, best or last?

 

Best.

triplem @ 10 Aug 2010 03:00 AM

Best.

In successful submissions for

pdwd @ 11 Aug 2010 10:12 AM

In successful submissions for this problem the last one is used (at least when you have the same number of points like 0.888, but worse detailed result).

Sorry, the best :)

pdwd @ 11 Aug 2010 10:13 AM

Sorry, the best :)

some1 plz tell me, wat test

Gaurav Panwar @ 21 Aug 2010 09:03 PM

some1 plz tell me, wat test cases exactly means?

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