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 Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(medium) » Bytelandian gold coins

Bytelandian gold coins

Problem code: COINS

  • Submit
  • All Submissions

All submissions for this problem are available.

In Byteland they have a very strange monetary system.

Each Bytelandian gold coin has an integer number written on it. A coin n
can be exchanged in a bank into three coins: n/2, n/3 and n/4.
But these numbers are all rounded down (the banks have to make a profit).

You can also sell Bytelandian coins for American dollars. The exchange
rate is 1:1. But you can not buy Bytelandian coins.

You have one gold coin. What is the maximum amount of American dollars
you can get for it?

Input

The input will contain several test cases (not more than 10). Each
testcase is a single line with a number n, 0 <= n <= 1 000 000 000.
It is the number written on your coin.

Output

For each test case output a single line, containing the maximum amount
of American dollars you can make.

Example

Input:
12
2

Output:
13
2

You can change 12 into 6, 4 and 3, and then change these into
$6+$4+$3 = $13.

If you try changing the coin 2 into 3 smaller coins, you will get
1, 0 and 0, and later you can get no more than $1 out of them.
It is better just to change the 2 coin directly into $2.


Author: admin
Date Added: 1-12-2008
Time Limit: 9 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, 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, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

kumar_ravi @ 6 May 2009 02:28 AM

till when to take the input..??

till 10 test cases..?? then how come only two inputs are here??

dark_tears @ 6 May 2009 12:26 PM

it says that no of inputs can be 10 at max

kalaiselvant @ 20 May 2009 02:36 AM

What will be the terminating condition for input?

kyun @ 25 May 2009 12:47 AM

Input will terminate on end of file

gargnitin123 @ 5 Jun 2009 08:10 AM

do like input a no. and output it immediatly and this could happen till max of 10 times

anshusaurav @ 8 Jun 2009 11:51 PM

nitin did u sbmmited soln with ur tech nd got result correct" entering one input and printing one output "
i solved by that bt now i think its file related

anshusaurav @ 8 Jun 2009 11:57 PM

@ codechefs program with warning are allowed or not

jason_rgx420dz @ 9 Jun 2009 05:03 AM

what should be the output for coin values beyond the boundary values,i.e beyond 1,000,000,000?should there be an output or should it move on to the next test case?

jason_rgx420dz @ 9 Jun 2009 05:04 AM

also whats the format for the input and output, first input then output or output the result right after the input?(tried every possible way, still not solved)

leppyr64 @ 9 Jun 2009 07:38 AM

@jayant - there is no input less than 0 and no input greater than 1 000 000 000. It matters not whether you input all the possiblities and then do output, or input one, output one. Personally, I read the first input, made the first output, read the second input, made the second output, etc.

jason_rgx420dz @ 10 Jun 2009 02:48 AM

my code seems to be giving the correct output but on submission it says 'wrong answer'.can someone look it over and help me out. the solution id is 37285

leppyr64 @ 10 Jun 2009 06:09 AM

@Jayant: Only you and the admins have access to your submissions. The admins won't help you with this, as it's your responsibility to solve the problem. If you have questions about the problem, take it to the problem specific section of the forum.

saurabhh @ 14 Jun 2009 07:24 AM

Do we need to ask for the no. of test cases here?

chetanc @ 15 Jun 2009 10:37 PM

i dont understand the code is absolutely working fine in visual studio!!!!!!!!!!!But still i am getting runtime error!!!!!!!!!!!!Any Comments Pls

dejavu @ 19 Jun 2009 05:28 PM

can someone please calrify as to when the input should be terminated? as this is console input do we wait till 10 numbers are entered?? what should be the termination point for the code?

jaganr @ 20 Jun 2009 01:10 AM

Can i get the input for which the program failed and the expected output? I checked my program and could not find any error with it.

anshusaurav @ 21 Jun 2009 08:47 AM

wats the format of giving the output..
ie
first takin all inputs
or
takin one input processing and giving output for it thn taking another input

neha_khedkar @ 25 Jun 2009 05:41 AM

hfksdhksdfn,sdnf

Its not jus acceptin #include<conio.h>
n #include<iostream.h>

wtf???

i0exception @ 25 Jun 2009 08:50 AM

@neha : Codechef uses gcc. conio.h is a non standard file. Don't include it and code compiled on turbo C is not guaranteed to compile on our judge. There will be an FAQ put up shortly regarding this issue.

gnarang @ 26 Jun 2009 05:58 PM

Hi I have written the code in Java. I renamed my file to Main.java and uploaded it. The code expects the user will manually enter the input..number of coins and each amount. I am using a Buffered Reader as input instead of Main(String[] arg) list, as it gives user a better interface. Am I doing something wrong? How is the input expected? Another query...can we upload multiple Java files for a single solution?

i0exception @ 26 Jun 2009 07:50 PM

@gautam The input will be as specified in the problem statement. Read until you encounter an End Of File marker. Don't output any values other than those specified in the statement.

pippo @ 1 Jul 2009 10:39 PM

