tourist's blog

By tourist, history, 7 years ago, translation, In English

Here is the tutorial of Hello 2018. Enjoy!

Modular Exponentiation
Christmas Spruce
Party Lemonade
Too Easy Problems
Logical Expression
Strongly Connected Tournament
Power Substring
Don't Exceed
Tutorial of Hello 2018
  • Vote: I like it
  • +463
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
  Vote: I like it +7 Vote: I do not like it

Not a single tutorial is available ? Only solutions ?

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +152 Vote: I do not like it

    Sorry, the tutorials will be available shortly after the end of system testing.

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +42 Vote: I do not like it

      Don't be sorry man. Forgive us for being stupid and not understanding you problems, sorry.

»
7 years ago, # |
  Vote: I like it +1 Vote: I do not like it

I'm liking this new trend.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

why this solution worked? cin>>n>>m; int a=pow(2,n); cout<<m%a<<endl; what about overflow?!

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    a will be -2147483648, but in the way C++ works with negative modulo it will work...

    • »
      »
      »
      7 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      a could be any value, couldn't it? Depending on n. It's unlikely to be <= 10^8, but possible or not?

      • »
        »
        »
        »
        7 years ago, # ^ |
        Rev. 3   Vote: I like it 0 Vote: I do not like it

        It varies depending on the PC architecture (32 or 64 bits), compiler and operating system, in my PC and in Codeforces custom invocation it has that value. For every n >= 31 it has the same value.

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Even though it overflows the % operation is unsigned so the number remains big enough to work properly.

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it -10 Vote: I do not like it

    in c++ when a large double number ( larger than the receiver type ) is put into smaller receiver it automatically casts it to the largest possible number to be put in the receiver in this case INT_MAX so when a number is calculated % INT_MAX it will always give the number

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Can you give a source for this information?

      • »
        »
        »
        »
        7 years ago, # ^ |
          Vote: I like it -7 Vote: I do not like it

        you can try it write down cout << (int)1e12 and write down cout << INT_MAX see the results of the two operations .

        • »
          »
          »
          »
          »
          7 years ago, # ^ |
            Vote: I like it +5 Vote: I do not like it

          That is no proof, could be undefined behavior

»
7 years ago, # |
  Vote: I like it +3 Vote: I do not like it

I think on F, that ans[0] = ans[1] = 0..

Thanks for the contest, it was fun!

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    Thank you, tutorial was updated, changes will come into force soon.

»
7 years ago, # |
Rev. 2   Vote: I like it -16 Vote: I do not like it

I used a greedy solution for question C .First I found out the bottle which has least value of cost per litre .Then I used a formula to give maximum possible number of bottles of this category(i.e. L/(volume of bottle of the category). Then i brute forced my solution ( i bought the best possible bottle at the moment by using a formula and then subtracted the volume from L, then repeat and repeat till L becomes <= 0 ). However, my solution failed on test case 14 of system testing. Here is my solution link My solution Any help would be appreciated. Thanks :)

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +12 Vote: I do not like it

    It fails for the case:

    Spoiler 1
    Spoiler 2
    Spoiler 3
  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I used quite similar greedy approach for problem C with one little modification and I got AC. Maybe someone will find it interesting. Firstly, let's sort the bottles by the cost per litre. Let's start from the cheapest of them going to the most expensive. Lets denote the size of the bottle i as V[i]. We have two different cases:

    • V[i] <= L. Here we have the best price because we going down from the cheapest bottle and we will buy all the V[i] litres. Then we can add to the answer this price and multiply that by the number of times. Of course we should subtract this V[i] multiplied by the number of times from the L. Then we can buy one more bottle with this size and it will be more litres than we need, but maybe it has the cheapest price and it will be the best variant? Otherwise, we can continue going down to the more expensive bottles per litre, but we will not buy the extra litres as it was before. We need just to update our realAns as you can see it in the code below:
    if(a[i].V <= L) {
        ll times = (L / a[i].V);
        ans += times * a[i].cost;
        L -= a[i].V * times;
        realAns = min(realAns, ans + a[i].cost);
    }
    
    • V[i] > L. We can buy this bottle and it will be our ans. Here we go:
    realAns = min(realAns, ans + a[i].cost);
    

    This solution seems nice to me. Here the it is 34026125 . Feel free to ask questions if something is not clear for you.

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Nice solution! Can you explain how you got the intuition to sort by cost per unit volume?

      • »
        »
        »
        »
        7 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Sure. I just thought about the greedy solution and then it was obviously, because the main idea in greedy is to buy the cheapest bottle.

