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 » Practice(hard) » Ordering the Soldiers

Ordering the Soldiers

Problem code: ORDERS

  • Submit
  • All Submissions

All submissions for this problem are available.

In Byteland it is always the military officer's main worry to order his soldiers on parade correctly. Luckily, ordering soldiers is not really such a problem. If a platoon consists of n men, all of them have different rank (from 1 - lowest to n - highest) and on parade they should be lined up from left to right in increasing order of rank.

Sounds simple, doesn't it? Well, Sgt Johnny thought the same, until one day he was faced with a new command. He soon discovered that his elite commandos preferred to do the fighting, and leave the thinking to their superiors. So, when at the first rollcall the soldiers lined up in fairly random order it was not because of their lack of discipline, but simply because they couldn't work out how to form a line in correct order of ranks. Sgt Johnny was not at all amused, particularly as he soon found that none of the soldiers even remembered his own rank. Over the years of service every soldier had only learned which of the other soldiers were his superiors. But Sgt Johnny was not a man to give up easily when faced with a true military challenge. After a moment's thought a solution of brilliant simplicity struck him and he issued the following order: "men, starting from the left, one by one, do: (step forward; go left until there is no superior to the left of you; get back in line).". This did indeed get the men sorted in a few minutes. The problem was solved... for the time being.

The next day, the soldiers came in exactly the same order as the day before, and had to be rearranged using the same method. History repeated. After some weeks, Sgt Johnny managed to force each of his soldiers to remember how many men he passed when going left, and thus make the sorting process even faster.

If you know how many positions each man has to walk to the left, can you try to find out what order of ranks the soldiers initially line up in?

Input

The first line of input contains an integer t<=50, the number of test cases. It is followed by t test cases, each consisting of 2 lines. The first line contains a single integer n (1<=n<=200000). The second line contains n space separated integers wi, denoting how far the i-th soldier in line must walk to the left when applying Sgt Johnny's algorithm.

Output

For each test case, output a single line consisting of n space separated integers - the ranks of the soldiers, given from left to right in their initial arrangement.

Example

Input:
2
3
0 1 0
5
0 1 2 0 1

Output:
2 1 3
3 2 1 5 4

Warning: large Input/Output data, be careful with certain languages


Date: 2008-12-01
Time limit: 13s
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.

darthsitius @ 20 Jun 2009 02:10 AM