my solutions seems to me pretty fast, but they say it runs out of time ((
looks like 10 test cases is no problem for it (given there's a 9 sec time limit):

# time ./coins < test
13
9244998
248604
745745845
1000000000
10378474
672523451
12793817
12793817
245756745

real 0m0.212s
user 0m0.200s
sys 0m0.000s
# cat test
12
3452345
123123
745745845
1000000000
3745256
672523451
4536345
4563734
245756745

any hint on why is this happening?

pippo @ 1 Jul 2009 10:40 PM

aghrr.. formatting broke (
forget it

i0exception @ 1 Jul 2009 11:04 PM

are you reading till EOF? It can happen that your program stalls after processing all the testcases and that might be giving a TLE.

pippo @ 2 Jul 2009 12:02 AM

yep, I'am. It exits successfully after processing all the input.

i0exception @ 2 Jul 2009 12:29 AM

@evgenly you could try simply taking in the values without processing and printing any arbitrary value. Just to make sure whether your program is timing out because of your processing algorithm or does it stall whle taking input.

pippo @ 2 Jul 2009 12:38 AM

let's see... the version without any processing (that just echoes the input) worked for 3ms and *termanated*.

i0exception @ 2 Jul 2009 12:41 AM

@evgenly Try it on the online judge and see if it terminates here as well.

lalalapo @ 11 Jul 2009 02:13 AM

how many inputs should we give to test the code? i've tried many things: one input one output --> wrong
10 input max (i can only input 2 like the example above) --> wrong
stops after press enter twice --> still wrong

although i can solve the problem, i still cant figure out what the input and output should be..

admin 2 @ 11 Jul 2009 02:56 AM

The input and output are mentioned in the problem statement. You should probably read the FAQ in the help section on the top right corner of the page. It explains how to take input and print output. You can also read the Input output tutorial thats put up. Each test case consists of one number which has to be taken as the input and you have to print one number as the output.

arbitlinks @ 18 Jul 2009 08:26 PM

I am submitting the right answer in JAVA to this problem, but the online judge is not accepting it.I am taking just one input from keyboard and immediately outputing the result.
I have also tried taking 10 inputs , but all from standard input.

praveen_agrawa @ 22 Jul 2009 02:50 AM

I submitted my solution in Java: Main,java. It is expecting a filename which should contain all 10 numbers, one on each line. Its running perfectly on my machine, but not on submission. It doesn't even tell what's the expected output or its format, just that 'Wrong answer'. Can somebody help here?

praveen_agrawa @ 22 Jul 2009 02:58 AM

If the problem statement includes some clue on how the program will be invoked, i.e. java Main <filename>, or whatever way, then we can make the program run that way on our machines before submission.
Throwing only "wrong answer" doesn't help. It should also tell if the output numbers are wrong, or some output format/sequence error etc, i mean li'l more explanation should be there..

prof_chaos @ 22 Jul 2009 06:31 AM

after 5 attempts m able to submit a soln; for all u guys hving prob wid input format .... here is d soln
input is read frm a file "input.txt"
output as mentioned a single line output fr each read input

my code still hvin prob wid time limits .......... cant figure it out
fr 10 inputs time taken is
real 0m0.003s
user 0m0.000s
sys 0m0.000s

but online checker says time xceeded :(

admin 2 @ 22 Jul 2009 10:36 PM

Please read http://www.codechef.com/help/ for information on how to submit a solution in Java

milon @ 24 Jul 2009 03:10 PM

did any get it right ?????

vscool22 @ 6 Aug 2009 09:31 PM

In the first line should we write number of test cases then proceed with taking inputs?

admin 2 @ 6 Aug 2009 10:13 PM

You just need to write the output. you don't have to write the number of test cases to stdout.

mkd_16 @ 16 Aug 2009 12:43 PM

I find this annoying as hell that the number of test cases isn't specified, I set it to 10 and it said the answer was wrong but I have no real way of knowing if my answer is wrong or just the test cases I am expecting.

triplem @ 16 Aug 2009 01:35 PM

You don't need to know the number of test cases or assume it is 10 or anything like that. Just keep reading from standard input until you reach EOF - every language has a very easy way of checking that.

mkd_16 @ 17 Aug 2009 06:20 AM

I've seen from various sources that the output for 1,000,000,000 should be 4243218150 but I"m not getting this and I don't know why anyone would be. My output works for most other numbers numbers though.

triplem @ 17 Aug 2009 12:40 PM

That is definitely the correct answer for that input. Are you sure you are getting right answers for other inputs? Perhaps your interpretation of the problem is incorrect.

mkd_16 @ 17 Aug 2009 01:04 PM

I am getting the right output for 12,2,104 ..... and most other numbers I test, I think my problem arises with larger numbers? I"m using c .

triplem @ 17 Aug 2009 04:02 PM

Did you notice that 4243218150 is greater than 2^31?

Okay i guess I dont

mkd_16 @ 19 Aug 2009 03:29 AM
Okay i guess I dont understand the problem because Ive done the math myself and I get 1083333333 when adding 1000,000,000/2 ,3,4 .....so lost.

It doesn't say you can only

triplem @ 19 Aug 2009 07:19 AM
It doesn't say you can only go to the bank once.

Okay thanks that makes alot

mkd_16 @ 20 Aug 2009 01:29 AM
Okay thanks that makes alot more sense and I am now getting the correct answers.... just not according to code chef lol.

Nevermind I was using

mkd_16 @ 20 Aug 2009 06:03 AM
Nevermind I was using while(!cin.eof()) which was causing the issue, thanks agian.

i wrote a very simple

moideenjanab @ 21 Aug 2009 02:20 AM
i wrote a very simple recursive function for this, and it runs excellently on my laptop, even with ten 8-digit numbers. I seem to be exceeding CodeChef's time limit. Anyone has any ideas?

what is a test

dhirajb64 @ 21 Aug 2009 12:59 PM
what is a test case?????????please answer me

I feel a recursive solution

admin @ 21 Aug 2009 01:12 PM

I feel a recursive solution will time out. Find out the complexity of the solution and you will realize why.

 

@Dhiraj A test case is a set of inputs against which your code is tested. If the output your code produces is in accordance with the test output, then your code is correct, else it is wrong.

hey,what should be the output

nishantb @ 21 Aug 2009 05:06 PM
hey,what should be the output for 3452345.as no./2=1726172.5 its is taken as 1726172 no/3 is1150781.667 it is taken as 1150781 and no/4 is863086.25 it is taken as 863086 so the sum amounts to 3740039..as is my output m i corect atleast for this case...?

@Dhiraj its just the input

nishantb @ 21 Aug 2009 05:57 PM
@Dhiraj its just the input for which they check the o/p of your program..

@Nishant You are

admin @ 21 Aug 2009 06:29 PM

@Nishant You are misinterpreting the problem statement. Re-read it.

hey,,please explain it

nishantb @ 21 Aug 2009 09:16 PM
hey,,please explain it clearly...i have already read it a lot of times...

someone there to help me out

nishantb @ 21 Aug 2009 09:54 PM
someone there to help me out

You are missing the fact that

admin @ 21 Aug 2009 09:56 PM

You are missing the fact that you can further exchange the obtained coins for more coins.

How may i check the run time

nishantb @ 29 Aug 2009 09:37 PM

How may i check the run time on my dev c++ compiler??

Have a look at the function

admin @ 31 Aug 2009 01:42 PM

Have a look at the function named clock()

 INPUT: 123123 1000000000 120

Abhishek kumar @ 9 Sep 2009 08:04 PM

 INPUT:

123123
1000000000
120
1234512345
12121212
3422
83848586
999999999

OUTPUT:
248604
4243218150
144
5412617448
37595901
5052
294643700
4243218150

These are the results which i m getting and i have check with all the answers given above , my answers match with them but i m getting WA on submitting.
Somebody how has successful submission can plz check these and let me know

Can i know the reason for a

tush726 @ 10 Sep 2009 07:12 PM

Can i know the reason for a python runtime error?? the code works fine on my computer

This is infuriating.  No clue

brailsmt @ 10 Sep 2009 11:34 PM

This is infuriating.  No clue whatsoever as to *why* I'm getting a wrong answer.  It could be any number of things and I have no way of knowing what it is.  It seems one must be lucky to get the right answer...

Premature optimization killed

brailsmt @ 11 Sep 2009 12:05 AM

Premature optimization killed me...  *sigh*

I was trying but I could not

gaurav_gopi123 @ 14 Sep 2009 07:19 PM

I was trying but I could not do it.. where I can see the solutions submitted by others for this problem

can we not use

rakshith_babu @ 15 Sep 2009 11:16 PM

can we not use while(scanf("%d",&a)){ }  as terminating condition after the end of inputs.

@Rakshith Check what scanf()

admin @ 16 Sep 2009 01:20 PM
@Rakshith Check what scanf() returns. @Gaurav The solutions for this are not public yet.

i guess scanf returns the no

rakshith_babu @ 17 Sep 2009 05:40 AM
i guess scanf returns the no of items read from that perticular scanf statement else zero ...

thnx aniruddha.. i got the

rakshith_babu @ 17 Sep 2009 05:52 AM
thnx aniruddha.. i got the termination..

yo rakshith check this for

harshithsirigeri @ 19 Sep 2009 10:07 AM
yo rakshith check this for taking input: while(gets(str) && (i=atoi(str))!=0) { cout<

the dollars increase by the

mastermind12 @ 24 Sep 2009 05:08 PM

the dollars increase by the given number only when the number on the coin is a multiple of 12.but why am i getting wrong answers.plzzz help

i am get right answer on

rajul884 @ 26 Sep 2009 08:57 PM

i am get right answer on turbo c

but on this site they said it is wrong why???

i am getting 1083333333  on

rajul884 @ 26 Sep 2009 08:59 PM

i am getting 1083333333  on input 1000000000

but it said my program s wrong

That's because it is wrong.

triplem @ 27 Sep 2009 08:02 AM

That's because it is wrong. And so is that value.

are the cases taken by

aseem_pandey @ 30 Sep 2009 09:24 PM

are the cases taken by yash0101 are correct ????

someone please tell me....

what is run time error

kamal.lnmiit @ 10 Oct 2009 08:01 AM

what is run time error

It means that your program

admin @ 10 Oct 2009 05:55 PM

It means that your program gave an error while it was executing. It did not end gracefully.

A run time error here on

Obitus @ 12 Oct 2009 04:29 AM

A run time error here on codechef could also mean that you took up too much memory or something like that.  Your program could run fine but still be marked "run time error" if it's a memory hog...

I have finished the problem

manee @ 15 Oct 2009 06:10 PM

I have finished the problem and my code is correct coz its matching all the inputs and outputs discussed in the forum bt my problem is with submitting... i run the program till 10 times or till it enounters EOF (is -1 value) but still codechef says Wrong Answer!!

Can anyone help me?

Run it till it encounters an

admin @ 15 Oct 2009 06:29 PM

Run it till it encounters an EOF. The way you are checking for EOF is not correct. Read up on the return value of scanf().

#include void main() { char

avix @ 16 Oct 2009 07:52 PM
#include void main() { char c[1000]; int n,i,k[1000],ki[1000],count=0; while((c[count]=getChar()) !=EOF) { count++; } for(i=0;i=k[i]) { printf("%d",k[i]); } else printf("%d",ki[i]); } } please help whats wrong in it

@Anirudhha Thanks for the

manee @ 17 Oct 2009 05:30 PM

@Anirudhha

Thanks for the help but even though I changed it to

int check=scanf("%lu",&n);

if(check!=1)

break;

if((n>1000000000)||(n<=0))

continue;   //also tried break; here

 

it still says WA. I still don't know how to give the output!! I have been stuck on this part for a long time now... even though solving the problem wasn't this difficult as this!

You need to print the output

admin @ 18 Oct 2009 07:21 PM

You need to print the output to stdout as specified in the output specifications.

Is this possible to do

BlakeR22z @ 19 Oct 2009 11:58 AM

Is this possible to do without recursion?  Probably a stupid question.  I would assume I'm just so used to recursion now that I can't think of another solution.  Trying to do this in PERL with recursion is horribly inefficient.

how to take inputs when not

shivmitra @ 21 Oct 2009 11:09 AM

how to take inputs when not given the no. of cases...i m facing the same prob. at uva also...can anyone tell me some tutorial url or something..dont tell it cud b done by EOF or scanf ..i hav tried both ...i m somewhere getting wrong..plzzz tell what to do???

What else can we say? Input

triplem @ 21 Oct 2009 11:26 AM

What else can we say? Input methods return certain values if you reach the end of the file, like scanf returns EOF. There's no way for anyone of knowing how you've wrongly implemented it. Just read your programming language's documentation carefully.

what is the format of input

aadisriram @ 25 Oct 2009 03:39 PM

what is the format of input ?

my program is working fine but every time the program is run it will take only input and give the corresponding output.

I ran my code on gcc 4.4.1

texens @ 5 Nov 2009 04:30 PM

I ran my code on gcc 4.4.1 and i give in a test file as input:

test file: run by ./a.out < test

12
2
99999999
1000000000
12345678

 

 

and get the following resut:

13
2
364906343
4243218150
37769173

 

As far as i know, the outpur is correct, but everytime i submit, i get wrong answer...

this is my 1st submission on this forum.. and am not sure abt submission formats..

is there some particular format in which the output is to be given? is there some particular format in whcih the input will be given?

I'm unable to find a reason as to why my answer is getting rejected...

any suggestions will be appreciated.. thanks...

memoization worked very well

naveeninkgp @ 10 Nov 2009 09:16 PM

memoization worked very well for this problem.time 0.01s. Want to know if still there are better solutions.

After numerous tries , I

hsisahens @ 20 Nov 2009 06:42 PM

After numerous tries , I finally managed to solve the problem. 2 small hints for people who are very sure that their solution is correct but are getting "wrong answer" and are struggling like I was just a few minutes before

1. If you are getting "time Limit exceeded" , make sure 2 things a) u are able to detect end of file of the input. b) ur code is working within the time limit for inputs of the range >=109

2. Make sure u r not getting -ve results for large inputs in the range of >= 109. Use the largest data type possible , ie like "long long int" in C++ (64 bit integer).

 

Ok.I saw many ppl talking of

alok @ 21 Nov 2009 02:03 AM

Ok.I saw many ppl talking of just one thing that is the input format. Is it so difficult for the admins to just clarify the way the input should be given ?

I mean just clarify whether to take input from some file (as some pple. said here) or just manual input. Also many have got confused with the way input is shown in the example here. You are asking for test cases in the problem, which is apparently absent from the Input format (direct test values : 12,2).

The input format is pretty

triplem @ 21 Nov 2009 02:34 AM

The input format is pretty clear. The number of test cases is not part of the input; it isn't meant to be. You should read http://www.codechef.com/wiki/ for general information.

My code is a simple recursion

ajayram @ 4 Dec 2009 01:17 AM

My code is a simple recursion but program takes too much of time for inputs greater than 10^7 .. and it simply deso not respond for an input of 1000000000 does anyone have any method to deal with extremely large inputs?

Try to cache repeatedly

admin @ 4 Dec 2009 03:09 PM

Try to cache repeatedly encountered values.

@Aniruddha - Thanks vey much

ajayram @ 5 Dec 2009 02:49 AM

@Aniruddha - Thanks vey much for the hint I used a data structure for caching values as they are calculated and cut down on the no of recursons to be solved , got the correct answer according to codechef :)

i am getting SIGSEGV

rampage @ 20 Dec 2009 08:18 PM

i am getting SIGSEGV error.....
can someone tell me what i am doing incorrectly?

i use a recursive function and keep storing the results for further use....

#include<stdio.h>
#include<map>

using namespace std;
map <int,long long> reference;

int power(int,int);
long long getMaxExchange(int);
int getN(char);

int n;

int main()
{
char ch;
while((ch=getchar())!='n')
{
getN(ch);
printf("%lldn",getMaxExchange(n));
}              
return 0;
}

int getN(char ch)
{
int index,i,num[10];   
index=1;                
num[0]=ch-48;                
while((ch=getchar())!='n')
{
num[index]=ch-48;
index++;
}
n=0;
for(i=0;i<index;i++)
{
n+=num[i]*power(10,index-i-1);
}
return n;
}


long long getMaxExchange(int n)
{
if(n==0)
{
return 0;
}
long long ref=reference[n];
if(ref==0)
{                        
if(n>n/2+n/3+n/4)
{
ref=n;     
}
else
{
ref=(getMaxExchange(n/2)+getMaxExchange(n/3)+getMaxExchange(n/4));
}
reference[n]=ref;
}
return ref;
}

int power(int a,int b)
{
int ans=1;
while(b>0)
{
ans*=a;
b--;
}
return ans;
}

Don't you think you will use

admin @ 20 Dec 2009 09:54 PM

Don't you think you will use too much memory?

No, it won't use too much

triplem @ 21 Dec 2009 02:17 AM

No, it won't use too much memory. The only problem is the way you are reading input; you aren't dealing with the \r character in unix.

@Stephan err....can you

rampage @ 21 Dec 2009 10:39 AM

@Stephan

err....can you please elaborate a little....or give me some link to know exactly what you are telling?

http://en.wikipedia.org/wiki/

triplem @ 21 Dec 2009 11:40 AM

http://en.wikipedia.org/wiki/Newline

got accepted....thanks

rampage @ 21 Dec 2009 11:57 AM

got accepted....thanks

#include<stdio.h> int

rumi2752 @ 26 Dec 2009 09:15 PM

#include<stdio.h>

int main(void)

{

int a,b,i;

for(i=1;i<=10;i++){

scanf("%d",&b);

a=((b/2)+(b/3)+(b/4));

if(a>b)printf("%dnn",a);

else if(a==b)printf("%dnn",b);

else printf("%dnn",b);

}

return 0;

}

can anyone tell me what is wrong here?????

#include<stdio.h>int

rumi2752 @ 26 Dec 2009 09:17 PM

#include<stdio.h>
int main(void)
{
int a,b,i;
for(i=1;i<=10;i++){
scanf("%d",&b);
a=((b/2)+(b/3)+(b/4));
if(a>b)printf("%dnn",a);
else if(a==b)printf("%dnn",b);
else printf("%dnn",b);
}

return 0;
}

sorry the code is this...................

i cant type \n\n

rumi2752 @ 26 Dec 2009 09:18 PM

i cant type nn

ps.  \n\n    means ..new line

rumi2752 @ 26 Dec 2009 09:20 PM

ps.  nn    means ..new line

Read the other comments.

triplem @ 27 Dec 2009 02:45 AM

Read the other comments.

for(; scanf("%lld",&x) !=

Dalchand @ 4 Jan 2010 08:04 PM

for(; scanf("%lld",&x) != EOF; printf("%lld n",coin(x)));

will it work... i mean will

Dalchand @ 4 Jan 2010 08:05 PM

will it work... i mean will it terminate at eof?

#include<stdio.h>   int

cpt jack @ 4 Jan 2010 11:55 PM

#include<stdio.h>

 

int main()

{

int t,i;

long int n,sum;

scanf("%d",&t);             //no.of  test cases

for(i=0;i<t;i++)

{

scanf("%ld",&n);

sum= n/2 + n/3 + n/4 ;

 

if(sum > n)

printf("n%ld",sum);

else

printf("n%ld",n);

}

return 0;

}

 

 

can anyone tell me whats wrong with my code

Your problem has already been

triplem @ 5 Jan 2010 06:09 AM

Your problem has already been addressed several times in the comments. Coins can be exchanged multiple times.

i know the coins can be

cpt jack @ 5 Jan 2010 10:40 PM

i know the coins can be exchanged multiple times, thats not the problem. my question is, how come my code is wrong when it shows correct output whith my compiler

Because you are probably not

admin @ 5 Jan 2010 10:46 PM

Because you are probably not testing it as extensively as the judge program.

I am using recursive and

ram79 @ 13 Jan 2010 04:39 AM

I am using recursive and getting the correct answer. For the max input value of 1,000,000,000 the compiled binary gives out 4243218150 correctly and takes 8 seconds to respond with a result.

So is the time limit of 9 seconds inclusive of all the 10 test cases or is it an average of the 10.

The time limit is the entire

triplem @ 13 Jan 2010 05:10 AM

The time limit is the entire time your program takes to execute all test cases, not an average.

The online judge tends to also be slower than a home computer by a factor of 2 or 3, so you're going to need a huge improvement over a time of 8 seconds for that test case.

For

ram79 @ 13 Jan 2010 05:15 AM

For Input:

999999991
999999992
999999993
999999994
999999995
999999996
999999997
999999998
999999999
1000000000

-------------

Output is:

4243218150
4243218150
4243218150
4243218150
4243218150
4243218150
4243218150
4243218150
4243218150
4243218150

real    1m10.134s
user    1m10.135s
sys     0m0.001s

And 1 minute 10 seconds is

triplem @ 13 Jan 2010 05:19 AM

And 1 minute 10 seconds is longer than the 9 second time limit.

import javax.swing.*;class

Prash23 @ 16 Jan 2010 04:31 PM

import javax.swing.*;
class Main
{
public static void main (String[] args)
{
int val,amc;
int td =Integer.parseInt( JOptionPane.showInputDialog
( "enter d no of test case" ));
for(int i=0 ;i<td;i++)
{
val =Integer.parseInt( JOptionPane.showInputDialog
( "enter d coin value" ));
amc=((val/2)+(val/3)+(val/4));
System.out.println(amc);
}
}
}

 

can an y one say wht is d RUN TIME ERROR

You are to read from the

triplem @ 16 Jan 2010 04:35 PM

You are to read from the standard input stream. Not from a JOptionPane.

thankx stephen but may i know

Prash23 @ 16 Jan 2010 06:14 PM

thankx stephen but may i know d reason why we should not use JOptionpane

thnx

hai stephen even when i use

Prash23 @ 16 Jan 2010 06:29 PM

hai stephen even when i use i/o streams its showing RUN TIME ERROR

You can't use a JOptionPane

triplem @ 17 Jan 2010 04:06 AM

You can't use a JOptionPane because that isn't how the judge works. The judge works by using standard streams.

You haven't submitted any solutions that use the correct input/output methods.

@stephen can u tell me which

dabbcomputers @ 20 Jan 2010 11:41 PM

@stephen

can u tell me which header file used in c language for eof()

/sources/Main.java:7: class

lakshmana @ 21 Jan 2010 11:36 PM

/sources/Main.java:7: class Coin is public, should be declared in a file named Coin.java public class Coin ^ 1 error

 

it's giving me this error..the file i have uploaded is itself Coin.java..

i don't understand whats the issue here..

Read the FAQ.

triplem @ 22 Jan 2010 02:13 AM

Read the FAQ.

Dont they accept programs in

Priteesh ranjan @ 7 Feb 2010 09:12 PM

Dont they accept programs in BlueJ ??...mine got rejected..says compiler error

What will be the terminating

suryabhan @ 10 Feb 2010 07:27 PM

What will be the terminating condition for input?

where my programme give wrong ans , can u send me an example

I wrote my code in java. Do I

sush12110 @ 13 Feb 2010 11:13 AM

I wrote my code in java. Do I need to write each test case in diffrent main files. My code is as below:

class Bytegc
{
public static int calc(int no)
{
int max=no;
if(no==0)
return 0;
else
{
int no1=calc(no/2);
int no2=calc(no/3);
int no3=calc(no/4);
if(max<(no1+no2+no3))
max=no1+no2+no3;
return max;
}
}


}
public class Main
{
public static void main(String []args)
{//Test case 1
{
int cno=12;
int res = Bytegc.calc(cno);
System.out.println(res);
}
//Test case 2
{
int cno=2;
int res = Bytegc.calc(cno);
System.out.println(res);
}
}


}

The code works fine on other compilers Also the output is correct. Can anyone tell me why it is not getting submitted.

It doesn't say there will be

triplem @ 13 Feb 2010 11:27 AM

It doesn't say there will be exactly 2 test cases. You should process input until you have reached EOF. See the FAQ.

will u please tell me how to

markandaysharan @ 21 Feb 2010 03:54 PM

will u please tell me how to write a program for bytelandian coins ?

Dont forget that you can

moijf @ 23 Feb 2010 05:16 PM

Dont forget that you can change again the coins after the first change ! (and again and again....)

this is the best one dynamic

dabbcomputers @ 24 Feb 2010 05:46 PM

this is the best one dynamic programming example...

this is the best one dynamic

dabbcomputers @ 24 Feb 2010 05:47 PM

this is the best one dynamic programming example...

thanx codechef...

 

my code is giving negative

abhishek6590 @ 10 Mar 2010 10:16 PM

my code is giving negative result for 745745745....i am using long int in C ....how can i increade my integer range?

 

Good Dynamic Programming

enrique3 @ 11 Mar 2010 10:46 PM

Good Dynamic Programming Problem!

 

@Abhishek: I am using long as well int C# (System.Int64). 64-bit Integers should be fine to crack this problem.

@Enrique : I also think that

abhishek6590 @ 12 Mar 2010 01:37 PM

@Enrique : I also think that LONG INT should do the workbecause its range is upto (2^31)-1=2147843647..which is greater than 10^9..the largest input can be 10^9

But still it is not working dont know why

  please tell me where is my

abhishek6590 @ 12 Mar 2010 01:40 PM

 

please tell me where is my mistake...i just want that my code should give correct result..i am not considering time..plz help

 

#include<stdio.h>

long int max(long int) ;
main()
{
long int n;
int i=0;char c;
while(i<=9)
{
c=scanf("%ld",&n);if(c==EOF)break;
printf("%ldn",max(n));i++;

}
return 0;
}
long int max(long int m)
{
if (m<=11)
return(m);
else
return max(m/2)+max(m/3)+max(m/4);
}

Test your code on cases which

triplem @ 12 Mar 2010 02:50 PM

Test your code on cases which could be harder than others.

@ admins how much memory

tipsy25187 @ 15 May 2010 08:20 PM

@ admins

how much memory could be used at runtime.

i am getting runtime error my code works fine on my system.

Read the FAQ. You have some

triplem @ 16 May 2010 04:22 AM

Read the FAQ. You have some very basic errors in your code.

hints :- 1)memoization is

gunjanbansal @ 22 May 2010 02:29 PM

hints :-

1)memoization is good but memory is scrase
2)Simplicity is essence of life(input)

Even 1000000000 is showing

manjotpahwa @ 6 Jun 2010 12:47 AM

Even 1000000000 is showing correct solution. No idea for which case my solution is failing. My code: http://www.codechef.com/viewsolution/252674

@Admin: Please check my

manjotpahwa @ 6 Jun 2010 11:44 AM

@Admin: Please check my solution and tell me for which case my solution is failing? I think its correct still its showing wrong answer.

http://www.codechef.com/viewsolution/252973

You can't have tested your

triplem @ 6 Jun 2010 12:23 PM

You can't have tested your code much; try small inputs and you will find an error very quickly.

@Admin: I don't get it, if he

manjotpahwa @ 6 Jun 2010 12:38 PM

@Admin: I don't get it, if he has a coin of value greater than what he would have after exchanging into smaller number, then he will directly convert it into dollars right? That is the basis of the input output example given in the case of 2, where he directly changes his money value to dollars instead of exchanging it for coins.

When I said small values, I

triplem @ 6 Jun 2010 01:49 PM

When I said small values, I meant, say, all inputs between 1 and 20. You don't have the correct value for all of them.

I have done it using dynamic

invinicible007 @ 8 Jun 2010 06:13 PM

I have done it using dynamic programming, time complexity is o(n) bt my space complexity is also o(n) so its giving run time error for larger value of n. Can anyone suggest a hint to do it in o(1) space

can anyone point the fault in

deathsmoke @ 10 Jun 2010 02:34 PM

can anyone point the fault in this program--

 

#include<iostream>
using namespace std;
unsigned long long int do_arithmetic(unsigned long long int test);
int main(){
unsigned long long int cases;
unsigned long long int ans;

cin>>cases;
do{
ans= do_arithmetic(cases);
cout<<ans<<endl;
cin>>cases;
}while( cases !=EOF);

return 0;
}

unsigned long long int do_arithmetic(unsigned long long int test){
static unsigned long long int cache[100]={0};
static unsigned int lookup[25]={0,1,2,3,4,5,6,7,8,9,10,11,13,13,14,15,17,17,19,19,21,22,23,23,26};
if(test<25)
return lookup[test];

else{
if( test<100){
if(cache[test]!=0)
return cache[test];
else {
test=(do_arithmetic(test/2)+do_arithmetic(test/4)+do_arithmetic(test/3));
cache[test]=test;
return test;
}

}

return (do_arithmetic(test/2)+do_arithmetic(test/4)+do_arithmetic(test/3));
}
}






for a cases like 144 the

prajata @ 12 Jun 2010 01:55 PM

for a cases like 144 the series is non-converging i feel...you can run a test.

import java.io.*; public

karan_verma57 @ 15 Jun 2010 12:06 AM

import java.io.*;

public final class Main

{

public static void Main (String args[])

throws IOException

{

BufferedReader br=new BufferedReader (new InputStreamReader(System.in));

String h=br.readLine();

int t=10;

int t1[]=new int[10];

int sum,k;

for(int i=0;i<t;i++)

{

t1[i]=Integer.parseInt(br.readLine());

t1[i]=lulu(t1[i]);

}

for(int i=0;i<t;i++)

{

System.out.println(t1[i]);

}

}

public static int lulu(int a)

{

int k=a,sum=0;

while(a>0)

{

sum=((a/2)+(a/3)+(a/4));

if(sum>a)

{

k=sum;

a=sum;

}

else if(sum<a)

{

a=sum;

}

else

{

return sum;

}

}

return k;

}

}





why is it showing a runtime error!!???




someone plzzz help me!!!

  i have seen so many guys

raman bhatia @ 19 Jun 2010 05:38 PM

 

i have seen so many guys facing a porblem in this one.. its easy.. perform DP and store the results as soon as u calculate any value.. this will prevent all those unnecessary recursions thus leading to TLEs
if u still face ny problem, you can even contact me on fb http://www.facebook.com/#!/profile.php?id=100000701735367

Hi Admins Please check my

everest @ 25 Jun 2010 06:46 PM

Hi Admins

Please check my solution to the problem. Its giving WA. Can you give a clue as to what could be going wrong?

@Rajat You haven't tried the

javadecoder @ 25 Jun 2010 06:57 PM

@Rajat

You haven't tried the worst case,it gives wrong answer for n=1000000000.

@Piyush I have tried for the

everest @ 25 Jun 2010 10:27 PM

@Piyush

I have tried for the worst case which n=10^9. The answer I get is 4243218150.

It matches with the answer reported by coders above. What could be going wrong? I am using unsigned long int but I am testing on 64-bit system. Do you think that could be the culprit? I'll try variations and check as well.

Whoa finally got it. Time:

everest @ 25 Jun 2010 11:03 PM

Whoa finally got it. Time: 0.00 and Mem: 2.1M Yay!

The mistake was in the interpretation difference of unsigned long int in 32bit and 64bit systems I guess.. Converting to long long int did the trick.

why map.h can't support this

rijin @ 1 Jul 2010 01:42 PM

why map.h can't support this c++; or which type can i select to compile please help me?

my programs run fine in BlueJ

uniquetrij @ 20 Jul 2010 10:55 AM

my programs run fine in BlueJ but every time i submit them here it says wrong answer... what is the reason???

what will be the worst case

uniquetrij @ 20 Jul 2010 11:19 AM

what will be the worst case result? is it not 1083333333 ?? then what is it?

The answer is a lot more than

triplem @ 20 Jul 2010 01:01 PM

The answer is a lot more than that. Don't forget if you exchange once, you are receiving coins that can be exchanged again..

@Admin: I have implemented

satbirsoni @ 2 Aug 2010 06:04 PM

@Admin: I have implemented solution using recursion.But i am exceeding time limit.i have few question

 

-> is it a mathmatical problem and we have to device a forumal and implement it.?

-> can me use multi-threading ?

Hi, I can see my solution

ahsan_82@hotmail.com @ 11 Aug 2010 12:22 AM

Hi,

I can see my solution working fine in my computer, but the admin says wrong answer. Can anyone tell me what should be the input and output type? I tried files named input.txt, output.txt, input, output. But nothing works.

FAQ

triplem @ 11 Aug 2010 02:31 AM

FAQ

Hi, I tried with the

ahsan_82@hotmail.com @ 11 Aug 2010 06:36 PM

Hi,

I tried with the following format for this problem but still shows wrong answer.

./coin.exe <input.txt> <out.txt>

Could anyone tell me is that the correct way for testing the code? I am really confused.

@Mohammad Ahsan:-/coin.exe

anish7766 @ 11 Aug 2010 07:31 PM

@Mohammad Ahsan:-/coin.exe <input.txt >out.txt

Hi admin, Can you please

crazycoder @ 18 Aug 2010 04:19 PM

Hi admin,

Can you please check my code.I am getting runtime error.My code works fine on my machine.

http://www.codechef.com/viewsolution/309605

which data tupe to use to

coolsainideepak @ 21 Aug 2010 01:33 PM

which data tupe to use to store 10^9???

@deepak long int

anubhav.7nov @ 21 Aug 2010 09:20 PM

@deepak

long int

#include <iostream>#include

akshaydixi @ 24 Aug 2010 11:51 AM
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. using namespace std;
  5. long long fn (long long);
  6. int main()
  7. {
  8. int t;
  9. long long n;
  10. cin>>t;
  11. for(int i=0;i<t;i++)
  12. {cin>>n;
  13. cout<<fn(n)<<endl;}
  14. return 0;
  15. }
  16.  
  17. long long fn(long long n)
  18. {
  19. long x,y,z;
  20. long a=n/2;
  21. long b=n/3;
  22. long c=n/4;
  23. if( (a+b+c) > n)
  24. {
  25. x=fn(a);
  26. y=fn(b);
  27. z=fn(c);
  28. if(x>a)
  29. a=x;
  30. if(y>b)
  31. b=y;
  32. if(z>c)
  33. c=z;
  34. return a+b+c;
  35. }
  36. else return n;}
  37.  

canr see whats the problem
im getting correct output for every no ive tried

Why WA with my

ostadk1 @ 25 Aug 2010 07:00 PM

Why WA with my program?

#include<iostream>
using namespace std;
int main(){
long long n;
long long i;
int j=0;
while(cin>>n)
{
j++;
i=int(n/2)+int(n/3)+int(n/4);
if(n>i)
cout<<n<<endl;
else
cout<<i<<endl;
if(j==10)
break;
}
return 0;
}

@All, hey people. you all

thechamp @ 26 Aug 2010 05:01 PM

@All, hey people. you all found that for 10^9 answer should be 4243218150, but if you further exchange this amount you get 4596819662. which can be further exchanged and you get even higher amount. how could you stop at 4243218150? am i missing something?

That final answer you come up

triplem @ 27 Aug 2010 02:32 AM

That final answer you come up with for 10^9 is all using very small coins, which can't be further exchanged.

i still could not get. can

thechamp @ 27 Aug 2010 07:35 PM

i still could not get. can you please elaborate.

thnx Stephen, i got your

thechamp @ 27 Aug 2010 09:21 PM

thnx Stephen, i got your point :)

