Hi all,
I was trying to solve one of the google code jam problems. I encountered with an error and need some help.The following code that i wrote for a particular problem is not working at all.The code compiles but shows a runtime error something like : "throwing an instance of std::bad_alloc()" . Can anyone help me out please? here is the code.
@Ispil I am using windows.And the code is compiling fine.but not running.
Its showing a run time error.Is compiling on shell somewhat different from compiling on windows?I really don't know anything about it...
No, you're right, the problem here shouldn't have to do with compilation. The text inside your ms.in and ms.out files may be the source of the problems.
I would check to make sure they open properly first off, and use a debugger to see where exactly it's throwing the exception.
@Ganado thank you very much.you can check the the ms.in and ms.out in google code jam's website.The question is named as minimum scalar product. The names of files are different although.It is named A-small-practice.in
@MiiNiPaa I am posting my ms.in file below.please check.
Did yoiu really mean to read from .out file and write to .in file?
Some other hints:
You have 10 zeroes in each vector which is not what you want.
int is too small to hold all possible values.
You are outputting extra information in your file.
@MiiNiPaa Thank you for pointing out the error.The .out file and .in file were in wrong position.so i changed it.i have commented out the extra information.but i am getting right answer for first iteration and a wrong answer for the next one.
Can you help in correcting it? Here is the code now.
thank you.My code passed the small input.But it is not passing the large input test.I am also using long long in my vector.Can you tell me what changes i have to do to my code? I am using c++ 11