Do all the soldiers have different ranks ( id's)?

spradeep @ 1 Jul 2009 06:09 PM

I guess most of the Java Programs are timing out when I submit. i.e. the result is not obtained from the program within the time limit.

I can optimize the code, but i don't know to what level. In the problem itself, if you guys can give the order of the input data which will be used to verify the program, it will be easier for us to optimize.

i0exception @ 1 Jul 2009 06:19 PM

@Pradeep What do you mean by giving the order of the input data?

spradeep @ 3 Jul 2009 10:57 PM

Hi Aniruddha. Sorry for the late reply. I mean to say, you are giving some input data and verifying my program by running it in codechef server machine right? If you give us the order of the input data that you use to verify my program, it would be useful to optimize my code. I am seeing a warning in the above problem saying "large input data". But, if you have given the order of input data it would have been useful. For example, in this problem, you could have given - Order of input: 10 test cases, maximum 100 soldiers per test case.

darshankpbhat @ 10 Jul 2009 03:58 PM

i have tried optimizing to the greatest.. but still says timelimit exceeded can somebody help...

admin 2 @ 10 Jul 2009 05:53 PM

@darshan You might want to check the complexity of your solution. If your complexity is of a higher order, no matter how hard you optimize it, it won't run in time.

dmurat @ 16 Jul 2009 08:52 AM

my algorithm runs in O(N^2) time in the worst case. It is impossible to reduce it to O(N)... And I cant figure out how to do it in O(NlogN) time... :S

dmurat @ 16 Jul 2009 08:55 AM

btw, is there a case where the input is
0 1 2 3 4 5 6 7...

blindenvy @ 25 Jul 2009 08:08 AM

I would be very surprised if anyone got this in java under time.

vscool22 @ 13 Aug 2009 05:14 PM

Is it possible that a soldier can move more steps to left than the actual number of soldiers standing on its left. For example: "0 2 2 3 1" Is this case possible? Can 2nd soldier move 2 steps to left even if there is only one soldier is standing on its left..?

admin 2 @ 13 Aug 2009 06:49 PM

@vinay Please re-read the problem statement. Your question is answered in the statement itself.

triplem @ 13 Aug 2009 06:51 PM

No, that wouldn't make any sense.

Hi, Can I submit a solution

Aby @ 29 Aug 2009 06:08 PM

Hi, Can I submit a solution in C#? Also what would be the signature of method which I have to write? Is it as follows?

    public static string Solve(string [ ])

 what must be the time

dharmendhar.p @ 3 Sep 2009 12:35 PM

 what must be the time complexity???

like O(n), O(n^2) for this program to run...

Has to be better than O(n^2).

admin @ 3 Sep 2009 01:11 PM

Has to be better than O(n^2).

can sm1 give me its solution

nobby @ 5 Sep 2009 04:59 PM

can sm1 give me its solution

How do I submit code written

vinayakpk @ 9 Sep 2009 01:07 AM

How do I submit code written in C#. I submitted a console app and then I submitted the source code. Bothe the times i got compilation error.

 

Vinayak

does the time taken  for

rahulgolwalkar @ 13 Sep 2009 10:09 AM

does the time taken  for finding the answer matter on whether i use a linked list or an array??

or it just depends only on the order?

Well, I am unclear as to what

admin @ 13 Sep 2009 07:53 PM

Well, I am unclear as to what you mean by 'order'. Linked lists and arrays are two different data structures and as such, comparison between the two is inappropriate.

i made a code for this

Akhil Vinod @ 30 Sep 2009 07:39 PM
i made a code for this problem in turboc c++ in windows .... i modified it to run on the g++ compiler provided by cygwin on windows... but it is not compiling on codechef judge

pls do post a rpli, i hav

Akhil Vinod @ 1 Oct 2009 12:53 AM
pls do post a rpli, i hav tried several times to submit the solution

Please take a look at Sample

i0exception @ 1 Oct 2009 01:02 PM

Please take a look at Sample Solutions and the FAQ

man its an o(n) simple algo

GIjoe @ 5 Nov 2009 03:52 PM

man its an o(n) simple algo .....

Hey where do i find the

kevin36524 @ 8 Nov 2009 12:02 PM

Hey where do i find the solution to this problem???

OR

Can anyone give some hint?? i tried it with linked list.

But it took too much time

Please give some alternative algo!!

I'd like to point out that

hiptobecubic @ 10 Nov 2009 11:26 PM

I'd like to point out that the examples are a bit ambiguous.

I originally interpreted the question as, "List original position by rank" instead of "List rank by original position". It's easy to see which is correct when you consider it, but the example outputs are the same either way.

It wasn't until a friend (who originally agreed that I was doing it correctly) pointed out that I had it backwards that I corrected my mistake.

I think the problem statement

admin @ 11 Nov 2009 02:07 PM

I think the problem statement + the examples do a good job of explaining what is required.

Anybody able to get the

abhinava.srivastava @ 12 Nov 2009 04:00 PM

Anybody able to get the O(NlogN) time..?

My solution: Worst case O(N^2) & best case O(N). getting TLE.

 

TO THE WEBMASTER Please

sharma_apoorv @ 18 Nov 2009 03:37 PM

TO THE WEBMASTER

Please clarify in the question that the positions moved by a soldier array is given such that the soldiers are standing in the wrong formation and not after sorting how much each soldier had to move.

Hi , From where to read

nageshbgl @ 26 Nov 2009 11:23 AM

Hi , From where to read inputs and where to put output ..i mean console or file or is there any method signature... any info plz...

Standard input/output

triplem @ 26 Nov 2009 11:50 AM

Standard input/output streams.

Thanks Stephen , Is there any

nageshbgl @ 26 Nov 2009 12:28 PM

Thanks Stephen , Is there any successfull submiotion for this problem in Java .. i mean in time...i am going out of time.

Yes.

triplem @ 26 Nov 2009 12:49 PM

Yes.

I am getting RunTimeError

nageshbgl @ 26 Nov 2009 01:35 PM

I am getting RunTimeError ..How can i know what type of error ...any info.. plzz

It's a runtime error. Your

admin @ 26 Nov 2009 01:50 PM

It's a runtime error. Your program ceased to execute midway. Please test on the local system with large test cases.

I have hit on a O(n) algo,

sumit9 @ 12 Dec 2009 04:14 PM

I have hit on a O(n) algo, its giving proper answers for the quoted test cases, but the submission says wrong answer.

I have pasted my code in forum at

http://discuss.codechef.com/showthread.php?t=922

Anyone plz help  :)