what is the terminating

e2e @ 29 Aug 2010 05:56 PM

what is the terminating condition for this problem?

When they say that there are

ritesh104 @ 29 Aug 2010 09:27 PM

When they say that there are multiple test case and there is no terminating condition given , you should assume that EOF is the terminating condition.

please someone help me with

ashishrathi @ 1 Sep 2010 06:02 PM

please someone help me with this code....

i hv cheked it on my machine it gives correct answer ....

pls help...

 

#include<stdio.h>
#include<iostream>

using namespace std;

long int *a = new long int[1000001];

long int max(long int b)
{
if(b>1000000)
return (max(b/2)+max(b/3)+max(b/4));
else
return a[b];
}




int main()
{
long int i ;

for(i=0 ; i<=11 ; i++)
a[i]=i;

for(i=12 ; i<=1000000 ; i++)
a[i]=a[i/2]+a[i/3]+a[i/4];

long int sol[10] , temp;

i=0;
while(scanf("%ld",&temp) && i<10)
{
if(temp>1000000)
sol[i]=max(temp);
else
sol[i]=a[temp];
i++;
}

for(long int j=0 ; j<i ; j++)
cout<<sol[j]<<"n";

delete []a;
a=NULL;
return 0;
}

hey ADMIN pls help..

ashishrathi @ 2 Sep 2010 06:23 PM

