OddProblem code: DCE05 |
All submissions for this problem are available.
The captain of the ship TITANIC is a little .... off the track. He needs to select the crew for the ship. But everyone seems to be eligible. So to test their intelligence, he plays a game.
The contestants have to stand in a line. They are given the numbers in the order in which they stand, starting from 1. The captain then removes all the contestants that are standing at an odd position.
Initially, standing people have numbers - 1,2,3,4,5...
After first pass, people left are - 2,4,...
After second pass - 4,....
And so on.
You want to board the ship as a crew member. Given the total number of applicants for a position, find the best place to stand in the line so that you are selected.
Input
First line contains the number of test cases t (t<=10^5). The next t lines contain integer n, the number of applicants for that case. (n<=10^9)
Output
Display t lines, each containg a single integer, the place where you would stand to win a place at TITANIC.
Example
Input: 2 5 12 Output: 4 8
| Author: | uploader0 |
| Date Added: | 14-10-2009 |
| Time Limit: | 2 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, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
|
If you are still having problems, see a sample solution here. |

Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
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.
main() should return
main() should return something.....
Does the time limit holds
Does the time limit holds good for Java also?
See the FAQ.
See the FAQ.
According to me you cannot
According to me you cannot do static memory allocation during runtime..As you are doing long int num[n]...Instead u should try using pointers and then allocate desired memory for inputs to be taken.
Look up what %i means.
Look up what %i means.
Needed to know the general
Needed to know the general output format.
Should it be :
1. test cases:
Input
Output
....
OR
2.
Test cases:
All inputs
All outputs
I am asking this cause in some solutions given on Codechef followed both formats and accepted. When I put something, it's giving TLE.
You aren't printing the input
You aren't printing the input back to the screen, only the output, and it makes absolutely no difference at what time during your program's execution you do this, as long as the output is correct.
Your code doesn't actually work properly on the sample input; have you not tested your program at all?
Okay, I looked up what "%i"
Okay, I looked up what "%i" means, made the appropriate change and got "Correct". Thanks.
Is n >=2 ? If not then what
Is n >=2 ? If not then what should happen when n = 1. n means the number of applicants.
With only one person it
With only one person it should be pretty obvious at what point they should stand..
Yea its obvious.
Yea its obvious. But theoretically, 1 is odd. And the specification says that odd number be thrown out.
Anyways, solved it.
Well, in that case, there's
Well, in that case, there's nothing different between 1 and anything else; you always get down to 1 person eventually, and 1 is always odd. It is implied the game stops when there is 1 person left.
My python code is running
My python code is running fine on my system. But when i submit it is giving me runtime NZEC error. Can anyon explain me what it is ?
i get answer in this form for
i get answer in this form for 10^9:-
5.368709e+08
Is this ok?
what is time limit and how
what is time limit and how it is calculated?
Hi admin I am submitting
Hi admin
I am submitting solution for this problem, but everytime it says time exceeded.
I would request you to have a look at my logic which is of single line, and give me some direction so as where am going wrong. I dont want to use any unnecessary loops for this problem which am doing but still am getting time exceeded.
Please help.
Thanks
To admins: Probably your test
To admins:
Probably your test cases don't cover a subtle corner case. I have submitted two different solutions to this problem (174407 and 174408). The two solutions differ by only one character. However, with n=8, they produce different answers. Your system has AC both of them. Ideally,174407 shouldn't be AC, it should be WA.
It obviously isn't possible
It obviously isn't possible to cover every single test case. No matter what the test cases are you will be able to write a wrong program that can get accepted; there is no need to change the test cases every single time this happens. If your program is right, it will be accepted; that is all that matters.
I have the correct code but
I have the correct code but the time limit is exceeded...............
No; if you have time limit
No; if you have time limit exceeded, then you do not have the correct code.
@viswateja nelakuditi: I have
@viswateja nelakuditi:
I have the same problem (runtime error) but I don't understand why. If somone car check my code which is simple (http://www.codechef.com/viewsolution/211516).
Thanks.
please somebody reply
please somebody reply
@Mayank: Using iostream is
@Mayank: Using iostream is far too slow.
@mayank at max your number of
@mayank at max your number of iterations can b:
10^6*10^9+10^6 which is very very large figure...
i have written the
i have written the code
http://www.codechef.com/viewsolution/232121
1 can output be given as input is given(Method 1) or else how to store results for such a large no of test cases
2 the code written as per Method 1 is giving an internal error??
@gaurav ... read the FAQ.
@gaurav ... read the FAQ. Don't include conio.h, its a windows/DOS specific header file.
i submitted the code but it
i submitted the code but it is giving runtime error, plz help:
http://www.codechef.com/viewsolution/232239
You clearly still haven't
You clearly still haven't read the FAQ.
Read the problem statement.
Read the problem statement.
you are not printing the
you are not printing the answer in correct format.
it must be printf("%dn", ans[i]) instead of printf("%dn", ans[i]);
ohh this comment section does
ohh this comment section does not show the backslash sign..
@manjot..here again your
@manjot..here again your array SIZE is too small to work for a file with test cases t=10^6
@Tor-Einar Jarnbjo - 7th
@Mayank: Using iostream is far too slow.
Not specifically for this problem but I have also had an issue with my programs timing out. What would you use instead of iostream? printf and scanf? or is there a more streamlined way of I/O
I am writing it using Arrays
I am writing it using Arrays in Java.
But to store 1 billion of no I need around 4 GB of RAM. That is why I think it is giving runtime error.
Anyone used any other data structure?
@ishan no need of any data
@ishan
no need of any data structure
try something diff to solve this
Hey everyone, This is my
Hey everyone,
This is my first time posting in one of the CodeChef forums even though I signed up over five months ago. Just a few moments ago I successfully submitted a solution to DCE05, an Easy level problem. The time limit according to the problem statement was 1s.
According to this site, my solution took 5.96s but still passed somehow. How can that be? Don't blast me too hard, Steve. I'm not as advanced at this as you are (yet). :-)
I have a link to my solution that I would like to post, but I am not sure whether or not that is against the rules.
~Aaron
That little line saying 'Have
That little line saying 'Have you browsed through the FAQ?' right under 'Post new comment' is there for a reason ;)
Oh, yeah. Fine print... :)
Oh, yeah. Fine print... :)
"Codechef might test your
"Codechef might test your code multiple times with different input files. If your code gives the correct answer within the time limit for each input file, the execution time displayed is the total of the time spent for each test case."
I guess that would be the answer!
somebody please help!
somebody please help!
you have about 10^6 test
you have about 10^6 test cases in that one ... printing the results out through System.out.println individually is probably whats slowing you down.
@abcd: u read to need faq u
@abcd: u read to need faq
u dont need to store all inputs and process then print all the output.
just take 1 input process it and print it.... better read FAQ.
need to read** lol
need to read** lol
@Antapreet Singh Thanks,I got
@Antapreet Singh
Thanks,I got AC. :)
Can using cin/cout slow you
Can using cin/cout slow you down too ?
@akhil- yes it do.. go fa
@akhil- yes it do.. go fa scanf/printf
Please don't post code here
Please don't post code here (FAQ), and make sure you go through all the comments before you post a new one. Using System.Out.println is probably whats slowing you down.
ADMIN here is my
ADMIN
here is my code
http://www.codechef.com/viewsolution/272950
plz tell me how can i reduce memory usage,,,
i m getting run time error..:(
@admin... i hav gone through
@admin...
i hav gone through the faq...n i understood..but i m not getting how to avoid the use of large arrays or make dem fit in memory
is dis bcoz m declaring large
is dis bcoz m declaring large array like a[1000000] inside a function....
admin plz reply.....
http://www.codechef.com/views
http://www.codechef.com/viewsolution/272955
wats the problem now its using 9.3 m of memory....i hav declared array outside functions.....plz help admin
ADMIN: Well, the
ADMIN:
Well, the straightforward code got accepted for me. But when I am going for faster I/O processing, I am getting a wrong answer. I do not know where I am going wrong, as my answers seem to be correct for the test cases.
Link to my code is:
http://www.codechef.com/viewsolution/273972
@admin I have solve this
@admin
I have solve this problem in java, algorithm executed for 10^6 values take system mili time
Start: 1278022137699
End: 1278022137717
But, when execute on the your enviorment it always says time limit exceeds.
Can you tell me is there are some problem in I/O.
Your code doesn't appear to
Your code doesn't appear to be related to this problem in the slightest. What problem are you trying to solve?
@ sanchit 1 obvous mistake
@ sanchit 1 obvous mistake in your code that i have found us that while you are outputting the data.
using printf("%ldn",&b[i]) you should use b[i] and NOT &b[i]
Also your algo is o(n) which will certainly get TLE.
@Stephen can u plz check for
@Stephen
can u plz check for which testcase my program is giving wrong answer.
My submission id is 287951.
somebody please reply
somebody please reply
try pow((double)2,j-1)
try pow((double)2,j-1)
the main thing is... the
the main thing is...
the function pow always return a double, so to make it integer, I used typecasting and used long to have the required range of int.
how would this ( pow((double)2,j-1)) help??
suggest something else
thanks
the main thing is...the
the main thing is...
the function pow always return a double, so to make it integer, I used typecasting and used long to have the required range of int.
how would this ( pow((double)2,j-1)) help??
suggest something else
thanks
somebody please reply
somebody please reply
@pruthvi: l=2**times what
@pruthvi:
l=2**times
what does this statement do??
Can somebody please post some
Can somebody please post some testcases??
Hi Admin, I solved this in
Hi Admin,
I solved this in PHP with the mose optimised algorithm. Still i get time limit exceeded. Can you please point me where i am doing wrong. This is my solution.
http://www.codechef.com/viewsolution/317705
Hey Shuaib, I noticed that
Hey Shuaib, I noticed that you are using BigIntegers in your solution, when int by itself is perfectly capable of handling the data the will be encountered while solving the problem. BigInteger will only slow down the execution and lead to TLEs. Use primitives.
Tell me something...in the
Tell me something...in the input, we are passing a text file which contains the test cases right ? || Are we passing the numbers directly and getting the output ?
For those of you who are
For those of you who are trying to solve this using Java, you can try using a StringBuffer to store your results instead of an array of integers (which seems to be the conventional approach). With this method, you will prevent memory leaks that might occur when you try this with an array. Plus the StringBuffer objects are built thread-safe, if you are trying that sort of thing.
I got an execution time of 2.47 seconds with my solution. Not sure how many test cases were involved but I tried at home with the maximum specified of one million and noticed that the only bottleneck was the speed with which the display could print one million strings.
So, give this a try. Hope it all works out for you.
@Mayank, Where in the problem
@Mayank,
Where in the problem statement does it tell you to print out unnecessary information?
pheeeew, Passed !!!
pheeeew, Passed !!!
i am fed up of this time
i am fed up of this time delay error suggest something please
http://www.codechef.com/viewsolution/341480
Hi Sir I submitted my code.
Hi Sir I submitted my code. It was accepted but shows 0M memory and 0s execution seconds why????
Please don't post code here;
Please don't post code here; read the FAQ.
As the FAQ says, any main method must always return 0; not returning 0 is the definition of runtime error.
@Stephen, I changed the
@Stephen,
I changed the return statement from 1 to 0,
but still geting the same runtime error (SIGSEV)
http://www.codechef.com/viewsolution/357754
check the solution here
thanks
I hadn't read the rest of
I hadn't read the rest of your code yet, but you still haven't read the FAQ. You aren't allowed to read from files.
Read the FAQ. You have lots
Read the FAQ. You have lots of mistakes in your code.
Hey guys, so i am using scanf
Hey guys, so i am using scanf to get my input but when i my output just adds onto my input when i output it with printf. How do i get it where the output is by itself instead of after the input.
PS: I tried System('CLS'); but it gave me an error.
As I mentioned in the comment
As I mentioned in the comment right above yours, read the FAQ.. it tells you exactly that.
As is explained in the FAQ
As is explained in the FAQ which you clearly still haven't read, only your output is important. The judge tests your program by redirecting the standard input stream to a file, and then compares that file with the expected file. It makes no difference whatsoever at what point in your program you read input, since the judge can never tell.
That solution will give a runtime error since you are told there could be a million test cases but your array is only of size 1000.
Andrew, using an array with 1
Andrew, using an array with 1 million should be fine on gcc 4.008. Using anything less will yield the wrong answer.
here number of applicantants
here number of applicantants can be 10^9. However many solutions have used int to read it however int size being 2 bytes or 4 bytes can read maximum number of 2*10^6. However all solutions have been judged right including mine. Why would it be so.
The maximum value that can
The maximum value that can fit in an int on virtually all compilers these days is 2^31 - 1 = 2147483647 > 10^9.
The exact same logic is
The exact same logic is ACCEPTED when written in C++ but times out in Java!
Java: http://www.codechef.com/viewsolution/388087
C++: http://www.codechef.com/viewsolution/388052
Am I missing something?!!!
It says it took 1.35 s to
It says it took 1.35 s to compile my program. Time limit is one second. Yet, successful.
Mistake?
Yes. The mistake being that
Yes. The mistake being that you didn't read the FAQ :P
It's funny how that's the
It's funny how that's the answer to most questions. Thanks :)
o my god mene ye saite join
o my god mene ye saite join kar ke galti kar de mujhe to problm he samj nhi aye :( m just 12 pass na and doing btech in 1st year nw
just now submitted the ans
just now submitted the ans twice got timed out once and correct second .I only changed the c++ io to C io i am amazed at how much difference this makes
@admin i cooked the code and
@admin i cooked the code and it works gr8
but time imit exceeded.
For 1000000000 the answer i got in my pc in 4 seconds
the ans was 536870912 pleez tell me whether its correct or not
although i coudnt submit but m happy that i framed the code:)))
what does SIGSEGV error
what does SIGSEGV error mean???
FAQ
FAQ
@ all Java programmers.. as
@ all Java programmers..
as mentioned in most of the above posts, most of us hit the "timing exceeded" problem because of sysout after processing each input (like in the previous problems). store and bulk output as a single string.
@stephen please tell the
@stephen please tell the answer for 1000000000
i got the ans in 4 secnds in my pc
it was 536870912
Read the 'Input' section.
Read the 'Input' section. (And also the FAQ).
Hi admin how is it possible
Hi admin
how is it possible that both yelyenyes (submission no. 353156 ) and expo (submission no. 354225) have successful submissions when both of them produce different ouputs for the same input
For eg.
yelyenyes's output or test cases
1 is 0
2 is 1
4 is 2
and expo's output is
1 is 1
2 is 2
4 is 4
clearly expo's ouptut is correct !!!
even i am getting wrong answer for the same ouputs!!!
Runtime error means your main
Runtime error means your main function is not returning 0. Your main function will never return 0.
I had attempted this problem
I had attempted this problem 7 times out of which 1 had a compilation error and the rest exceeded time limit.
I'm quite confused here as the version ID454541 is the exact copy of a successful submission by gowri sundaram and still fails on the time limit.
Versions ID454120 & ID454330 has a complexity of n2
I had later submitted a modified solution in versions ID454523 & ID454536 such that the complexity is n and suprisingly it still fails on the time limit.
Please clarify.
I have tried submitting my
I have tried submitting my solution many times. But still it times out. Here is my solution#mce_temp_url#!
Please have a look at it and help me. I am stuck!
please reply admins!
please reply admins!
Same problem...no mater what
Same problem...no mater what i try....it times out!!!!....help please...
df
df
is there any one out
is there any one out there...??????
i can hear you...!!!!
i can hear you...!!!!
Then please help me out!
Then please help me out!
Your operations such as log
Your operations such as log and pow are time consuming i guess.
Whatever code i write it is
Whatever code i write it is giving me tle....... why so????? i even tried pasting some code which the site indicated was solved in 0.0s...... I have been finding this problem for all questions... Can Someone explain y????
i think there is some thing
i think there is some thing wrong with this exercise
i mean,
if the contestn is 4,
so it will be
1234
24
4
so the answer is 4
but i try code that wriiten by the 'correct' solver, it will result 2, not 4.
hows your opinion?
hansfry..you are
hansfry..you are right..rather than caring about other code ..make your own
then only you ll be known as codechef
Please explain the three
Please explain the three lines in Input. For this problem We need 3 data :
1) no. of vacancies,
2)no. of applicants
3) no. of times the captain removes people(i.e. passes)
In Problem explanation Under Input heading a woed 'test case' is specified. What is test case here ? Is it no. of Passes? And explanation says 'next t lines are no. of applicants for case'. Do we need to solve this problem for t (no. entered in first line) cases ?
Then We have no. of applicants for each cases but What is no. of vacancies (or members in a crew) and how many passes for each cases. where is two data for each cases. Any one please explain me
i have undestood the problem
i have undestood the problem ....
can smbody give me the logic to solve this
@shailesh kishore If you have
@shailesh kishore
If you have understood the problem then try to find out the answer for more number of test cases and see the pattern of the output.
the class name is Main and
the class name is Main and not ODD
I never knew that scanf and
I never knew that scanf and cin would result me a difference in submission....
It seems that the codechef
It seems that the codechef tester is down... it gives time limit exceeded. I had a look the sample codes that have successfully executed.. Mine should certainly work faster than theirs... SOMEONE PLZ look into this
This problem tester is not
This problem tester is not working for JAVA. ...It always says Time limit exceeded.... Even for the code which shows successful submission above... What a joke.!!!
WHAT IS THE OUTPUT FOR INPUT
WHAT IS THE OUTPUT FOR INPUT =2 ?????????????
DATA IS INCOMPLETE
DATA IS INCOMPLETE
Something is seriosly wrong
Something is seriosly wrong with the way codechef judge deals with languages. I was getting TLE for my JAVA program but exactly same Algo passed for C programm.
I have felt it for some other problems also. Is using Java for such programming contests is not a Good Idea!
sir please reply to problem
sir please reply to problem
i am gettin a runtime
i am gettin a runtime error.plz help me out.
somthing wrong with you i
somthing wrong with you i have even submitted a copy of accepted program it still says tim limit exceeded..
Yes even I did same...
Yes even I did same... Submitted accepted program and is saying time limit exceeded....
Why am I getting runtime
Why am I getting runtime error SIGABRT ? I have read FAQ but donot understand why it gives this error even when I'm using long when there are solutions which are using only int ?
I Don't lIke tHis ideA Of A
hey my code is dis!! But here
#include int main() { long
This does not make sense. I
Yeah this needs to be marked
I agree ... The problem seems
I am getting "Time Limit
what d hell is going on.....
hi Admin, i am not getting
Hi all, I solved it in
hey...i submitted the code of
sorry total code dint get
why my code is not getting
@hungrycoder: Post a link to
here is the link
@hungrycoder The runtime
@balajiganapath thanks for
http://www.codechef.com/views
this is d
@ank007 don't use
http://www.codechef.com/views
I submitted this solution and
It helps to use buffer in
@balajiganapath hey thnx for
@ank007:u cud learn from my
hey tell me ,in the example
does ur example say 12
simple math technique will
can array not have a size of
@admin plzzz tell me the
i have chckd for all
Hello! I have a runtime error
is it d highest power of 2?
Guys,The Problem essentially
Guys,The Problem essentially
Respected Admin, I have
my logic is to find the
I am getting runtime error
My solution in C was exactly
@admin, my program works on
hey admin,my prog. is giving
why am i getting "Time Limit
Please see my code?? which
Please... Why am i getting
Protip: There is a solution
@geist8 Thanks for mentioning
@admin::I think test case
need help in optimizing the
used PrintWriter, still
finally got it correct... new
a=input(); i=0; j=0; while i
my code runs well on my
my code is running well on my
http://www.codechef.com/views
Come on, My program is
I had implemented using
Cant we give a formula?
2^|_ (log(n)/log(2)) _|
Can any one tell me why i am
IT IS POSSIBLE IN JAVA! I
These problems are useless
hello admin, my code is
I would like you to go
where is the problem ...... u
is brute force necessary
same code in c++ gives time
too cruel for python :|
@kushdilip: cin and cout are
#include main() { int
@shil read FAQ about NZEC -
i checked last ,first, mid
I am getting this on my
and now its showing time
i think no of vacancies needs
plz help
The correct formula to solve
#include void read_num(int
i dont want to enlist on
my solution is running in my
Why is this code exceeds time
Hep ppl can anybody tell me
My python code gives runtimes
Oh, I solved it. Just
Why this code is not working.
Admin, My worst-case time
WTH! My worst-case complexity
Finally, got it! Printing
I followed the tutorial of
@elva136, I wrote the
okay got accepted using long
#include #include int kk(int
Please tell me wats wrong
Please..help me with the
my code's code
TLE everytime in java. This
@jindal_bit: I've solved it
can i have more test cases??
here written that the time
My code isnt getting executed
I keep on getting TLE for my
my code is running perfectly
Can anyone tell why I am
Can anyone help me out, why I
@ram87reddy : I ran your code
@ram87reddy : I meant unlike
can anyone plz help me wid
this is my solution :
Piece of cake.. I did this in
http://www.codechef.com/statu
can anyone tell me why this