Need help in the optimization

Pages: 12
Oct 6, 2018 at 6:56am
How fast does your code run ?
How fast should it be ?
Oct 6, 2018 at 12:23pm
Put this at top of main, it will speed up input quite a bit.
1
2
  std::cin.sync_with_stdio(false); 
  std::cin.tie(nullptr);
Oct 6, 2018 at 1:29pm
I doubt very much that the above will be sufficient.

Start by writing a program that is not using non-legal constructs, such as:

1
2
    cin>>n>>m;
    ll a[n],b[n],c[n];

The above is not legal in C++, array sizes must be compile time constants. By the way are you sure using arrays is necessary?

Second use meaningful variable names, it'll make your program much easier to read and maybe even make it possible to follow the program logic.

Third stop using silly type defs like: typedef long long int ll;, just say what you need.

Fourth since this is C++ define and initialize your variables close to first use instead of one big glob at the beginning on some scope.

What is the maximum value of m and n?

Are you sure you're not overflowing the size of your long long int in any of your calculations?

Oct 8, 2018 at 2:03pm
@burada
If you're brand new to programming, and don't understand the question, then why on earth are you trying to tackle competitive programming challenges?
Last edited on Oct 8, 2018 at 2:03pm
Oct 8, 2018 at 3:11pm
if you are optimizing ...

n=int(raw_input) -1
n=n-1 //rolled into above.
y=n%26
z=n//26
if(y<2): //better comparison
print(2**z, 0, 0)
elif(y<10): //y already checked against 2 in the previous if, and comparisons cost
print(0, 2**z, 0) //do you need a lookup table of powers of 2 for these?
else:
print(0, 0, 2**z)

Last edited on Oct 8, 2018 at 3:12pm
Oct 9, 2018 at 1:49pm
how can we apply binary search to find the maximum range in hmappy, can somebody please help ?
Oct 9, 2018 at 2:03pm
I got 100 in digit sum and circles question.
I could give hints for both questions in return to hints for HMAPPY
Oct 9, 2018 at 2:16pm
What are these competitive programming challenges anyway?

Are you supposed to show the extent of your knowledge in there? If you demonstrate that you know nothing, that is also a success (in showing what you actually know).


Lets say that I would participate. To win, of course. It would then be in my interest to sabotage every rival by offering "help", wouldn't it?
Oct 9, 2018 at 3:42pm
to jab1jaby, iamdad6, shinok1, maxdaen, Dum:
create your own damn thread and provide all the info there (like, for example, the problem statement)


@op: read the limits of your problem
1≤N≤10^5
0≤M≤10^18
you decided to traverse M doing N operations each time, so 1e23 in total, that's too much
you need to change your approach to have 10e6 at most, so perhaps O(n lg n)
Oct 10, 2018 at 1:44pm
@ne555, im referring to the same problem posted by @beauty01.
Oct 10, 2018 at 2:39pm
¿how the hell I'm supposed to guess that its name?

for binary search
say that the answer is x, now simply verify if you can reach x
so traverse the array giving balloons to make sure that the cost does not exceed x in all the days. If you don't run out of ballons then it was possible and you may decrease `x', else you need to increase it

1
2
3
4
5
6
7
8
low = 0
high = M
while low < high:
   answer = floor( (low+high)/2 )
   if posible(demand, cost, balloons, answer):
      low = answer
   else:
      high = answer



the order then would be O(N lg M) which is quite good
Last edited on Oct 10, 2018 at 2:51pm
Oct 10, 2018 at 3:20pm
@ne555 , what should i take 'x' as initially?
and ty for the reply.
Oct 10, 2018 at 10:09pm
> what should i take 'x' as initially?
suppose that you give no balloons at all, that would be the maximum possible cost, the upper limit.
may start at limit/2

by the way, the pseudocode fails in corner cases, fix that first.
Oct 11, 2018 at 6:53pm
@new accounts: please be a little more specific with what you don't understand, I don't want to repeat myself.

edit: also, don't pm me, use this thread.
Last edited on Oct 11, 2018 at 7:05pm
Oct 12, 2018 at 10:53am
..
Last edited on Oct 12, 2018 at 12:40pm
Oct 12, 2018 at 11:21am
If this is a Codechef problem, you should know that the Codechef adjudicators are aware of this forum, and that people use it to cheat on their contests. If you use this forum to try and cheat, you run the risk of being disqualified.
Oct 12, 2018 at 11:29am
@MikeyBoy,
yes it's an ongoing challenge. https://www.codechef.com/OCT18B/problems/HMAPPY
Actually quite a hard one - success rate so far 5.45
Oct 12, 2018 at 11:36am
Well, the more people who use this forum to cheat, the more disqualifications there will be, and the lower that success rate will be...
Oct 12, 2018 at 11:38am
I prefer Rhett Butler's solution.
Pages: 12