hey ADMIN pls help..

my run id is 331160. the code

teddy_coders @ 12 Sep 2010 02:27 PM

my run id is 331160. the code is running good on pc for all inputs even some test cases devised by me.bt codechef is again and agin givin run time error.i have checked fr array overflow and underflow bt still thats not the problem.admins pls check

my run id is 331160. the code

teddy_coders @ 12 Sep 2010 02:27 PM

my run id is 331160. the code is running good on pc for all inputs even some test cases devised by me.bt codechef is again and agin givin run time error.i have checked fr array overflow and underflow bt still thats not the problem.admins pls check

100000000 long longs uses far

triplem @ 12 Sep 2010 02:36 PM
100000000 long longs uses far too much memory.

@admin my code is running

kushsharma @ 14 Sep 2010 11:40 PM

@admin

my code is running successfully on my machine..it is well within time limits..

but on submitting here..it gave runtime error..help..?

// COINS   package

mohit2kewl @ 15 Sep 2010 12:13 AM

// COINS

 

package practice;

 

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

 

public class Main {

 

public static void main(String[] args) throws  IOException {

 

int N;

double a,b,c;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String array [] = new String[10];

 

 

int count=0;

 

while(!(array[count] = br.readLine()).equals("")) {

 

N = Integer.parseInt(array[count]);

a = Math.floor(N/2);

b = Math.floor(N/3);

c = Math.floor(N/4);

 

if((a+b+c)>N) {

 

System.out.println( (int) (a+b+c));

}

 

else {

 

System.out.println(N);

}

 

count++;

}

 

}

 

}

- wat is wrong with this ?

#include<stdio.h>     int

ejoe @ 16 Sep 2010 11:28 PM

#include<stdio.h>

 

 

int main()

{

long int n,s;

long cal(long);

while(scanf("%dl",&n) != EOF)

{

// printf("n%ld",n);

printf("n%ld",cal(n));

}

return 0;

}

 

long int cal(long int n)

{

long int a,k;

long int b;

long int c;

while(n != 0)

{

a = cal(n/2);

b  = cal(n/3);

c = cal(n/4);

k = a + b + c;

if(k > n)

return k;

else

return n;

}

}