»
7 years ago, # |
  Vote: I like it -15 Vote: I do not like it

Great set of problems.I liked the 3rd one most.Credits goes to @tourist, my man. Thumbs up for all the problem setters too.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there different kind of solution for problem C?

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Here, 34034532 .

    Same logic but a bit different implementation. :)

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The solution I wrote only passes through the bits of L once, going from least-significant to most-significant. 34027236

    If, at any time, buying bottle i would be better than the entirety of the sum we've already calculated, then replace the sum with the cost for bottle i.

»
7 years ago, # |
  Vote: I like it +8 Vote: I do not like it

E problem uses the same concept as F Problem of this contest.

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    I think E is suitable for smart or patient person. I quit immediately after reading it.

»
7 years ago, # |
  Vote: I like it +18 Vote: I do not like it

Misread problem D. How to solve the problem optimally when k >= a pj instead of k ≤ apj in problem D?

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it +6 Vote: I do not like it

    I think that the beauty of problem D comes when you think of it geometrically. Imagine that you have a point in the plane with coordinates .

    Then, for a fixed k, they are asking you a question about the points in a semiplane that lies to the right of the vertical line x = k, including the line (this is in the original statement with k ≥ apj, it lies to the left of that line if we choose k ≤ apj).

    With this in mind, I think that both problems look more like a "Sweep Line" kind of task, doesn't it? (this is how I approached problem D during the contest, and why I believe that solution 2 in the editorial is more natural, although this last part is clearly subjective)

    • »
      »
      »
      7 years ago, # ^ |
      Rev. 4   Vote: I like it +3 Vote: I do not like it

      "it lies to the left of that line if we choose ....", not exactly. When we count problems in score such that k >=  apj, we can choose problems on either side of the line. The points for which k >=  apj are added to the score, however, we can choose points on other side of the line which don't satisfy this condition which will increase value of k (not increasing the score though), however this also moves the line and we can add new points with lesser ti such that k >=  apz increases and we can replace few points.

      Basically, when k >=  apk, the final points/score will not always be equal to the number of problems we choose.

      • »
        »
        »
        »
        7 years ago, # ^ |
        Rev. 2   Vote: I like it +5 Vote: I do not like it

        I misread it too and used the following idea. Let's sort our arrays in non-descending order of ai. Run a binary search on the value of x result points, and then say that the total amount of solved problems should be at least ai. Then for any j <  = i j-th element can give us a point if we will take it and we will suppose now that all the elements right to the i-th will not give us a point(if they actually will we'll consider it later). So we should take x elements from the i - th prefix with minimum total time, and then we should take ai - x elements from all the array with minimum total time(except the taken ones). It also can be noticed(but it is not neccesary) that this check procedure for a given x is to find out whether there exists such i that the sum of minimum x elements from the i-th prefix plus sum of minimum ai - x elements from the i + 1-th suffix is no more than T. It can be implemented with two segment trees(for prefix and suffix elements) (where trees are build on the array sorted by the time now and making a transition from i to i + 1 we do some changes, and find the sum of some first values).

»
7 years ago, # |
  Vote: I like it +57 Vote: I do not like it

My rating is now fibonacci sequence (2358) :)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    that rating was 2 years ago, what about now??

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone find out why this code for D.Too Easy Problems (based on binary search) get runtime error? http://mirror.codeforces.com/contest/913/submission/34026112 Thanks in advance.

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Thank You [user:tourist]for nice and pretty problem. Now I am a Blue Coder :'(. I am Very Happy For That. :)

»
7 years ago, # |
  Vote: I like it +20 Vote: I do not like it

