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 » February 2010 Contest » Sorting device

Sorting device

Problem code: MX

  • All Submissions

All submissions for this problem are available.

You work for a large company, and your job is to design sorting devices. Devices are built from:

  • n inputs,
  • n outputs,
  • gates which have two inputs and send to output the minimum ("min gates") or maximum ("max gates") of the two numbers given at their input,
  • connecting wires.

You are competing in a bid for a Bytelandian Ministry of Information contract to design the smallest possible device (in terms of the number of gates) which sorts any input. Each device will go through a rigorous test process on a number of data sets. However, through some Good Friends in High Places you have managed to acquire some additional information concerning the exact data sets (permutations) your device will be tested on. Make use of this, and of course your superior programming skills, to win the bid!

Input

First, two numbers, 2 <= n <= 20, 1 <= k <= 1000, the number of inputs and the number of different permutations for which your device will be tested. The next k lines contain permutations of the numbers 1 .. n.

Output

First, output p, the number of gates in your device (0 p 106). The next p lines should contain definitions of the gates used, in the form of a pair of integers, xi,yi, and exactly one of the strings "min" or "max". To be able to use the output of a gate as the input of a subsequent gate, we use the following convention. First of all, the range for inputs xi and yi is as follows: 1 <= xi,yi < n+p. The output of the i-th gate is assumed to be input n+i.

Finally, a sequence of exactly n integers in the range 1..n+p should follow, describing which of the "inputs" should be hard-wired to successive outputs of the device.

Scoring

If your program does not produce a sorting machine which works for every input (sorting it in ascending order), it will be deemed incorrect. Otherwise, you will score p penalty points for each test case solved.

Example

Input:
3 2
1 2 3
1 3 2

Output:
2
2 3 min
2 3 max
1 4 5

Score:
0.5


Author: admin
Date Added: 15-01-2010
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, 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.

This problem statement also

Brian Drake @ 1 Feb 2010 04:29 PM

This problem statement also has missing inequality signs (first sentence in the Output section).

Would it be correct to say

Brian Drake @ 1 Feb 2010 04:38 PM

Would it be correct to say that the example output is not the best possible output for the example input, because the score is 0.5 (not 1) ("Each contest will have one min/max tie breaker problem, where the best solution will receive one point ...", http://www.codechef.com/FEB10)?

The sample output may or may

triplem @ 2 Feb 2010 02:01 AM

The sample output may or may not be optimal, but the score in your output and the score for the problem are different. The lowest possible score achieved in the output is assigned a problem score of 1; the rest are proportional.

Might I ask how the inputs

pieguy @ 2 Feb 2010 07:29 AM

Might I ask how the inputs were generated?  Are n, k chosen uniformly, and all permutations random?

n,k are chosen by choosing,

izulin @ 2 Feb 2010 04:55 PM

n,k are chosen by choosing, permuations are random

I don't understand, If we

omkardanke @ 3 Feb 2010 09:21 PM

I don't understand, If we don't have to print the sorted numbers, what is the use of giving different permutations of the inputs?

 

All we need is 'n' to print the gate pattern.

 

Is this bit of information correct or have I misunderstood?

@Omkar Where the problem says

Brian Drake @ 4 Feb 2010 12:20 PM

@Omkar Where the problem says "Make use of this", they mean to focus on producing a device that works for the permutations you are given. This generally requires less gates than a device that works for every possible permutation. For example, the device represented by the sample output works for each of the permutations provided but does not work for every possible permutation. The less gates the device has, the higher your score.

+1

abhijith @ 4 Feb 2010 02:46 PM

+1

Is it possible I get Wrong

mbalunovic @ 4 Feb 2010 02:48 PM

Is it possible I get Wrong Answer when my program runs more than 1 second?

 

If your program does not produce a sorting machine which works for every input (sorting it in ascending order), it will be deemed incorrect.

 

It says nothing about TLE.

@Mislav The statement you

Brian Drake @ 4 Feb 2010 02:55 PM

@Mislav The statement you quoted applies when your program exits successfully within the time limit. Otherwise, you will get Compile Error, Run-time Error or Time Limit Exceeeded as usual.

Can I ask are there test

mbalunovic @ 6 Feb 2010 12:14 AM

Can I ask are there test cases for which answer doesn't exist?

Not in official test cases, i mean generally...

What does p penalty point for

sppraveen @ 7 Feb 2010 03:02 AM

What does p penalty point for each test case mean? I can see the best point so as 157. Does this mean he has only used 157 gates on an average for all test cases?

Yes.

triplem @ 7 Feb 2010 03:25 AM

Yes.

what is the meaning of this

codegambler @ 9 Feb 2010 02:21 PM

what is the meaning of this line?

gates which have two inputs and send to output the minimum ("min gates") or maximum ("max gates") of the two numbers given at their input,

the meaning is that: there

izulin @ 9 Feb 2010 04:37 PM

the meaning is that:

there are gates,

gates have two inputs

gates send either minimum or maximum of inputs to output (depends on gate)

sorry for this too trivial a

akantev @ 10 Feb 2010 08:35 AM

sorry for this too trivial a doubt....Each gate is characterised by xi, yi and min/max. What exactly are xi,yi? and could someone please explain how thhis is sorting..

thanks in advance

m newbie hereits my first

anant4coding @ 10 Feb 2010 04:48 PM

m newbie here

its my first time

can u please tell me how to take input

whether as .txt file or somhw else???

smbdy please tell me what xi

akantev @ 10 Feb 2010 09:14 PM

smbdy please tell me what xi and yi are in the above problem.....

It would be helpful if the

alok @ 11 Feb 2010 09:16 AM

It would be helpful if the explaination of the output os also given

There are (n + p) quantities

Brian Drake @ 11 Feb 2010 01:29 PM

There are (n + p) quantities called "inputs". Those labelled 1..n are actual inputs to the device. The "input" labelled (n + i) is the output of the ith gate. Each gate is characterised by two numbers, which are the labels of the "inputs" that the gate's inputs are connected to, and the string "min" or "max", describing what the gate does. Finally, the outputs are characterised by the labels of the "inputs" they are connected to.

If you trace the operation of the device given in the sample, with, for example, input 1 being 1, input 2 being 3 and input 3 being 2, you will find that the outputs are 1, 2 and 3, in that order, i.e. they are sorted. The device might not work for all inputs; it only needs to work for the inputs given; this may allow you to use less gates, which is your aim in this problem.

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