my program shows time limit excluded.can some1 just say if dere is another logic or something behind solving this...plsss just give me a hint and not more than that

Dear

geddamsatish @ 17 Sep 2010 10:51 AM

Dear Admin

http://www.codechef.com/viewsolution/333304

Can you tell me whats wrong but its working on my computer

 

Have another look at the

triplem @ 17 Sep 2010 01:01 PM

Have another look at the input section. Your code only prints 13 for the sample input, then stops.

this is my code. it is giving

pandyajay1 @ 19 Sep 2010 04:17 PM

this is my code.

it is giving right output.

so why is it giving wrong answer.......????????

please check this........

#include<stdio.h>
int main()
{
float n=10,k=0,a;
while(n>0)
{
scanf("%f",&a);
if(a<0 && a>1000000000)
{
break;
}

if(a<=1000000000 && a>=0)
{
k=(13*a)/12;
printf("%0.0fn",k);
}
if(a<0 && a>1000000000)
{
break;
}
n--;
}
return 0;
}

I'm afraid it gives the wrong

triplem @ 20 Sep 2010 05:03 AM

I'm afraid it gives the wrong output on nearly every single test case. For example, the output for 13 should be 13, not 14.

yap.my code was wrong as i

pandyajay1 @ 20 Sep 2010 03:49 PM

yap.my code was wrong as i thought we can exchange  the gold  coin only ones with bank......

here are my test results i

vfix @ 23 Sep 2010 12:32 AM
here are my test results i think all of them are correct...but still getting wrong answer......(each test case and its result is seperated by "----------------------------" with the other test case and its result)...have a look...any suggestions? large testcase: 325654 706123 ---------------------------- 65659 130624 ---------------------------- 54454899 187812070 ---------------------------- 1000000000 4243218150 ---------------------------- 56689 113327 ---------------------------- 99999 203708 ---------------------------- 999999 2566393 ---------------------------- 8488798 24972042 ---------------------------- 89899889 323166474 ---------------------------- 48779 93732 ---------------------------- 8898998 25750058 ---------------------------- 45554899 153069088 ---------------------------- 45487996 153069088 ---------------------------- 7878788787 40516397183 ---------------------------- 96587446 357562933 ---------------------------- small testcase 0 0 ---------------------------- 1 1 ---------------------------- 2 2 ---------------------------- 3 3 ---------------------------- 4 4 ---------------------------- 5 5 ---------------------------- 6 6 ---------------------------- 7 7 ---------------------------- 8 8 ---------------------------- 9 9 ---------------------------- 10 10 ---------------------------- 11 11 ---------------------------- 12 13 ---------------------------- 13 13 ---------------------------- 14 14 ---------------------------- 15 15 ---------------------------- 16 17 ---------------------------- 17 17 ---------------------------- 18 19 ---------------------------- 19 19 ---------------------------- 20 21 ---------------------------- 21 22 ---------------------------- i have used "-----------------------------------" only here ...not in my submission

oops sorry for that.....think

vfix @ 23 Sep 2010 12:35 AM
oops sorry for that.....think i forgot to use "
" tag

here are my test case

vfix @ 23 Sep 2010 12:44 AM
here are my test case result.....(sorry for the previous posts)..... large testcase
325654
706123
----------------------------
65659
130624
----------------------------
54454899
187812070
----------------------------
1000000000
4243218150
----------------------------
56689
113327
----------------------------
99999
203708
----------------------------
999999
2566393
----------------------------
8488798
24972042
----------------------------
89899889
323166474
----------------------------
48779
93732
----------------------------
8898998
25750058
----------------------------
45554899
153069088
----------------------------
45487996
153069088
----------------------------
7878788787
40516397183
----------------------------
96587446
357562933
----------------------------
small test case 0
0
----------------------------
1
1
----------------------------
2
2
----------------------------
3
3
----------------------------
4
4
----------------------------
5
5
----------------------------
6
6
----------------------------
7
7
----------------------------
8
8
----------------------------
9
9
----------------------------
10
10
----------------------------
11
11
----------------------------
12
13
----------------------------
13
13
----------------------------
14
14
----------------------------
15
15
----------------------------
16
17
----------------------------
17
17
----------------------------
18
19
----------------------------
19
19
----------------------------
20
21
----------------------------
21
22
----------------------------

oh my god....i should have

vfix @ 23 Sep 2010 02:22 AM
oh my god....i should have read the input format clearly.... @stephen...read your comments on the input format .....thats when i realized that i need to correct the way in which my program is taking the input.... ;)

RUNTIME ERROR message

sharad_banka @ 26 Sep 2010 03:33 AM

RUNTIME ERROR message conflict.

When I check "all submissions" section, then the runtime error for my submission suggests error SIGSEGV, where as in the "my submissions" section the runtime error is OTHER.

Why this discrepancy ?

Also, I dont get a runtime

sharad_banka @ 26 Sep 2010 03:51 AM

Also, I dont get a runtime error on my end, for 10 successive inputs of 1000000000, when using gcc on linux. I get proper result. Why am i getting a runtime error, as output ? Can I have the test cases for which my input faces segmentation fault ?

Why I got wrong answer if on

giullianom @ 28 Sep 2010 11:22 PM

Why I got wrong answer if on all tests cases that I make, the results got ok.

 

public class Main {

private final static Scanner scanner = new Scanner(new InputStreamReader(System.in));

public static void main(String... args) throws IOException {
/*
* For manual test
* String [] inputs = new String [] {"0", "2", "325654", "7878788787" };
*/

String [] inputs = scanner.next().split(" ");

for (String s:inputs){
long moeda = Long.valueOf(s);

int moeda1 = new Double(moeda / 2).intValue();
int moeda2 = new Double(moeda / 3).intValue();
int moeda3 = new Double(moeda / 4).intValue();
long lucro = (moeda1 + moeda2 + moeda3);

System.out.println(lucro < moeda ? moeda : lucro);
}
}
}

Firstly, it gives the wrong

triplem @ 29 Sep 2010 06:30 AM

Firstly, it gives the wrong answer on the sample input since it only prints out 13, not the 2 on the second line.

Secondly, it gives wrong answer on almost every other input. For example, the answer for 100 is 120, not 118. If you don't understand why, try reading the other comments.

#include <iostream>using

khanaleemullah @ 6 Oct 2010 05:15 PM

#include <iostream>

using namespace std;
long long coin(int,int[]);
int main()
{
int t,x;
scanf("%d",&t);
while(t--){
scanf("%d",&x);
long long int arr[1000000000];

int res=coin(x,arr);
printf("%d  n",res); 
}
system("pause");
return 0;
}

long long int coin(int y,int c[])
if(y<1)
return 0;
if(y==1)
return 1;
if(c[y]!=-1)
return c[y];
long long int t=coin(y/2)+coin(y/3)+coin(y/4);
c[y]=t;
return c[y];
}

sir pls tell me where i m rong???

i mean Stephen Merriman sir

khanaleemullah @ 6 Oct 2010 05:16 PM

i mean Stephen Merriman sir pls help me out...i m really tired naw....pls sir...i m sstuck in these for 1 week ..!!!

according to above comments

rohit_tats @ 10 Oct 2010 08:29 PM

according to above comments 1000000000 gives result 4243218150. how??

1000000000/2 =500000000

1000000000/3=333333333

1000000000/4=250000000

 

total=1083333333 should be the answer.

where am i wrong??


my program is working for all

sricha @ 10 Oct 2010 11:58 PM

my program is working for all test cases except the extreme one of 1000000000...any suggestions of how can i improve my code.

hey evry1... whats the prob

tarun550 @ 15 Oct 2010 05:32 PM

hey evry1... whats the prob with my code???

#include<iostream>
#include<math.h>
using namespace std;
main()
{   
for(int counter1=0;counter1<10;counter1++)
{
long long int a,num[3],f=0,g=0,h=0;
long long int sum1,sum2=0;
cin>>a;
if(a<1000000001&&a>0)
{sum1=a;
num[0]=a/2;
num[1]=a/3;
num[2]=a/4;
if((num[0]+num[1]+num[2])<a)
{
cout<<a;
}
else
{
if((num[0]+num[1]+num[2])>=a)                           
{
while(sum1>sum2)
{                        
for(int counter3=0;counter3<2;counter3++)
{
f=num[counter3]/2;
g=num[counter3]/3;
h=num[counter3]/4;
if(num[counter3]<(f+g+h))
{
num[counter3]=(f+g+h);
}
}
sum2=sum1;
sum1=(num[0]+num[1]+num[2]);
}
}
cout<<sum1;}}}}


can someone help me with my

codeur @ 29 Oct 2010 01:15 AM

can someone help me with my code... its working for small inputs but not for large one

#include<iostream>

#include<vector>

 

using namespace std;

 

int main()

{

vector<unsigned long> one;

//unsigned long one[50];

unsigned long n,a,b,c,m;

 

int i=0,x=0;

 

while((scanf("%lu",&n))&&x<10)

{

x++;

i=0;

m=n;

one.push_back(n);

 

while(!one.empty())

{

n=one.back();

one.pop_back();

i--;

a=n/2;

b=n/3;

c=n/4;

 

if((a+b+c)>=n)

{

m+=a+b+c-n;

 

one.push_back(a);

one.push_back(b);

one.push_back(c);

 

}

else

{

if(!one.empty())

{

n=one.back();

one.pop_back();

}

}

 

}

printf("%lun",m);

}

 

return 0;

}

the variable i is useless in

codeur @ 29 Oct 2010 01:16 AM

the variable i is useless in above code, plz dont pay attention to that :)

It should be pretty easy to

triplem @ 29 Oct 2010 04:34 AM

It should be pretty easy to see why it doesn't work on large inputs by testing it with an input of 1000000000. You'll need to come up with a more clever algorithm. You're repeating several calculations that you don't need to.

hello admin  i used simple

iiit @ 29 Oct 2010 07:45 PM

hello admin  i used simple recurssion but it exceeds time limit and i dont know anything about caching ,how to go about it....

Hi admin, Please tell me wats

nitin2goyal @ 1 Nov 2010 09:57 PM

Hi admin,

Please tell me wats wrong with my code..It says wrong answer but i think my code is fine

#include<iostream>

using namespace std;

int main()

{

long int i,j;

while(cin>>i)

{

j=(i/3)+(i/2)+(i/4);

if(j>i)

cout<<j<<"n";

else

cout<<i<<"n";

}

return 0;

}

#include <iostream> #include

gjthedon @ 3 Nov 2010 12:36 AM

#include <iostream>

#include <vector>

#include <algorithm>

#include <cstdlib>

#include <cstdio>

 

using namespace std;

 

vector <long unsigned int> memo;

vector <long unsigned int> index;

 

long unsigned int maxDollars( long unsigned int n );

long unsigned int maximum ( long unsigned int x, long unsigned int y );

 

int main()

