Bytelandian gold coinsProblem code: COINS |
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 |
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.
till when to take the input..??
till 10 test cases..?? then how come only two inputs are here??
it says that no of inputs can be 10 at max
What will be the terminating condition for input?
Input will terminate on end of file
do like input a no. and output it immediatly and this could happen till max of 10 times
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
@ codechefs program with warning are allowed or not
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?
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)
@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.
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
@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.
Do we need to ask for the no. of test cases here?
i dont understand the code is absolutely working fine in visual studio!!!!!!!!!!!But still i am getting runtime error!!!!!!!!!!!!Any Comments Pls
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?
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.
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
hfksdhksdfn,sdnf
Its not jus acceptin #include<conio.h>
n #include<iostream.h>
wtf???
@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.
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?
@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.
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?
aghrr.. formatting broke (
forget it
are you reading till EOF? It can happen that your program stalls after processing all the testcases and that might be giving a TLE.
yep, I'am. It exits successfully after processing all the input.
@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.
let's see... the version without any processing (that just echoes the input) worked for 3ms and *termanated*.
@evgenly Try it on the online judge and see if it terminates here as well.
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..
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.
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.
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?
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..
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 :(
Please read http://www.codechef.com/help/ for information on how to submit a solution in Java
did any get it right ?????
In the first line should we write number of test cases then proceed with taking inputs?
You just need to write the output. you don't have to write the number of test cases to stdout.
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.
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.
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.
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.
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 .
Did you notice that 4243218150 is greater than 2^31?
Okay i guess I dont
It doesn't say you can only
Okay thanks that makes alot
Nevermind I was using
i wrote a very simple
what is a test
I feel a recursive solution
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
@Dhiraj its just the input
@Nishant You are
@Nishant You are misinterpreting the problem statement. Re-read it.
hey,,please explain it
someone there to help me out
You are missing the fact that
You are missing the fact that you can further exchange the obtained coins for more coins.
How may i check the run time
How may i check the run time on my dev c++ compiler??
Have a look at the function
Have a look at the function named clock()
INPUT: 123123 1000000000 120
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
Can i know the reason for a python runtime error?? the code works fine on my computer
This is infuriating. No clue
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
Premature optimization killed me... *sigh*
I was trying but I could not
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
can we not use while(scanf("%d",&a)){ } as terminating condition after the end of inputs.
@Rakshith Check what scanf()
i guess scanf returns the no
thnx aniruddha.. i got the
yo rakshith check this for
the dollars increase by the
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
i am get right answer on turbo c
but on this site they said it is wrong why???
i am getting 1083333333 on
i am getting 1083333333 on input 1000000000
but it said my program s wrong
That's because it is wrong.
That's because it is wrong. And so is that value.
are the cases taken by
are the cases taken by yash0101 are correct ????
someone please tell me....
what is run time error
what is run time error
It means that your program
It means that your program gave an error while it was executing. It did not end gracefully.
A run time error here on
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
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
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
@Anirudhha Thanks for the
@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
You need to print the output to stdout as specified in the output specifications.
Is this possible to do
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
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
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
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
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
memoization worked very well for this problem.time 0.01s. Want to know if still there are better solutions.
After numerous tries , I
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
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
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
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
Try to cache repeatedly encountered values.
@Aniruddha - Thanks vey much
@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
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
Don't you think you will use too much memory?
No, it won't use too much
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
@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/
http://en.wikipedia.org/wiki/Newline
got accepted....thanks
got accepted....thanks
#include<stdio.h> int
#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
#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
i cant type nn
ps. \n\n means ..new line
ps. nn means ..new line
Read the other comments.
Read the other comments.
for(; scanf("%lld",&x) !=
for(; scanf("%lld",&x) != EOF; printf("%lld n",coin(x)));
will it work... i mean will
will it work... i mean will it terminate at eof?
#include<stdio.h> int
#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
Your problem has already been addressed several times in the comments. Coins can be exchanged multiple times.
i know the coins can be
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
Because you are probably not testing it as extensively as the judge program.
I am using recursive and
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
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
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
And 1 minute 10 seconds is longer than the 9 second time limit.
import javax.swing.*;class
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
You are to read from the standard input stream. Not from a JOptionPane.
thankx stephen but may i know
thankx stephen but may i know d reason why we should not use JOptionpane
thnx
hai stephen even when i use
hai stephen even when i use i/o streams its showing RUN TIME ERROR
You can't use a JOptionPane
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
@stephen
can u tell me which header file used in c language for eof()
/sources/Main.java:7: class
/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.
Read the FAQ.
Dont they accept programs in
Dont they accept programs in BlueJ ??...mine got rejected..says compiler error
What will be the terminating
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
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
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
will u please tell me how to write a program for bytelandian coins ?
Dont forget that you can
Dont forget that you can change again the coins after the first change ! (and again and again....)
this is the best one dynamic
this is the best one dynamic programming example...
this is the best one dynamic
this is the best one dynamic programming example...
thanx codechef...
my code is giving negative
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
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
@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
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
Test your code on cases which could be harder than others.
@ admins how much memory
@ 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
Read the FAQ. You have some very basic errors in your code.
hints :- 1)memoization is
hints :-
1)memoization is good but memory is scrase
2)Simplicity is essence of life(input)
Even 1000000000 is showing
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
@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
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
@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
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
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
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
for a cases like 144 the series is non-converging i feel...you can run a test.
import java.io.*; public
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
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
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
@Rajat
You haven't tried the worst case,it gives wrong answer for n=1000000000.
@Piyush I have tried for the
@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:
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
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
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
what will be the worst case result? is it not 1083333333 ?? then what is it?
The answer is a lot more than
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
@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
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
FAQ
Hi, I tried with the
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
@Mohammad Ahsan:-/coin.exe <input.txt >out.txt
Hi admin, Can you please
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
which data tupe to use to store 10^9???
@deepak long int
@deepak
long int
#include <iostream>#include
Why WA with my
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
@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
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
i still could not get. can you please elaborate.
thnx Stephen, i got your
thnx Stephen, i got your point :)
what is the terminating
what is the terminating condition for this problem?
When they say that there are
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
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..
hey ADMIN pls help..
my run id is 331160. the code
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
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
@admin my code is running
@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
// 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++;
}
}
}
#include<stdio.h> int
#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;
}
}
Dear
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
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
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
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
yap.my code was wrong as i thought we can exchange the gold coin only ones with bank......
here are my test results i
oops sorry for that.....think
" tag
here are my test case
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
RUNTIME ERROR message
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
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
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
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
#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
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
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
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
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
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
the variable i is useless in above code, plz dont pay attention to that :)
It should be pretty easy to
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
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
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
#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
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
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
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
@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
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
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
Your array uses about 238mb of memory - that's far more than you're allowed.
//sumitdugar #include<iostrea
//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);
}
}
//sumitdugar #include<iostrea
//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);
}
}
//sumitdugar #include<iostrea
//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);
}
}
//sumitdugar #include<iostrea
//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);
}
}
Can some1 tell me y dis is a
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
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
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
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
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
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
//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
#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
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
You can exchange coins multiple times.
i wish to ask that if i put
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
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
@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 {
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
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
Can i know the reason for a python runtime error?? the code works fine on my computer
I'm not sure how you are
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
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
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
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
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
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
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
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
@Amir...thanks a lot buddy ..i just forgot to write return type ..
please chck ot this and tell
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
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
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
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
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
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.
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.
can you tell me the prob with
if possible upload a tutorial
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
@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
can any one tell me whts wrong with d code
@Soumendu : u either can
@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
@Turja Narayan Chaudhuri
The comments already have lot of hints: recursion+memoization.
can any tell whats wrong in
can any tell whats wrong in this code.
public class Main{public static void main(String[] args) {try{while(br.readLine()!=null){for(int k=0;k<i;k++){catch(IOException e){};can anyone tell me what's
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
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
my code gives the correct
@adityasingh109: Think of how
import
why isnt it
whats wrong with my
#include #include #include #d
I got the same results as
hey howz d ans for 1000000000
sorry,......ignore tht
RUNTIME ERROR SOLUTION: Hi
Woa!! Where are all my endl;
@admin Howcome using
If a coin can be divided only
ANS hey howz d ans for
#include long max(long
i solv this question on my
Hello fellow
Can Anyone please tell, whats
Can Anyone please tell, whats
my program is giving right
I solved it using recursion
Can anyone tell whats number
import
i checked a submitted
can someone make a tutorial
I think CodeChef's system
please help me to find my
I am also getting Time Limit
#include void main() {
my code iz the mst compact
if i have 24; the max value
used dp+recursion :)
In my opinion the spec was a
I've written a code in C. I
how to submit a solution,,,
Why is this giving time
m not able to understand why
i got the tricky part but i m
after trying evrything i
after trying evrything i
I cant take in anything