i think program has to be

07EE37 @ 12 Dec 2009 04:41 PM

i think program has to be O(n2) for the worst case and O(n) best case. the sorting algorithm is insertion sort so to get back the unsorted array, we would need a similar algorithm but doing the opposite.

I used an algo which doesnt

sumit9 @ 12 Dec 2009 04:46 PM

I used an algo which doesnt have any sorting...so it should always work in linear time.

It has given correct answers for above test cases as well.

I tried hard but cant

sumit9 @ 14 Dec 2009 06:38 PM

I tried hard but cant understand the bug in my code.

Any help....

My code is at,

http://discuss.codechef.com/showthread.php?t=922

I am also curious, was there

mrinmoy_g @ 19 Dec 2009 10:57 PM

I am also curious, was there any C program submission without TLE. I have updated my soln but still I am getting TLE.

Posted my soln in http://discuss.codechef.com/showthread.php?t=922

You can get the answer to

admin @ 19 Dec 2009 11:13 PM

You can get the answer to your question by simply checking out the list of successful submissions.

the solution is not being

sumit9 @ 24 Dec 2009 12:32 AM

the solution is not being displayed in the list of submissions

My solution works fine for

varunkamath @ 5 Jan 2010 09:55 PM

My solution works fine for the problem cases stated but the I still get a wrong answer on submission.

I have posted my solution at http://discuss.codechef.com/showthread.php?t=922

@Aniruddha what would be the

vikrantsingh02 @ 11 Jan 2010 10:21 AM

@Aniruddha

what would be the steps order for the final rank order 32415?

It is unclear that the soldier would move left until there is no one superior to his (just) left or to his left direction?

Each soldier moves until

triplem @ 11 Jan 2010 10:24 AM

Each soldier moves until there are no superiors anywhere to the left of the soldier. Otherwise they wouldn't end up sorted, would they?

I am getting run time error

prateekg @ 19 Jan 2010 03:48 PM

I am getting run time error which says "Run Time Error(OTHER)". Can you tell me where exactly the problem is.

I have written code in c# thus "int" can easily be assigned with 200000 (Max value), my array is not going out of bound. I have checked everything but still getting error.

@Admin - Please help!

Other implies using too much

triplem @ 19 Jan 2010 03:57 PM

Other implies using too much memory. Your StringBuilder is going to be far too large by the end of the last test.

You should not be waiting until the end of your program to print things out. Read the new FAQ.

@Stephen - Thanks for reply.

prateekg @ 19 Jan 2010 06:43 PM

@Stephen - Thanks for reply. I am printing result after each test case besides that I have removed my Array as well and now its exceeding the time limit. :( 

No clue what is going wrong and how to optimize it further... :(

I just test two different

washingtonzju @ 29 Jan 2010 08:28 PM

I just test two different methods, using tree or skip list can solve this problem. And the solution is mentioned in my blog

http://washingtonzju.blogspot.com/2010/01/solution-of-ordering-soldiers....

:)

@admin: My code for ORDERS

jenishc @ 2 Feb 2010 07:54 PM

@admin:

My code for ORDERS runs in O(nlogn) time. For n=200000, for the worst case input, the code takes less than 3 seconds to find the solution. But printing the solution is taking a lot of time, ~20 seconds in Java. What should i do?

can we have the exact Test

arbitlinks @ 14 Feb 2010 01:22 PM

can we have the exact Test cases our solutions are subjected to, this will help us in designing an optimum solution

No. FAQ

triplem @ 14 Feb 2010 01:40 PM

No. FAQ

FAQ

justfor @ 14 Apr 2010 09:10 PM

FAQ

Hello all, I posted a

gizmo @ 10 May 2010 07:37 PM

Hello all,

I posted a solution which gives the wrong answer. The problem of this is that it gives exactly the same output as this one on the bunch of tests I did (up to 200000 soldiers, several instances...). The one I linked is a naive solution which should be exact. I cannot know exactly because it runs out of time here :)

So without giving the code I'm trying now, can someone try to explain me what is wrong with my naive solution, without considering the time it takes to solve the problem?

 

Thx!

It is exceeding the time

code.chief @ 21 May 2010 02:01 PM