{

long unsigned int input;

cin>> input;

while( input != EOF )

{

index.clear();

memo.clear();

index.push_back(0);

memo.push_back(0);

 

index.push_back(1);

memo.push_back(1);

 

cout<<maxDollars(input)<<endl;

 

}

}

 

long unsigned int maxDollars( long unsigned int n )

{

vector<long unsigned int>:: iterator p = find( index.begin(), index.end(), n );

if( p != index.end() )

{

return memo[ p - index.begin() ];

 

 

}

 

else

{

 

long unsigned int maxProfit = maximum( n, maxDollars( n/2 ) + maxDollars( n/3 ) + maxDollars( n/4 ) );

index.push_back( n );

memo.push_back( maxProfit);

 

return maxProfit;

 

}

 

 

 

 

}

 

long unsigned int maximum ( long unsigned int x, long unsigned int y )

{

 

return (x > y)?x:y;

}

How many times can we go to

icode @ 28 Nov 2010 08:50 PM

How many times can we go to the bank? I keep getting it right in VS2010 Prem., but it keeps telling me "Runtime error" when I do it on CC!

Also, will it enter a line

icode @ 28 Nov 2010 08:51 PM

Also, will it enter a line after it finishes?will it be:

100

1230

12301

231290

12390

 

end. or would it be

332904

23409923

23490

23940

end?

You can go as many times as

triplem @ 29 Nov 2010 06:04 AM

You can go as many times as you like, not just once. There won't be a blank line at the end; read your programming language documentation for what Console.ReadLine() returns when it reaches the end of the input stream.

@stephen,admin: can you

ChunChun @ 30 Nov 2010 02:06 AM

@stephen,admin: can you please take a look at http://www.codechef.com/viewsolution/385682 . I'm getting a TLE :|

Have you tested your code on

triplem @ 30 Nov 2010 02:26 AM

Have you tested your code on the largest input? Should have been easy to see it would get a TLE without submitting it. Should also show you why that algorithm wouldn't work; you'll need something better.

hey stephen, can u plz see my

algomm @ 30 Nov 2010 04:42 AM

hey stephen,

can u plz see my solution and tell me why am i getting runtime answer.
my solution id is 385703.

Your array uses about 238mb

triplem @ 30 Nov 2010 05:29 AM

Your array uses about 238mb of memory - that's far more than you're allowed.

//sumitdugar #include<iostrea

sumitdugar @ 13 Dec 2010 10:11 PM

//sumitdugar

#include<iostream>

using namespace std;

 

long int dollar=0;

void gold(long int);

 

int main()

{

int test=1;

long int coin;

do{

dollar=0;

cin>>coin;

gold(coin);

cout<<dollar<<endl;

test++;

}while(test!=10);

system("pause");

}

 

void gold(int long coin)

{

long int a,b,c;

a=coin/2;

b=coin/3;

c=coin/4;

if((a+b+c)<=coin)

dollar+=coin;

else

{

gold(a);

gold(b);

gold(c);

}

}

how can i improve it's performance.....it's taking around 15 sec

//sumitdugar #include<iostrea

sumitdugar @ 13 Dec 2010 10:21 PM

//sumitdugar

#include<iostream>

using namespace std;

 

long int dollar=0;

void gold(long int);

 

int main()

{

int test=1;

long int coin;

do{

dollar=0;

cin>>coin;

gold(coin);

cout<<dollar<<endl;

test++;

}while(test!=10);

system("pause");

}

 

void gold(int long coin)

{

long int a,b,c;

a=coin/2;

b=coin/3;

c=coin/4;

if((a+b+c)<=coin)

dollar+=coin;

else

{

gold(a);

gold(b);

gold(c);

}

}

how can i improve it's performance.....it's taking around 15 sec

//sumitdugar #include<iostrea

sumitdugar @ 13 Dec 2010 10:21 PM

//sumitdugar

#include<iostream>

using namespace std;

 

long int dollar=0;

void gold(long int);

 

int main()

{

int test=1;

long int coin;

do{

dollar=0;

cin>>coin;

gold(coin);

cout<<dollar<<endl;

test++;

}while(test!=10);

system("pause");

}

 

void gold(int long coin)

{

long int a,b,c;

a=coin/2;

b=coin/3;

c=coin/4;

if((a+b+c)<=coin)

dollar+=coin;

else

{

gold(a);

gold(b);

gold(c);

}

}

how can i improve it's performance.....it's taking around 15 sec

//sumitdugar #include<iostrea

sumitdugar @ 13 Dec 2010 10:21 PM

//sumitdugar

#include<iostream>

using namespace std;

 

long int dollar=0;

void gold(long int);

 

int main()

{

int test=1;

long int coin;

do{

dollar=0;

cin>>coin;

gold(coin);

cout<<dollar<<endl;

test++;

}while(test!=10);

system("pause");

}

 

void gold(int long coin)

{

long int a,b,c;

a=coin/2;

b=coin/3;

c=coin/4;

if((a+b+c)<=coin)

dollar+=coin;

else

{

gold(a);

gold(b);

gold(c);

}

}

how can i improve it's performance.....it's taking around 15 sec

Can some1 tell me y dis is a

vinaymajety @ 14 Dec 2010 08:54 PM

Can some1 tell me y dis is a wrong solution??

 

// americandollar.cpp : Defines the entry point for the console application.
//


#include<stdio.h>
#include<stdlib.h>


void value(int);
int main()
{
int no_cases = 0,i=0;
int *a;
printf("Enter no of testcases");
scanf("%d",&no_cases);
a=(int *)malloc(no_cases*sizeof(int));
for(i=0;i<no_cases;i++)
scanf("%d",&a[i]);
for(i=0;i<no_cases;i++)
value(a[i]);

getch();
return 0;
}

void value(int n)
{
int sum=0;
sum=sum+n/2;
sum=sum+n/3;
sum=sum+n/4;
if(sum>n)
printf("n%d",sum);
else
printf("n%d",n);
}



y do v need to use a file fr

lanky @ 15 Dec 2010 11:47 AM

y do v need to use a file fr tis one...????

cant it b done widout a file...???

do v need to save the input and output for future use....???

Someone please look at this

tarun_kumar @ 15 Dec 2010 02:17 PM

Someone please look at this code.

http://www.codechef.com/viewsolution/399840

I tried with all the possible output with the extreme cases, my program is using around 38M of memory, not much.

but still I am getting a wrong answer. If possible please tell me a test case in which my program will print wrong answer.

Thank you

I'm not sure what compiler

triplem @ 15 Dec 2010 03:14 PM

I'm not sure what compiler you're using, but when I enter 1000000000 it prints that same number back again, which isn't the answer.

to Stephen Merriman i m using

tarun_kumar @ 15 Dec 2010 04:08 PM

to Stephen Merriman

i m using gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

when i enter 1000000000 my program give me 4243218150

is this output correct?

Posting a second comment

triplem @ 16 Dec 2010 02:37 AM

Posting a second comment saying 'please reply' isn't going to help at all.

I'm not sure why you are getting that output, but that isn't the output your program produces on the judge. Fix up your data types - you call n a long int, then pass it to a function as an int parameter. You then have an array of unsigned ints which are are assigning long ints to then return the unsigned int as a long int.. etc. It's not surprising you end up with the wrong answer :P

//Should I know what is wrong

amitkmr42 @ 17 Dec 2010 10:43 PM

//Should I know what is wrong in this program?

 

#include<iostream>

using namespace std;

main()

{

long i,n,c=0;

A:

{

cin>>n;

 

}

while(n!=EOF)

{

i=(n/2)+(n/3)+(n/4);

if(i>n)

cout<<i<<"n";

else

cout<<n<<"n";

c++;

if(c==10)

break;

goto A;

}

return(0);

}

#include <iostream>using

beginning2end @ 24 Dec 2010 04:46 AM

#include <iostream>
using namespace std;

int main()
{
int a[10000];

long int x,ptr;
ptr =1;

while(cin>>x)
{
long long int sum=0;
if(x<12)

printf("%un",x);
else
{
a[ptr]=x;

while(ptr>=1)
{
if(a[ptr]>11)
{
x = a[ptr];

ptr--;
a[ptr+1]= x/2;
a[ptr+2]= x/3;
a[ptr+3]= x/4;
ptr= ptr+3;
if(a[ptr]>11)
continue;
};
sum+=a[ptr];
ptr--;
}
printf("%u n",sum);  
}
ptr=1;
};          
return 0;

}

giving right results but exceeding time limit by a couple of seconds. how can i improve it.

ive executed this code for

karthiks3000 @ 28 Dec 2010 05:31 PM

ive executed this code for almost all possibilities. im getting all the right outputs. still my submission is not being accepted. can anyone please tell me why????

this is my code

 

import java.io.*;

import java.util.*;

 

class coins

{

public static void main(String args[])throws IOException

{

 

BufferedReader b=new BufferedReader(new InputStreamReader(System.in));

 

int i=0,n=0;

 

int no=0;

 

String pno=b.readLine();

while(pno !=null && i<10)

{

no=Integer.parseInt(pno.trim());

i++;

if(no>0 && no<= 1000000000)

{

int n2,n3,n4;

n2=no/2;

n3=no/3;

n4=no/4;

 

if((n2+n3+n4)<=no)

{

System.out.println(no);

}

else

{

System.out.println((n3+n2+n4));

}

}

 

 

pno=b.readLine();

}

}

}

 

You can exchange coins

triplem @ 29 Dec 2010 02:11 AM

You can exchange coins multiple times.

i wish to ask that if i put

mygaurav @ 1 Jan 2011 10:14 PM

i wish to ask that if i put the line

int* a=(int*)malloc((10001)*sizeof(int));

as global, it gave the error "initialiser element not constant" although i was not getting such an error with TC 4.5

Plz explain

 

How do u enter EOF through keyboard?

Hey How can you find out the

kaushikb @ 14 Jan 2011 08:30 PM

Hey

How can you find out the time your program runs? Ex i am not sure how mine is exceeding the 9 sec limit. So i want to Check how long it is actually taking

@stephen sir-i can't see why

anurag108 @ 17 Jan 2011 11:32 PM

@stephen sir-i can't see why i am getting wrong answer.please help

thank you

