Блог пользователя tourist

Автор tourist, история, 6 лет назад, По-русски

Разбор задач Hello 2018 доступен на русском и английском языках. Приятного прочтения!

Возведение в степень по модулю
Новогодняя елка
Лимонад для вечеринки
Слишком простые задачи
Логическое выражение
Сильносвязный турнир
Степенная подстрока
Не превышай
Разбор задач Hello 2018
  • Проголосовать: нравится
  • +463
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

Not a single tutorial is available ? Only solutions ?

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I'm liking this new trend.

»
6 лет назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

why did this code accepted for Problem A?

cin>>n>>m; int a=pow(2,n); cout<<m%a<<endl;

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    При n==1000000 ,выражение станет больше чем unsigned long long;

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      6 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

        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.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится -10 Проголосовать: не нравится

    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

»
6 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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

Thanks for the contest, it was fun!

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится -16 Проголосовать: не нравится

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 :)

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +12 Проголосовать: не нравится

    It fails for the case:

    Spoiler 1
    Spoiler 2
    Spoiler 3
  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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.

»
6 лет назад, # |
  Проголосовать: нравится -15 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is there different kind of solution for problem C?

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Here, 34034532 .

    Same logic but a bit different implementation. :)

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
6 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    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)

    • »
      »
      »
      6 лет назад, # ^ |
      Rev. 4   Проголосовать: нравится +3 Проголосовать: не нравится

      "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.

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

        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).

»
6 лет назад, # |
  Проголосовать: нравится +57 Проголосовать: не нравится

My rating is now fibonacci sequence (2358) :)

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

ууу матан, дайте задачки которые возможно решить 10-ти классникам :(

»
6 лет назад, # |
  Проголосовать: нравится +20 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    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.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    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!).

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится
  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Can you explain your approach? Thanks!

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +14 Проголосовать: не нравится

      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.

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        3 7 5 11 18

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

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

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

          • »
            »
            »
            »
            »
            »
            6 лет назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

            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 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Пытался решить задачу E (Логическое выражение) поиском в ширину (или даже больше на Левита похоже):

1) создаем массив string-ов formulas длинны 256, где по "вектору значений" функции будем хранить функцию ответ на задачу

2) существует всего 3 функции длинны 1 ("x", "y", "z"), добавляем их в очередь

3) пока очередь не пуста:
* вычисляем val — значение текущей функции на всех возможных аргументах
* если для formulas[val] еще не вычислен или мы нашли более удачную функцию, то обновляем значение в массиве и пытаемся "расширить"/"дописать" данную функцию, для нахожения остальных формул

формулу f я расширял по следующим правилам: !f, f&x, f&y, f&z, f|x, f|y, f|z, !(f), f&!x, f&!y, f&!z, f|!x, f|!y, f|!z, (f)&x, (f)&y, (f)&z, (f)|x, (f)|y, (f)|z, (f)&!x, (f)&!y, (f)&!z, (f)|!x, (f)|!y, (f)|!z

таким образом мне удалось найти только 218 функций.

видит кто-нибудь ошибку? или просто я побрел не в ту степь?:)

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Надо расширять до f & g и f | g для всех пар функций f и g, найденных к текущему моменту — тогда решение заработает.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      спасибо, я так тоже сделал, тогда находятся все функции, но не обязательно оптимальные по длинне / лексикографическому порядку

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    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!

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      6 лет назад, # ^ |
      Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

      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!

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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)

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can't we slv B. Christmas Spruce with c ?

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Did you mean C language? In this task yes. But usually you can get 105 vertexes with [0;n - 1] edges (of course you can't create array [105][105]). That's why it is recommended to use C++ for sport programming :)

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

For problem C fourth example, why i get 44981600797903355?

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

i use dfs to solve the problem C 34018956

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Можно пояснить про E?

Заметим, что выражение однозначно задает то, какой функции оно равно и из какого нетерминала оно раскрывается.

Что подразумевается в данном случае под нетерминалом и почему количество возможных функций умножается на всего лишь на 3?

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Нетерминалы — переменные из грамматики, в данном случае это E, T, F.

    Состояние — пара (нетерминал; функция). Таких пар 3·223.

»
6 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

can we solve E using Karnaugh maps??

»
6 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

34011797

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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

      • »
        »
        »
        »
        6 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        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

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          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 ?

          • »
            »
            »
            »
            »
            »
            6 лет назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

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 ?

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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 !

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

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?

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    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?

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

In Solution of 913C ,in the following line

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

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

»
6 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

"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?

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Good problems,I like it!