It is exceeding the time limit even in python..can somebody help!!!

I have a very small algo of around 28 lines but it is still failing

@ADMIN.. IS ALL THE CASES

dabbcomputers @ 24 May 2010 03:35 PM

@ADMIN..

IS ALL THE CASES MUST HAVE A SOLUTION...??

MY MEAN TO SAY THAT IS THERE IS ANY CASE LIKE THIS

1

5

1 0 0 0 0

BECAUSE 1 RANK ONE CAN'T MOVE TO THEIR LEFT BECAUSE IT IS ALREADY AT LEFT MOST POSITION.....

PLEASE HELP....

can we use Scanner class to

AnoopNarang @ 25 May 2010 11:13 PM

can we use Scanner class to take input from console

??

plz help

 

Program working f9 in my pC

but runtime error in codechef

(code removed by admin)

Do not post code here. Read

triplem @ 26 May 2010 11:01 AM

Do not post code here. Read the FAQ.

Scanner is supported, but is extremely slow at reading input so you really shouldn't use. (Though, your algorithm is also too slow, so changing input methods alone won't help :))

The reason you are getting a runtime error would be obvious if you had tested your code on a maximal sized input, so I presume you haven't tried that yet.

i was trying reverse*

AnoopNarang @ 27 May 2010 01:47 AM

i was trying reverse* method,......... worked perfect ....... but time limit exceeding ...  :(

Can we have cases like :   0

AnoopNarang @ 27 May 2010 01:51 AM

Can we have cases like :

 

0 0 0 1 2   i.e ...  1 2 5 4 3

0 0 0 3 3  i.e ...  3 4 5 1 2

 

coz my algorithm solves all cases possible

 

and sample cases are of type 0 1 0 , 0 1 2 0 1

 

@Anoop In my opinion, your

gizmo @ 8 Jun 2010 03:26 PM

@Anoop

In my opinion, your 2nd case (0 0 0 3 3) should return 4 5 1 2 3.

@Guillaume Verger... for 4 5

AnoopNarang @ 14 Jun 2010 07:37 AM

@Guillaume Verger...

for 4 5 1 2 3 it will be 0 0 2 2 2

@Anoop Thx! Your answer

gizmo @ 14 Jun 2010 02:53 PM

@Anoop

Thx! Your answer points where I misunderstood this problem :) I thought that given the input we had to make the soldiers walk and then return the position. In the example 0 0 0 3 3, the soldiers 4 and 5 would have done 3 steps, going to the left of the soldier 1.

The program compiled

karan k @ 22 Jun 2010 06:59 PM

The program compiled successfully on my computer....but it shows that there is a compilation error in my program.It shows 'main' class not found,whereas there is a 'main' class in my program...the program's in Java...j2se

Lets talk about the

disastor @ 24 Jun 2010 06:14 PM

Lets talk about the case

 

5

0 1 2 0 1

1 2 3 4 5 (5th being the highest rank, there is no superior to 5 so it should not be performing any movement)

The movement for highest rank should always be zero.

 

I am not sure if I missed any thing here.

ignore above! i got it now

disastor @ 24 Jun 2010 06:23 PM

ignore above! i got it now

Hi all, i guess ... an

alengcm @ 1 Jul 2010 11:25 AM

Hi all,

i guess ... an algorithm with time complexity worst case O(n^2) and best case O(n) is enough, but the key factor is reducing time needed for reading input...

Is that so ??

Expecting comments from those who solved this problem ..

 

thanks

what does runtime error

manisha_shetty @ 2 Jul 2010 10:53 AM

what does runtime error (other) include specifically.My code gives runtime 0.25 & memory 220.3M as shown by codechef.i had earlier submitted a solution for another problem with same memory requirement.the Faq and sample solution have not helped evn..sum1 pls help

I ve tested all cases in by

akash_d_learner @ 20 Aug 2010 04:02 AM

I ve tested all cases in by pc. on dynamically alloting d arrary its comming TIME LIMT EXCEEDED (3.5 M). when i m statically allocating array size to 50000 den its comming RUNTIME EXCEPTION (1.50 TIME and 2.9M) none of the other code is been changed.

Did you have a question?

triplem @ 20 Aug 2010 05:08 AM

Did you have a question? Since the problem says n can be up to 200000, it's pretty clear why using 50000 would give you a runtime error. If you were asking why your code was timing out, have you tried test cases with n=200000?