http://www.codechef.com/viewsolution/425469

  public class Coins {  

sumitnsit @ 21 Jan 2011 03:52 PM

 

public class Coins {

 

public static void main(String[] args) {

System.out.println(test(100));

}

public static int  test(int num){

int a = num/2;

int b = num/3;

int c = num/4;

int d = a + b + c;

if(d>num){

d = test(d);

} else {

d = num;

}

return d;

}

}

Can Someone tell me whats

prince1991 @ 23 Jan 2011 04:29 PM

Can Someone tell me whats wrong with my code?? After submitting everytime its giving "Wrong Answer"

 

#include<stdio.h>

 

int main()

{

//int count=0;

long int money;

long int denom;

long int flag=0;

int test=0;

 

while(test<=9)

{

flag=scanf("%ld",&money);

 

if(flag==EOF)

break;

 

denom=(money/2)+(money/3)+(money/4);

 

if(denom>money)

printf("%ldn",denom);

else

printf("%ldn",money);

 

test++;

}

 

return 0;

 

}

Can i know the reason for a

sachin004 @ 24 Jan 2011 06:56 PM

Can i know the reason for a python runtime error?? the code works fine on my computer

I'm not sure how you are

triplem @ 25 Jan 2011 09:56 AM

I'm not sure how you are testing your code, since it will give a runtime error on every single input file on any computer due to you handling EOF incorrectly.

(If you fix that, it will give wrong answer on nearly every single input because, as mentioned many times already, nobody said you can only exchange a coin once.)

Hi everyone I am new to

tariq_bhat @ 1 Feb 2011 10:02 AM

Hi everyone

I am new to CODECHEF and i need a little help here.

Can any one of you please see the following solution for the problem

and help me in finding out why am i getting a time limit exceeded result

http://www.codechef.com/viewsolution/440676

 

Best regards

Tariq

You have a while(1) loop

triplem @ 1 Feb 2011 11:16 AM

You have a while(1) loop which never ends - you only break when there is a -1 in the input, but there is never a -1 in the input. You should break on EOF - end of file.

Thanks Stephen Merriman. so

tariq_bhat @ 3 Feb 2011 02:56 PM

Thanks Stephen Merriman. so here onwards i have to assume that all submissions will take input from a file. and i have to write code accordingly.

The input comes from the

triplem @ 3 Feb 2011 03:27 PM

The input comes from the standard input stream, but EOF is how input streams represent that they have finished. See the FAQ if you still aren't sure how your code is tested.

Can anybody tell me any test

syst3mw0rm @ 8 Feb 2011 06:44 PM

Can anybody tell me any test case (N>=12) for which the number itself is greater than the case when it is divided into pieces : N/2 , N/3 , N/4 ...

I have got my answer correct but i used to get wrong answer when i don't compare between N and the case when N is broken into N/2,N/3,N/4..

what is the error in this

sachin_nagar @ 8 Feb 2011 10:01 PM

what is the error in this code..on compiling compiler shows that Type mismatch in redeclaration of 'split'.

please help me.

 

#include<stdio.h>
long long split(long long);
int main(void)
{
long long n,result;
scanf("n%lld",&n);
result=split(n);
printf("n%lld",result);
return 0;
}

split(long long n)

{
if(n<(n/2+n/3+n/4))
return split(n/2)+split(n/3)+split(n/4);
else
return n;
}

I think this is correct

syst3mw0rm @ 8 Feb 2011 11:51 PM

I think this is correct version :

#include<stdio.h>
long long split(long long);
int main(void)
{
long long n,result;
scanf("n%lld",&n);
result=split(n);
printf("n%lld",result);
return 0;
}

long long split(long long n)

{

if(n<(n/2+n/3+n/4))
return split(n/2)+split(n/3)+split(n/4);
else
return n;
}

 

You should write the return type of function while defining it..otherwise it will try to take it as default int and that's why it shows type mismatch

@Amir...thanks a lot buddy

sachin_nagar @ 9 Feb 2011 10:30 AM

@Amir...thanks a lot buddy ..i just forgot to write return type ..

please chck ot this and tell

sachin_nagar @ 9 Feb 2011 10:52 AM

please chck ot this and tell me that what is the problem in this code .i tested it and it is running correctly..please i need your suggestion.

 

http://www.codechef.com/viewsolution/450412

Your code doesn't work on the

triplem @ 9 Feb 2011 10:56 AM

Your code doesn't work on the sample input, nor the largest possible test case. Perhaps you need to read the input section again.

i think that problem is of

sachin_nagar @ 9 Feb 2011 11:13 AM

i think that problem is of time limit exceed...but why it is showing wrong answer on submisson.i tested it with a sample in.txt and record output  in out.txt.

can you please tell me that what would be the output for input 1000000000.so that i could debug my code more precisely.

Like I said, your code does

triplem @ 9 Feb 2011 11:52 AM

Like I said, your code does not give the right answer on the sample input. Read the input section or the sample input. It certainly doesn't say the first number is the number of test cases.

If you're not sure how to test your code, see the FAQ.

feeling hope less

shriniwas814 @ 10 Feb 2011 07:45 PM

feeling hope less .......please help me

what is the problem with my code ??

 

#include<stdio.h>
int main()
{
unsigned long int n;
static double p;
int i=0;
int j;

while(scanf("%ld",&n)!=EOF)
{
if(n<(n/2+n/3+n/4))
printf("%ld",(n/2+n/3+n/4));
else
printf("%ld",n);
}


return 0;
}

please check my code

shriniwas814 @ 10 Feb 2011 07:48 PM

please check my code ...

 

#include<stdio.h>
int main()
{
double n;


while(scanf("%lf",&n)!=EOF)
{
if(n<(n/2+n/3+n/4))
printf("%.0lfn",(n/2+n/3+n/4));
else
printf("%.0lfn",n);
}


return 0;
}

I am getting runtime error.

itreallyisme @ 19 Feb 2011 04:22 PM

I am getting runtime error. What is wrong with this code?

 

#include<stdio.h>

#include<stdlib.h>

 

unsigned long long int best[100] = {0};

 

unsigned long long int getBest(unsigned long long int n)

{

if(n < 100 && best[n])

return best[n];

unsigned long long int temp;

temp = getBest(n/2) + getBest(n/3) + getBest(n/4);

if(temp > n)

{

if(n < 100)

best[n] = temp;

return temp;

}

else

{

if(n < 100)

best[n] = n;

return n;

}

}

 

int main()

{

int count = 0, i;

unsigned long long int temp[10];

best[1] = 1;

best[2] = 2;

best[3] = 3;

best[4] = 4;

unsigned long long int n;

while(scanf("%llu", &n) != EOF)

{

temp[count] = n;

count++;

}

for(i=0; i<count; i++)

printf("%llun", getBest(temp[i]));

exit(0);

}

Can someone tell me the prob.

gndps @ 23 Feb 2011 12:15 AM
Can someone tell me the prob. with my code
its not running on my pc
i tried to run it on codepad..its not working

int
main()
//function mr stands for max return
{
int down(int n);
int greater(int a,int b);
int mr(int n);
int n=12;
printf("enter n:");

down(n);
}
int down(int n)
{
if (n=0)

{return(0);}
else{
int max,a,b,c,sum;
a=n/2;
b=n/3;
c=n/4;
max=mr(a)+mr(b)+mr(c);
return(max);
}}

int greater(int a,int b)
{
if (a>b)
{return(a);}
else
{return(b);}
}
int mr(int n)
{
if (n=0)
{
return(0);
}
else
{
int x,final;
x=down(n);
final=greater(x,n);
return(final);

}
}

can you tell me the prob with

gndps @ 23 Feb 2011 12:18 AM
can you tell me the prob with my code
i've made it only for a single value

int
main()
//function mr stands for max return
{
int down(int n);
int greater(int a,int b);
int mr(int n);
int n=12;
printf("enter n:");

down(n);
}
int down(int n)
{
if (n=0)

{return(0);}
else{
int max,a,b,c,sum;
a=n/2;
b=n/3;
c=n/4;
max=mr(a)+mr(b)+mr(c);
return(max);
}}

int greater(int a,int b)
{
if (a>b)
{return(a);}
else
{return(b);}
}
int mr(int n)
{
if (n=0)
{
return(0);
}
else
{
int x,final;
x=down(n);
final=greater(x,n);
return(final);

}
}

if possible upload a tutorial

turjachaudhuri @ 19 Mar 2011 03:01 PM

if possible upload a tutorial on how to handle this problem!!!the logic is quite simple but since the input size is daunting....efficient handling of data and programming tricks are required,which being a newbie i can't fathom!!!so i need some help from ur side

@admin:I hav checked my

aniket_divekar @ 19 Mar 2011 08:56 PM

@admin:I hav checked my answers with more than 10 accepted solutions...i'm gettin d same ans as they are gettin..bt its givin me Wrong Answer....plz elaborate....i'll b more than happy if it says Time Limit Exceeded..but Wrong Answer certainly puts ur head for a round..:( :( :(

can any one tell me whts

suman3majee9 @ 19 Mar 2011 11:18 PM

can any one tell me whts wrong with d code

#include<stdio.h>
main()
{
int no,q;
while(1)
{
scanf("%d",&no);
q = no/12 ;
printf("%dn",13*q + (no%12)) ;
}
}

for n= 13 we can break it to 12+1
we can get $13 from 12 and 1$1 from 1
so $14

but the submitted codes are giving $13



@Soumendu : u either can

aniket_divekar @ 20 Mar 2011 05:55 PM

@Soumendu : u either can convert coin into american dollars directly or u have to divide them into three coins(n/2,n/3,n/4)

@Turja Narayan Chaudhuri The

lesley_t @ 20 Mar 2011 07:09 PM

@Turja Narayan Chaudhuri


The comments already have lot of hints: recursion+memoization.

can any tell whats wrong in

eagle06 @ 24 Mar 2011 11:33 PM

can any tell whats wrong in this code.

 


    import java.io.*;
    public class Main{
    public static void main(String[] args) {
    BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    long[] n = new long[10];
    long[] m = new long[10];
    int i=0,y=0;
    try{
    while(br.readLine()!=null){
    n[i]=Long.parseLong(br.readLine());
    m[i]= n[i]/2 + n[i]/3 + n[i]/4;
    i++;
    }
    
    for(int k=0;k<i;k++){
    if((n[k]!=0)&&(m[k]>n[k])) System.out.println(m[k]);
    else if((n[k]!=0)&&(m[k]<=n[k]))System.out.println(n[k]);
    else y=1;
    }
    }
    catch(IOException e){};
    }
    }

 


can anyone tell me what's

hpanwar35 @ 14 Apr 2011 10:25 PM

can anyone tell me what's wrong with my code... http://www.codechef.com/viewsolution/518854 It shows runtime error on the site but run perfectly on my pc.

Hello guys, Can Some One plz

km723 @ 23 Apr 2011 10:33 PM

Hello guys,

Can Some One plz tell me whats wrong with my code?

It is running fine on my PC,i am new here,so please help me out.

I would appreciate that a lot.

Here's th link to my code:-

http://www.codechef.com/viewsolution/530520

Please tell me why is it

kapilagarwal @ 29 May 2011 05:05 PM
Please tell me why is it showing time limit exceeded ? I have checked my program and it gives the correct answer for n=1000000000 also in milliseconds. The solution link is http://www.codechef.com/viewsolution/555190

my code gives the correct

adityasingh109 @ 30 Jun 2011 03:34 AM
my code gives the correct answer but exceeds time limit please help me solving the issue The solution link http://www.codechef.com/viewsolution/585708

@adityasingh109: Think of how

mukulgupta @ 30 Jun 2011 05:56 PM
@adityasingh109: Think of how many times the same function is being called for the same value. eg convert(2) is being called a lot of times for a value of n say 10000

import

raj23dev @ 1 Jul 2011 11:34 PM
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s =new Scanner(System.in); String x=s.nextLine(); if(x==null) System.exit(1); System.out.println(max(Long.parseLong(x))); } public static long max(long n) { long temp=(n/2)+(n/3)+(n/4); if(temp>n){ temp=(max(n/2)+max(n/3)+max(n/4)); return temp;} else return(n); } }

why isnt it

raj23dev @ 1 Jul 2011 11:34 PM
why isnt it working.......????????/

whats wrong with my

raj23dev @ 1 Jul 2011 11:45 PM
whats wrong with my solution http://www.codechef.com/viewsolution/587254

#include #include #include #d

zodiac_134 @ 22 Jul 2011 01:18 AM
#include #include #include #define max 10 void getMaxDollars(int num); int maxof(int a,int b) { return((a>b)? a:b); } int main() { long int num[max]; int i; printf("Enter numbers(max 10)n"); for(i=0;i

I got the same results as

bamdad74 @ 26 Jul 2011 11:30 AM
I got the same results as Kumar and it says wrong answer any suggestions INPUT: 123123 1000000000 120 1234512345 12121212 3422 83848586 999999999 OUTPUT: 248604 4243218150 144 5412617448 37595901 5052 294643700 4243218150

hey howz d ans for 1000000000

shubham9792 @ 5 Aug 2011 04:03 AM
hey howz d ans for 1000000000 is 4243218150 while we can get more as 4243218150/2+4243218150/3+4243218150/4>4243218150.....plz explain

sorry,......ignore tht

shubham9792 @ 5 Aug 2011 04:13 AM
sorry,......ignore tht

RUNTIME ERROR SOLUTION: Hi

chouhan @ 15 Aug 2011 01:27 AM
RUNTIME ERROR SOLUTION: Hi guys, As I was myself struggling to my mortal limits for curing the ailing cancer of Runtime Error. I must help the other 19 'Runtime' searches made using ctrl+f It could have been because of extensive memory usage for example: // Upto 10^6 #define MAX 1000001 The above MAX would work fine // Upto 10^8 #define MAX 100000001 This one would give Runtime Error Why are we doing this? If you need that answer, then probably you haven't cracked the answer yet. And there won't be any spoilers. Have fun Cracking the code All hail CC _/_

Woa!! Where are all my endl;

chouhan @ 15 Aug 2011 01:28 AM
Woa!! Where are all my endl; gone? n n n It just isnt readable anymore :/

@admin Howcome using

g4ur4v @ 17 Aug 2011 02:15 AM
@admin Howcome using recursion gives a TLE forthis question.. ca u plz explain?

If a coin can be divided only

click @ 24 Aug 2011 12:08 PM
If a coin can be divided only into 3 coins then how is the answer of 15 is 16???????

ANS hey howz d ans for

coderack @ 26 Aug 2011 12:36 PM
ANS hey howz d ans for 1000000000 is 4243218150 while we can get more as 4243218150/2+4243218150/3+4243218150/4>4243218150.....plz explain But you can not buy Bytelandian coins.

#include long max(long

peeyush18 @ 29 Aug 2011 08:45 PM
#include long max(long n,long m) { if(n>=m)return n; return m; } int main() { int n; while(scanf("%l",&n)) printf("%ln",max(n,((n>>1)+(n/3)+(n>>2)))); return 0; } this is my program any hint why this is wrong

i solv this question on my

goelrinku @ 9 Sep 2011 10:58 PM
i solv this question on my machine it shows correct ans but on submission it shw wrong ans pls any body helps me submission number=654931

Hello fellow

gcttirth @ 12 Sep 2011 11:46 PM
Hello fellow programmers! Would really like to get tips for improving myself. Solution : http://www.codechef.com/viewsolution/659685 Please provide any suggestions.

Can Anyone please tell, whats

tarunrathi89 @ 12 Oct 2011 07:25 PM
Can Anyone please tell, whats wrong in this code. It says time limit error. It works fine with me. #include #include long mid,trip,quad,total; long findmax(long num) { if(num<12) return num; total = findmax((num/2)) + findmax(num/3) + findmax(num/4); return (total>num)?total:num; } int main() { long a,n; while(scanf("%ld",&n)>0){ a=findmax(n); printf("%ldn",a); } return 0; }

Can Anyone please tell, whats

tarunrathi89 @ 12 Oct 2011 07:27 PM
Can Anyone please tell, whats wrong in this code. It says time limit error. It works fine with me. #include #include long mid,trip,quad,total; long findmax(long num) { long mid,trip,quad; if(num<12) return num; mid = num/2; trip = num/3; quad = num/4; total = findmax(mid) + findmax(trip) + findmax(quad); return (total>num)?total:num; } int main() { long a,n; for(int i=0;i<10;i++) { scanf("%ld",&n); a=findmax(n); printf("%ldn",a); } return 0; }

my program is giving right

imtechnomaniac @ 17 Oct 2011 01:32 AM
my program is giving right output but showing runtime error on submission ..... #include max(int *y,int *z) { int *d,i; d=&i; i=*z/2+*z/3+*z/4; if(*d>=*z) return(*d); else return(*z); } main() { unsigned int n,x; short int c=0; while(c<10) { printf(" input : "); scanf("%d",&n); if(n<=1000000000) { printf("output : %dnn",max(&x,&n)); c++; } else { printf("invalid no. enter againn"); } } }

I solved it using recursion

pankajb64 @ 18 Oct 2011 11:37 AM
I solved it using recursion but any idea how to do it iteratively (without using stacks and queues) ? It obviously gives a runtime error if we use dynamic programming with O(n) space complexity. Any idea how to do it in less than O(n) ?

Can anyone tell whats number

chandu_333 @ 28 Nov 2011 04:54 PM
Can anyone tell whats number 2 for in input

import

pratikjain123 @ 21 Dec 2011 09:32 PM
import java.util.Scanner; class coins { static int max(int a) { int x=a/2,y=a/3,z=a/4; if(x+y+z>=a) { x=max(x);y=max(y);z=max(z); return (x+y+z); } else return a; } public static void main(String args[]) { int a,b; Scanner sc=new Scanner(System.in); for(int x=0;x<10;x++) {a=sc.nextInt(); b=max(a); System.out.println(b); } } } Can somebody tell me what is the error with my program...

i checked a submitted

vivek17geek @ 8 Jan 2012 11:01 PM
i checked a submitted soln..and i m getting exact answer for all cases...still getting WA.

can someone make a tutorial

anthraxwar @ 22 Jan 2012 09:28 PM
can someone make a tutorial for this problem hence it is popular and rather small percentage of ppl has done it...

I think CodeChef's system

prosho @ 24 Jan 2012 07:41 AM
I think CodeChef's system test is worse than CodeForces's. It is because the submitters cannot see the test cases and if the submitted solution has Runtime Error, the system returns only very poor information for debugging. I hope sincerely the improvement of the system testing.

please help me to find my

bhupeshkumar99 @ 22 Feb 2012 05:55 PM
please help me to find my mistakes in this program.when i run it in codechef ,it says runtime error, but it is running well in my system #include #include int main() { int n,i,a,b; scanf("%d",&a); b=a/2+a/3+a/4; if(b>a) { printf("%d",b); printf("You can change %d into %d, %d and %d, and then change these into $%d+$%d+$%d = $%d. ",b,a/2,a/3,a/4,a/2,a/3,a/4,b); } else { printf("%d",a); printf(" If you try changing the coin %d into smaller coins, you will get %d, %d and %d, and later you can get no more than $%d out of them. It is better just to change the %d coin directly into $%d.",a,a/2,a/3,a/4,b,a,a); } }

I am also getting Time Limit

nickhalding @ 28 Feb 2012 01:16 AM
I am also getting Time Limit Exceeded error in my program, I am using C as my programming language, and using scanf to read inputs, in a while loop, till the scanf < 0. Please have a look at my solution at http://www.codechef.com/viewsolution/869818 and tell me what should i do! This is the first time i am programming in Code Chef! Please help,anyone who can!

#include void main() {

mayanapps @ 9 Mar 2012 11:30 AM
#include void main() { int a[10],s,i=0; for(;i<10;i++) scanf("n%d",&a[i]); for(i=0;i<10;i++) printf("n%d",((s=((int)a[i]/2+(int)a[i]/3+(int)a[i]/4))>a[i])? s : a[i]); } why there is run time error in codechef it is not in my pc

my code iz the mst compact

radical @ 9 Mar 2012 05:45 PM
my code iz the mst compact and runs in mch lesser than 1s for inputs of size less than 1 000 000 000 but still it shows runtime error.... @admin plz help..

if i have 24; the max value

nicokurniawan @ 31 Mar 2012 11:15 AM
if i have 24; the max value for american dollar i get should be 26 right ? 24/2 + 24/3 + 24/4 i just tried a number of successful solution, but always returns 27, can someone explain me ?

used dp+recursion :)

ka4tik @ 4 Apr 2012 02:28 AM
used dp+recursion :)