Its my first time seeing an Integral being applied in competitive programming (in problem H)! :3

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    There is this very interesting problem that uses integrals (now that I read H from this contest, the problems are somewhat similar).

    EDIT: ok, maybe not that similar since in the problem I pointed out you could calculate the integral with general algorithms such as Riemann integration or Simpson's rule, whereas here you have to mathematically compute the integral since you need an exact answer.

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    http://main.edu.pl/en/archive/oi/11/zga

    This one has integrals and it's also about gambling (a nice bonus of the problem!).

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it
  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you explain your approach? Thanks!

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +14 Vote: I do not like it

      Maintain a vector for the lemonade types and sort it according to the cost per liter(c[i]/(2^(i-1)). This sorts the lemonades according to the most optimal types of lemonade (cheapest lemonade) by normalizing the quantity to 1 liter. Thus we can greedily say that, if we buy lemonades in this sorted order, we can obtain maximum liters of lemonade from a given amount of money.

      Therefore, now we can use binary search to fix the amount of money we have, and then see if it is possible to obtain atleast L liters of lemonade by traversing in this sorted order and taking as many no. of lemonades of each type as possible.

      Hence, amount of money used can be easily minimized.

      • »
        »
        »
        »
        7 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        3 7 5 11 18

        what about this case? are you sure your code passes this case? UPD: Got it. I was wrong.

        • »
          »
          »
          »
          »
          7 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          ok. I checked this case against LGM's code. Your code gives similar to them. But how its 33? shouldn't it be 34?

          • »
            »
            »
            »
            »
            »
            7 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Buy 3 one liter bottles, cost=3*5=15 Buy 1 four liter bottle, cost=18

            Net cost=15+18=33 to buy 7 liters of lemonade

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Nice approach, I had the same idea but was not sure how to use binary search.

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

In problem C purpose of doing the following is? L -= need << i;

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    you are taking "need" number of bottles of 2^i size. "need << i" is basically "need * (2^i)"

»
7 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Can anyone tell why my code for C is failing for last sample input. The logic is similar to editorial. Link to my solution : My Solution

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    See for example the following test case:

    5 7

    1 2 3 4 9

    The correct output is 4 (take one bottle of 8 liters) but your answer gives 6.

    Hope this helps you!

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

for problem G,the tutorial says "In this problem n ≤ 11. m = 6 is enough for such n",why 6 is enough?

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    m = 6 is enough because if n ≤ 11 then 10m ≥ 2·2n + m.

    Let x = a·10m. If x is not divisible by 2n + m, we add to x. After that if x is divisible by 5 we add 2n + m to x.

    After such transformations x is divisible by 2n + m, x is not divisible by 5 and x ≤ a·10m + 2n + m - 1 + 2n + m. We know that 10m ≥ 2·2n + m. Therefore b = x - a·10m < 10m. That's exactly what we want.

    • »
      »
      »
      7 years ago, # ^ |
      Rev. 4   Vote: I like it 0 Vote: I do not like it

      thank you! I didn't understand clearly why "10^m ≥ 2·2^(n + m)" <=> "there exists k satisfying equation (1) and (2)" earlier, and after read your tutorial more carefully, I got that "Consider equation . Every number in the equation is divisible by 2^(n + m), lets divide all the numbers by this. The result is — equation (3) where . Use the following lemma: Lemma For every positive integer t number 2 is primitive root modulo 5^t." shows why "10^m ≥ 2·2^(n + m)"<=>"there exists k satisfying equation (1) and (2)", and we just need to find any k under these assumes. In this way the range of an available m can be determined, very nice problem!

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      when 10^m>=2^(n+m+1), then b can choose from [0,10^m-1], since 2^(n+m)-1<2^(n+m+1)-1<=10^m-1, so the values of b can cover [0,2^(n+m)-1], thus there exists some b satisfying ai*10^m+b=0(mod 2^(n+m)) and let x=ai*10^m+b, so x/2^(n+m)=2^(k-n-m)(mod 5^(n+m)), since 2 is a primitive root of 5^(n+m), so there exists t in range[0,4*5^(n+m-1)) satisfying 2^t=x/2^(n+m)(mod 5^(n+m)), then let k=n+m+t>=n+m, this k is the answer to the problem

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    a way to prove 2 is primitive root of 5^k (k>=1) using induction: assuming (I) 2 is primitive root of 5^k, and (II) 2^phi(5^k)≠1(mod 5^(k+1)) first, about (II) 2^phi(5^(k+1))-1=2^5phi(5^k)-1= (2^phi(5^k)-1)*(2^4phi(5^k)+2^3phi(5^k)+2^2phi(5^k)+2^phi(5^k)+1) since 2^phi(5^k)=1(mod5^k) (using euler's theorem) and 2^phi(5^k)≠1(mod5^(k+1)) (by assuming),therefore gcd(5^(k+2),2^phi(5^k)-1)=5^k if 5^(k+2)|2^phi(5^(k+1))-1 then there must be 5^2|2^4phi(5^k)+2^3phi(5^k)+2^2phi(5^k)+2^phi(5^k)+1 but 2^phi(5^2)=1(mod 25), thus 2^(sphi(5^k))=(2^phi(5^2))^(s*5^(k-2))=1(mod 25) so 2^4phi(5^k)+2^3phi(5^k)+2^2phi(5^k)+2^phi(5^k)+1=5(mod25) so 2^phi(5^(k+1))≠1(mod 5^(k+2))

    then about (I) for t in range [0,phi(5^(k+1))), 2^t=1(mod5^(k+1))=>2^t=1(mod5^k)=>phi(5^k)|t let t=phi(5^k)*s, since 0<=t=phi(5^k)*s<phi(5^(k+1)) so 0<=s<5, consider 2^t-1=(2^phi(5^k)-1)(2^(s-1)phi(5^k)+2^(s-2)phi(5^k)+....+1) so 5^(k+1)|2^t-1 <=> 5|2^(s-1)phi(5^k)+2^(s-2)phi(5^k)+....+1 since 2^phi(5^k)=(2^4)^(5^(k-1))=1(mod5) so 2^sphi(5^k)=(2^phi(5^k))^s=1(mod5) so 2^(s-1)phi(5^k)+2^(s-2)phi(5^k)+....+1=s(mod5) thus 5|s and 0<=s<5 => s=0 thus for t in range [0,phi(5^(k+1))),2^t=1(mod5^(k+1))=>t=0, implying that 2 is primitive root of 5^(k+1)

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I made two mistakes in Problem C during the contest. 34026884 First doesn't deal with a empty tail at last. Second fail to score the status and made a lot of unnecessary calculation which made TLE. My solution is too complex in all. Any suggestion in shorten the code?34038638

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

For problem C fourth example, why i get 44981600797903355?

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    I was getting that too. You must have some index of array which is getting negative.

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      No, my solution is wrong.. Thanks for commented

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Somebody please explain for Problem E,How the number of functions are 256 and number of states are 3256?

»
7 years ago, # |
  Vote: I like it +1 Vote: I do not like it

i use dfs to solve the problem C 34018956

»
7 years ago, # |
  Vote: I like it +6 Vote: I do not like it

for problem 913D- Too Easy Problems

"The first observation is that if we solve a problem which doesn't bring us any points, we could as well ignore it and that won't make our result worse. Therefore, there exists an answer in which all problems bring us points. Let's consider only such answers from now on."

I don't think this is true,

Test Case

4 4
4 1
4 1
3 2
1 100

We solve 1,2,3 to make 1 points, Problems 1,2 don't bring us points but help increase the number of problems solved thus helping us solve problem 3 to earn 1 point.

Please let me know if I am stupid and have got it all wrong

  • »
    »
    7 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    What he meant is, there exists an answer where all problems ATTEMPTED brings us points.

    So, in your example, we could have just attempted the 3rd problem and it would have brought us 1 point (and 1 answer attempted only)

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      i get it, my bad. thanks for pointing out

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    please ignore the previous comment

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

In Problem D what if the score was only added when you have solved a[i] problems . Can anybody suggest a solution for that ?

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

can we solve E using Karnaugh maps??

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

In problem F, Strongly Connected Tournaments, can someone tell me how the law of total probability applies in each of the cases?

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why my solution failed on the 18th test case. On my machine, it's giving the right output. Why so?

34011797

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I'm guessing it's floating-point precision errors. Probably the calculation of log_2(m) is not exact when you do log_10(m)/log_10(2) as floating-point numbers, so the comparison against n may be wrong.

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      But in this test case log_2(m) is giving 25 . Hence if the condition would fail in this case and the output would be m%pow(2,n) would give 0 . Where is the mistake here ?

      25 33554432

      • »
        »
        »
        »
        7 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        yes, but you're storing all of these as floating-point numbers. Thus, the actual representation may not be exact, and doing equality comparisons or comparisons when the values should be equal to each other may be wrong. This might be why it failed on that test case.

        It may also be some weird C++ memory thing. I also discovered that if you change both variables to float (instead of one double and one float), then it passes all testcases. See the modified submission: 34077845

        • »
          »
          »
          »
          »
          7 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Alright,thanx that's ohkay . But what if I typecast log_2(m) to long long and then compare m and log_2(m)

          In that case also its not working . why so ?

          • »
            »
            »
            »
            »
            »
            7 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            probably because long long is an integer type. log_2(m) might not be an integer.

»
7 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Has anyone solved E using Sum of Products(SOP) form, then minimizing the terms using K maps or algebraic minimization and then finally combining terms to get lexicographically smallest function ?

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    I thought that it's the solution and pass the problem ASAP. However I think it can really work with some effort.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

i didn't understand problem E. can anyone please explain me that problem a little bit.

»
7 years ago, # |
  Vote: I like it +3 Vote: I do not like it

can someone explain me please what does he consider by states in the editorial of E and what does nonterminals from the right part of the rule mean ? Help would be appreciated !

»
7 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

I have a question about the problem F.

When we compute cp(s, i), if we think that we add a new player with the largest index, then the following equation holds: cp(s, i) = cp(s - 1, i) × (1 - p)i + cp(s - 1, i - 1) × ps - i.

But I thought that I add a new player with the smallest index. The equation below is what I made.

cp(s, i) = cp(s - 1, i) × pi + cp(s - 1, i - 1) × (1 - p)s - i

I cannot find why I was wrong... I've spent almost two days in order to solve this problem...

Could you tell me what I am doing wrong?

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it

    I explain about my equation.

    I'm going to add a new player whose index is the smallest. There have already been s - 1 players. After adding a new player, the number of players should be s.

    The first term, cp(s - 1, i) × pi, describe the case when a new player is not in the set of i players who lose to the others. The 'new added player' must win all the i players who are in the set. Thus, the probability is pi.

    The second term, cp(s - 1, i - 1) × (1 - p)s - i, describes the case when a new player is in the set. The 'new added player' must lose to all the s - i players who are not in the set. Thus, the probability is (1 - p)s - i.

    Would you tell me what is wrong?? Why should I add a largest-index-player like the official solution?

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      This way of computation of cp(s, i) is correct too. Maybe you have a mistake in other part of solution.

      • »
        »
        »
        »
        7 years ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        Thank you very much! I really appreciate your help.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I have a binary search solution for C, I did binary search on cost available and checked if maximum volume that can be bought is greater than volume required and in this way calculated minimum price. I passed the pretests but got wrong on 14 test case, it was due to overflow. After correcting overflow I got it accepted. Here is my submission.

»
7 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

In Solution of 913C ,in the following line

// ans = min(ans, sum + (L > 0) * c[i]); //

what is significance of (L>0) ????

  • »
    »
    7 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Remember that after you alter the domain as a[i] = min(2*a[i-1], a[i]), it makes sense to buy ith bottle as opposed to two i-1 bottles. So if L > 0, it means there is volume left, and it makes no sense to retain the bottles you picked previously, so get that extra ith bottle. As explained in editorial, if you set left most bit to 1, all the right side bits can be set to zero as the answer will still be maximum.

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      No , I'm talking about code of solution.

      • »
        »
        »
        »
        7 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        L = 0, (L > 0) equals to 0 (false)

        L = 1, (L > 0) equals to 1 (true)

»
7 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Can someone explain E clearly? I fail to understand what a state represents!

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

"It can be shown that the answer can be represented as , where P and Q are coprime integers. Print the value of P·Q - 1 modulo 998244353."

P·Q - 1 == , so it is a fractional number, isn't it?

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hey can someone tell me where I am wrong...this code is giving wrong answer on 17th test case... Problem B

http://mirror.codeforces.com/contest/913/submission/34023515

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Wow, problem G was really great! I also really liked problem F. Good work YakutovDmitriy :)

»
6 years ago, # |
  Vote: I like it +1 Vote: I do not like it

The solution of these problems was very clear! Thanks for the analysis and solution.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Good problems,I like it!