To Admin: I am very much

rajneesh2k10 @ 31 Aug 2010 05:30 PM

To Admin:

I am very much confused about the input format!!!  According to format the orders of the soldiers should be input in a single line. But any of the solution is not precisely following the input format as specified.

In C, the write scanf statement in a loop which is now way going to accept input from a single line with values separated by spaces. Its very confusing. Please tell me whether it can be done or not. Or provide me with the link of a running solution so that i can get the exact format n proceed.

scanf in a while loop will

triplem @ 1 Sep 2010 05:19 AM

scanf in a while loop will read inputs from a single line separated by spaces.. that's how scanf works. I'm not really sure what you're asking.

Please read this small code.

rajneesh2k10 @ 1 Sep 2010 11:17 AM

Please read this small code. It'll clearify my problem. I am trying to read 5 values separated by space using scanf and it gives me Segmentation Fault. I am using GCC. So how the space separated values are being accepted in the solution to the above problem using the same pattern of input.

#include <stdio.h>
int main()
{
int arr[5],i=0;
while(i<5)
scanf("%d",arr[i++]);
return 0;
}

See forum. Or a reference.

triplem @ 1 Sep 2010 01:42 PM

See forum. Or a reference.

Thnks a lot. Got the reply in

rajneesh2k10 @ 1 Sep 2010 03:08 PM

Thnks a lot. Got the reply in forum. Silly mistake. :)

I have submitted my solution

devendermishra @ 16 Sep 2010 11:08 PM

I have submitted my solution which runs for the sample test cases and one mentioned in the comment.

But, at the end, it got wrong answer. Is there any way to know for which test case, it goes wrong.

What the hell 1)The question

saurabh1bsp @ 29 Sep 2010 12:48 AM


What the hell

1)The question is ambiguous on direction left and right

2) anyway I solved it on my system with a very portable language java and it is running well for various test cases, but when I sumit the file it shows some compile time( not runtime) errors . How it could be possible

How exactly is it ambiguous?

triplem @ 29 Sep 2010 06:27 AM

How exactly is it ambiguous? Everything involving left and right seems perfectly clear to me.

As for your compile error, that is because you haven't read the FAQ so you do not understand what the judge requires.

The final content of the

calimero100582 @ 13 Oct 2010 07:54 PM

The final content of the console should look like:

2
3
0 1 0
5
0 1 2 0 1
2 1 3
3 2 1 5 4

or

2
3
0 1 0
2 1 3
5
0 1 2 0 1
3 2 1 5 4

forget the previous one I

calimero100582 @ 13 Oct 2010 08:20 PM

forget the previous one I read the FAQ

 

but I always have this error when I submit code

