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 2012 Challenge » Ambidextrous Chefs

Ambidextrous Chefs

Problem code: AMBIDEX

  • All Submissions

All submissions for this problem are available.

A recent spike in demand for competent chefs has caused the emergence of a highly specialized training program, in which chefs are trained to use 2 tools simultaneously (one in each hand). These chefs, called "ambidextrous chefs", can theoretically perform the same work as 2 ordinary chefs. The problem with these ambidextrous chefs is that their training is so specific that they cannot use any tools except for the 2 tools they can use simultaneously.

Head Chef wants to form chef teams of ambidextrous chefs. In order to form a complete team, for every tool present there must be at least one chef capable of operating it. Chef wants to create as many teams as possible, but at the same time hire as few chefs as possible. See the scoring section for details.

Input

Input begins with an integer T, the number of test cases. Each test case begins with 2 integers N and M. N is the number of different tools, and M the number of ambidextrous chefs. 2 lines follow with exactly M integers each, each between 1 and N. The i-th integer of each line indicates a tool that the i-th chef can use. It is guaranteed that the i-th integer of the first line will be different from the i-th integer of the second line. It is further guaranteed that each tool will be usable by at least one chef.

Output

For each test case, output M integers on a line, one per ambidextrous chef. The number should be 0 if the chef should not be hired. Otherwise, the number should be any positive number not exceeding 10000 to indicate the team to which that chef should be assigned. Chefs with the same team number will be assigned to the same team.

Scoring

Your score for each test case is (C*N-H)/M, where C is the number of complete chef teams formed, N is the number of tools, H is the total number of chefs hired, and M is the total number of chefs. If this value is non-positive for any test case, the submission will be judged "Wrong Answer" instead. Your score for each test file is the average of the scores for the individual test cases. Your overall score is the average of your scores on the individual test files. Note that optimal solutions are not required, but better solutions will earn more points.

Sample Input

2
5 9
5 1 5 5 1 3 4 4 1
3 2 2 3 5 1 2 2 4
8 12
6 6 8 7 1 1 6 5 3 8 7 6
2 8 1 5 8 2 7 7 1 3 4 4

Sample Output

2 2 1 3 3 1 3 2 1
2 0 1 1 2 1 0 2 2 1 2 1

The score for the first test case is (3*5-9)/9 = 0.666667, and the score for the second test case is (2*8-10)/12 = 0.5. Hence the overall score is 0.583333.

Test case generation

For each official test file, T is 10. For each test case, N is chosen randomly between 10 and 100, inclusive, and M between 200 and 1000, inclusive. Then ceiling(2*M/(N-1)) of each type of tool is placed in a sack, and one by one each of the chefs will randomly remove 2 different tools from the sack. If after all chefs have selected tools there is a tool that none of the chefs selected, the process is restarted with the same values of N and M.


Author: pieguy
Date Added: 11-10-2011
Time Limit: 6 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, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

How do you distinguish teams?

mr777 @ 1 Jan 2012 03:35 PM
How do you distinguish teams?

@mr777 See Output which says

hiroto_adm @ 1 Jan 2012 03:47 PM
@mr777 See Output which says "Chefs with the same team number will be assigned to the same team."

@hiroto_adm: "The i-th

mr777 @ 1 Jan 2012 04:16 PM
@hiroto_adm: "The i-th integer of each line indicates a tool that the i-th chef can use." For the first test case given, does this statement can be taken as, "5 and 3 tools can be used by Chef 1?"

@mr777 Yes. The 1st chef can

hiroto_adm @ 1 Jan 2012 04:21 PM
@mr777 Yes. The 1st chef can use the 5th tool and the 3rd tool in the first sample case.

@hiroto_adm: Thanks for your

mr777 @ 1 Jan 2012 04:25 PM
@hiroto_adm: Thanks for your response. Now, by taking the rule if all chefs are given the tools, how to assign teams? Like first chef can use tools 5 and 3, how will you place it in team 2?

@mr777 Read the problem

hiroto_adm @ 1 Jan 2012 05:49 PM
@mr777 Read the problem statement carefully, especially read Output section. I think it is written in the problem statement clearly.

Can anyone please explain the

mr777 @ 2 Jan 2012 05:44 PM
Can anyone please explain the criteria of hiring Chefs? I can't get how to put Chef 1 in team 2 or whatever team. What is the criteria of putting chefs in teams and getting them hired?

what if I swap all the

tangent19v_3 @ 3 Jan 2012 12:00 AM
what if I swap all the members of team 2 and team 3???? does it make any difference??? I mean if the output for first sample case becomes 3 3 1 2 2 1 2 3 1 instead of 2 2 1 3 3 1 3 2 1.

@mr777,tangent19v_3: the

cyberax @ 3 Jan 2012 04:45 AM
@mr777,tangent19v_3: the scoring process does not involve the team number given to a chef, as clearly explained in the problem statement (scoring paragraph).

Is there any bound on N and

amey9004 @ 7 Jan 2012 11:42 AM
Is there any bound on N and M?

does printing a blankline at

sreevy @ 7 Jan 2012 02:24 PM
does printing a blankline at the end of all the test case results have an impact on the answer. (Could the solution be deemed wrong because of an extra blank line at the end)?

@amey9004 See Test case

hiroto_adm @ 7 Jan 2012 02:27 PM
@amey9004 See Test case generation in the problem statement.

Isn't there a better solution

yuvraj_singla @ 7 Jan 2012 11:31 PM
Isn't there a better solution possible for test case 2??

@yuvraj_singla: Note that

david_adm @ 8 Jan 2012 01:17 AM
@yuvraj_singla: Note that optimal solutions are not required, but better solutions will earn more points. @sreevy: extra whitespace is ignored by the judge on this problem.

I don't know what's wrong

jaja @ 9 Jan 2012 08:31 PM
I don't know what's wrong with my code, so I submitted a program that prints M zeros for each test case and I get "wrong answer" - why? Is there a minimum score to pass?

@jaja See Scoring section in

hiroto_adm @ 10 Jan 2012 01:50 PM
@jaja See Scoring section in the problem statement.

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