In my opinion the spec was a

dudeofx @ 4 May 2012 02:47 AM
In my opinion the spec was a little ambiguous in that it didn't specify that the program should exit after the 10th case. I was checking for EOF

I've written a code in C. I

shashanksingh @ 9 May 2012 10:04 AM
I've written a code in C. I terminate the input when the user enters -1, i.e, scanned number is an EOF (which is -1 in C) Im however getting a runtime error!! The code works perfectly t my place. Is something wrong in taking the input at the server side?

how to submit a solution,,,

shimil @ 22 May 2012 04:31 PM
how to submit a solution,,, where to enter the qstn code,,, pls reply soon

Why is this giving time

coditor @ 8 Jun 2012 11:59 AM
Why is this giving time exceed limit.. thank you #include int split(int n) { int a1,b1,c1; a1=n/2; b1=n/3; c1=n/4; if(a1==0 || b1==0 || c1==0 || (a1+b1+c1)

m not able to understand why

udbhav_naruto @ 16 Jun 2012 10:54 PM
m not able to understand why for the input 1000000000 the output should be 4243218150 . m a new programmer. may be i missed the tricky part plz help me out. and plz tell me how to check eof in c++ for keyboard input. m using function eof() for termination but its not working.

i got the tricky part but i m

udbhav_naruto @ 17 Jun 2012 12:10 AM
i got the tricky part but i m having problem regarding part . plz tell function for eof. m using cin.eof() but not working . m coding in c++ and how does clock function output in c++

after trying evrything i

paragsaraogi @ 7 Jul 2012 04:43 PM
after trying evrything i could with my code to avoid run time error,i tried submitting an already submitted code.....it gave runtime error as well....WTF

after trying evrything i

paragsaraogi @ 7 Jul 2012 04:43 PM
after trying evrything i could with my code to avoid run time error,i tried submitting an already submitted and accepted code.....it gave runtime error as well....WTF

I cant take in anything

idontmakesense @ 1 Aug 2012 01:15 PM
I cant take in anything greater than 10^5. how are you guys doing it? Data type im using is unsigned long long in c++.
1 of 2
next ›

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

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 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.