:( internal error occurred in the system

 

Please help me to understand this one

In case of php code, you need

mustali @ 1 Nov 2010 11:20 PM

In case of php code, you need to execute

php -q test.php < in.txt > out.txt

instead of

php test.php < in.txt > out.txt

because php by default adds HTTP headers in output thereby causing result as "Wrong Answer"

Pls help run time error for

agneshreddy @ 30 Nov 2010 07:25 AM

Pls help

run time error for java program

is there any way to get the

narainbalaji @ 8 Mar 2011 06:16 PM

is there any way to get the case for which my solution fails?

Hm, my code was judged to

thomasahle @ 15 Jun 2011 05:55 AM
Hm, my code was judged to take 24.27s to complete, but it still succeeded. Weird.

@narainbalaji : Try creating

thomasahle @ 15 Jun 2011 05:56 AM
@narainbalaji : Try creating some random test cases and manually check your programs output.

Is there something wrong with

jgroenen @ 5 Jul 2011 05:50 PM
Is there something wrong with an extra space at the end of the line? Does that invalidate the result?

AN arraYliST is fAr more

bodmas @ 19 Aug 2011 01:23 AM
AN arraYliST is fAr more effICieNt tHAN A linKedlist fOr tHis probLeM aLtHOugH iT DOes nOt SolVe It iN TIme!

@admin: my code works well on

naveen007 @ 26 Aug 2011 06:04 PM
@admin: my code works well on my sustem but it shows runtime error on codechef...why??

i used a binary tree.. logn

abhirut @ 27 Sep 2011 12:06 AM
i used a binary tree.. logn insertion and then a recursive inorder traversal to find final positions. still time limit exceeded :S now im starting to tire.. :(

please! help someone? is

abhirut @ 27 Sep 2011 02:21 AM
please! help someone? is there something i dont see here? can I do without using a binary tree??

I see that most solutions are

akshar100 @ 9 Oct 2011 02:33 AM
I see that most solutions are in C/C++ and extremely few in Python or JAVA. Just wondering why so. Is that the distribution of choice of programming languages on CodeChef or is it just this problem? I wrote correct solution to this problem in both python and Java but bother are exceeding time limit. If the time limit is 13 seconds how come the last couple of programs have succeeded despite taking a much longer time ?

Can somebody point out why my

gaurav08021 @ 17 Oct 2011 05:52 PM
Can somebody point out why my solution is timing out: Here is my code(C) # include void cal_rank(int *pos,int array_size) { //printf("Size:%dn",array_size); int pos_shift,n,m; for(n=0;n0;--num_test) { scanf("%dn",&num_sol); //printf("Num of soldiers: %dn",num_sol); pointer = (int *)calloc((num_sol),(sizeof(int))); arg = pointer; size = 0; for(num_sol;num_sol>0;--num_sol) { scanf("%d",pointer); //printf(":%d:",*(pointer)); ++pointer; ++size; } //printf("nEnd of test casen"); cal_rank(arg,size); free(arg); printf("n"); } //free(arg); } int main() { get_input(); return 0; }

Can somebody point out why my

gaurav08021 @ 17 Oct 2011 05:53 PM
Can somebody point out why my solution is timing out: Here is my code(C) # include void cal_rank(int *pos,int array_size) { //printf("Size:%dn",array_size); int pos_shift,n,m; for(n=0;n0;--num_test) { scanf("%dn",&num_sol); //printf("Num of soldiers: %dn",num_sol); pointer = (int *)calloc((num_sol),(sizeof(int))); arg = pointer; size = 0; for(num_sol;num_sol>0;--num_sol) { scanf("%d",pointer); //printf(":%d:",*(pointer)); ++pointer; ++size; } //printf("nEnd of test casen"); cal_rank(arg,size); free(arg); printf("n"); } //free(arg); } int main() { get_input(); return 0; }

can someone help me with

pratikhora @ 21 Oct 2011 10:40 PM
can someone help me with submission. i am submitting my program but site says this language won't work. i am using c++

does anyone has any idea

flexicoder @ 20 Dec 2011 07:45 PM
does anyone has any idea whether the test cases have the worst case .....1 2 3 4 5... too....cuz i guess dat will change everythnng...thnx

This question has a clear

iamhashemi @ 15 Jan 2012 10:17 AM
This question has a clear answer with O(n^2) . I use this solution for test. my solution is O(N^1.5) . I have compared result of my solution and the O(n^2) result for 10000 times and all of them are the same. i test it for big sizes such as 20000 , 200000 and get no error from this test. but I get wrong answer from site. should I place extra 'n' or other thing into my result?

I used a simple insertion

kriateive @ 18 Jan 2012 05:23 PM
I used a simple insertion sort. Through i expected time limit exceeded, i keep on getting wrong answer! i have tested my ans with randomly generated large inputs against some of the accepted solutions and found their diff returns the output to be same! please help!

I, sure my solution should

amankhan1991 @ 19 Jan 2012 12:29 AM
I, sure my solution should work and it is working ofr the sample program but it is still not being accepted . why so ? :/

My logic is undeniable :p the

amankhan1991 @ 19 Jan 2012 12:34 AM
My logic is undeniable :p the answer coming in slmost zero seconds . what more do you expect :o

I always get time limit

vijinpv @ 20 Jan 2012 12:06 PM
I always get time limit exceeded error

this code produces the exact

henrykibiwott @ 4 Feb 2012 12:39 AM
this code produces the exact requirement in my pc and in microsoft visual c++ 6.0, but upon submission iam told time limit exceeded. somebody help me. i will be very pleased to be helped. #include int soldiers[200000]; int moves[200000]; int i, j, k, m, n, t, x, count, temp,xindex; int main() { scanf("%d",&t); do{ scanf("%d",&n); for(xindex=0;xindex1) { m=i-x; temp=soldiers[i]; for(j=i;j>m;j--) { soldiers[j]=soldiers[j-1]; } soldiers[m]=temp; } } printf("n"); for(k=0;k0); return 0; }

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

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