VECTAR4 - Changus Final Battle
Try the tutorial version first : Changus Big Battle : http://www.spoj.com/problems/VECTAR2/
Changu is going to fight a battle. He is powerful but he has a few limitations. If he kills x enemies on a particular day, then he can only kill x-1 or x or x+1 enemies on the next day. And also, he can kill no more than 1 enemy on the last day of battle. Given N, the number of enemies he has to kill to end the battle, you have to calculate the minimum number of days required for Changu to finish the battle, keeping in mind his limitations. He starts on day 1 by x=1, i.e. killing one enemy.
The first line contains an integer T denoting the number of test cases.
Each of the next T lines contain an integer N.
T lines : Minimum number of days required for each test case.
1 <= T <= 10^5
1 <= N <= 10^18
Input: 3 4 1 9 Output: 3 1 5
Case 1 : 1 + 2 + 1
Case 2 : 1
Case 3 : 1 + 2 + 3 + 2 + 1
Note: Test files have been updated. Solutions will be rejudged.
in vectar2 1st I got TLE but thinking deeply got AC in both question same code !!! Nice one O(1),yes:)
Last edit: 2017-01-14 17:33:31
Are the testcases weak ? I mean VECTAR2 is the tutorial problem with the same question but smaller constraints and my solution for VECTAR2 runs faster than that for VECTAR4, which is essentially the same code except for replacing int by long long . Anyways nice question. Made me think for a while. O(1) it is :)Last edit: 2016-10-07 22:22:10
Weak test cases. Worst case inputs are not in input file. My initial very bad code passed too!
@Piyush Kumar please remove spoiler comments.
<spoiler removed>Last edit: 2016-07-28 15:01:16
@tarungupta1956: me too :P +1/-1 in wrong order :P and I was looking for mistake for 15 minutes :P
took me 10 wa to realize a stupid mistake\: