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 CookOff
    • February Long Contest
    • January CookOff
  • 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 » May 2009 (Contest III) » Swapping mismatches

Swapping mismatches

Problem code: C1

  • All Submissions

All submissions for this problem are available.

You are given a sequence w of integers. A mismatch is any such pair of neighbouring elements of sequence w[i] and w[i+1], that w[i]>w[i+1]+1.
As long as there is any mismatch, you solve it by swapping the mismatching numbers. Given an input sequence, calculate one of the possible output mismatch-less sequences obtained by successively solving mistmatches by swapping.

Input

First - 1<=t<=10 - the number of tests. For each test: first - 1<=n<=100000. Then, n nonnegative integers.

Output

For each test, you should output exactly n integers.

Example

Input:
2
4
4 3 2 1
4
4 3 1 2

Output:
4 3 2 1
1 4 3 2

Date: 2009-04-20
Time limit: 1s
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 HASK CAML CLPS PRLG WSPC BF ICK TEXT


  • Submit

Comments

  • Login or Register to post a comment.

harshmoorjani @ 2 May 2009 05:21 AM

Ok, am getting a feeling that something is wrong with this problem... Its saying Timeout for my linear solution. Can someone please verify?

lokesh_nitw @ 3 May 2009 02:40 AM

can u explain the second output ?

deependu @ 3 May 2009 05:45 AM

ya it is like this
Anyone please Correct me if I am wrong. This is what I have understood.
The input sequence is
--->4 3 1 2
pair (3 1) are mismatch so they swap, now the sequence become
---->4 1 3 2
pair (4 1) are mismatch so they swap, now the sequence become
---->1 4 3 2
now no pair is mismatch.
this concludes to the final answer.

devanshu17 @ 4 May 2009 02:43 AM

The question reports that the time limit is 1s. But accepted answers have time limit beyond this. Can someone please explain what is exactly the time efficency criteria??

sandeep_patra @ 4 May 2009 07:38 AM

guys plz help me....
should the input takes unsigned long or ve integer means just 2^31 -1
or it should take 2^32 -1 value also

sandeep_patra @ 4 May 2009 08:44 AM

please help me guys...
first of all what does "t" means here "the number of tests" ???
if so how could it be (-1

lokesh_nitw @ 4 May 2009 06:22 PM

sandeep> its not "-1" it is "-" dash symbol

lokesh_nitw @ 4 May 2009 10:54 PM

can any one help me, i am getting correct out put , but it is displaying wrong, i cant understand , i applied on 1000 numbers and checked it.//

chiku @ 5 May 2009 06:52 PM

Hi All,
I have got correct answer too.... But i really dot understand why it says wrong answer. I tried possible test case inputs. Can somebody please help?

prunthaban @ 6 May 2009 02:11 AM

@Srikanth The contest is still running and asking for help is not right.

chiku @ 6 May 2009 02:35 AM

@Prunthaban K
thanks for reminding me.... :)

vinocit @ 6 May 2009 11:39 PM

"calculate one of the possible output mismatch-less sequences obtained by successively solving mistmatches by swapping."

Does this mean any sequence that doesn't have mismatch and exclusively contains all the elements given in the list?

tryitn1 @ 9 May 2009 11:58 AM

are the numbers unique ?

pinkeshjain @ 9 May 2009 04:10 PM

"Given an input sequence, calculate one of the possible output mismatch-less sequences obtained by successively solving mistmatches by swapping"

...Doesn't a sorted list (ascending) match one of the possible outputs not having any mismatches? Based on the requirements mentioned, the sorted list should also be an acceptable solution.

Pls confirm.
Thanks...

punbhatia @ 9 May 2009 05:36 PM

Pinkesh, I dont think that's correct. Consider the sequence
4 5 6 2 1
the sorted seq in ascending order would be: 1 2 4 5 6
however the only way to obtain that result is to break the rules of the problem by swapping 4 and 5; 4 and 6; 5

pinkeshjain @ 9 May 2009 07:07 PM

Yes Puneet, you are correct. Thanks for pointing out.

tryitn1 @ 10 May 2009 06:34 AM

i've a N (log N^2) algorithm but it is TLE. Anyone care to help me or suggest better. It is similar to merge sort. I divide into 2 halfs and then combine then.

http://codepad.org/AZj4Jwrn

imrankane2005 @ 11 May 2009 02:57 AM

@tvrju
It's against the spirit of competition to ask for any help during the contests.

Try on your own and after the contest post on the forum. You will get help then.

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