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

Автор BledDest, 5 лет назад, По-русски

Привет, Codeforces!

В 15.09.2019 13:35 (Московское время) состоится Codeforces Round 585 (Div. 2) для участников из второго дивизиона. Участникам раунда будет предложено 6 задач и 2 часа на их решение. Обратите внимание на необычное время начала раунда.

Раунд будет рейтинговым для участников второго дивизиона (с рейтингом менее 2100). Условия будут доступны как на русском, так и на английском языках.

Раунд начнется через 2 часа после начала квалификационного этапа и закончится с ним в одно и тоже время. Поэтому мы просим участников квалификационного этапа не распространять задачи до начала раунда. К сожалению, все задачи не поместятся в стандартный Div. 2 раунд, поэтому мы выбрали шесть из них.

Задачи вместе со мной придумывал и готовил Александр fcspartakm Фролов.

Благодарим Михаила MikeMirzayanov Мирзаянова за возможность провести зеркало квалификационного этапа и за платформы Codeforces и Polygon, Ильдара 300iq Гайнуллина за помощь в подготовке раунда и тестирование задач, а также Адилбека adedalic Далабаева и Романа Roms Глазова за прорешивание задач.

Как обычно, разбалловка будет объявлена ближе к началу раунда.

Удачи всем участникам!

  • Проголосовать: нравится
  • +134
  • Проголосовать: не нравится

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

Могу ли я участвовать в этом раунде, если я заявлен как официальный участник квалификационного этапа, но не буду участвовать в нем (согласно правилам квалификации, команда может участвовать в неполном составе)?

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

    учитывая что это Div2, думаю проблем вообще нет.

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

    Если ты не будешь знаком с задачами, то, конечно, можно участвовать в этом раунде.

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

    Да, в таком случае участвовать можно.

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

I'm newbie. i want to know how to contribute problems for contests???

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

Overlaps with atcoder bc141 D:

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

Well I did a good jod in 584

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

isn't that a clash with AtCoder Beginner Contest 141?

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

[deleted]

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

To be honest, there should be more Division 3 rounds!

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

Friendly time for Chinese users!

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

It is clashing with ABC141. Since ABC always starts at that particular time, can you please prepone this round by 35-40 mins? Many of us don't want to miss either of them.

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

    I think they can't move it because it's like online mirror of the on-site contest.

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

Good 好好!

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

I want to take part in this contest. But whether I can take part depends on whether I can finish my homework in 4 hours and I don’t think I can. QWQ

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

Где можно смотреть монитор собственно квалификации?

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

I'm going to do screencast with commentary in English of this round first, and then jump to ABC141. YouTube

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

Friendly time for Chinese! I can participate even in my school!!!!!

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

    School on Sunday?

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

      In many schools in China (including primary school, junior and senior high school, and most of them are boarding schools), students always go back to school one day before school days. Through sometimes it's illegal. (but truly all the boarding schools do so)

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

        Well, I am also a Chinese student. I do not agree with your opinion. The school is not wrong, even though the time of contest is friendly to us……

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

Scoring distribution?

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

What is the hack for D?

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

Is there a simpler solution to F than 2sat with segtree?

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

    I hope 2-sat with segtree won't pass (I tried to eliminate non-linear solutions).

    The easiest linear solution is to take care of $$$f$$$ by introducing variables of the form $$$f \ge i$$$, that way every station adds only $$$2$$$ clauses (with $$$f \ge l_i$$$ and with $$$f \ge r_i + 1$$$).

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

How to solve E in this contest? Why more than 200 participants solved it?

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

    I think it's googlebale, if you google it you might find a solution, Am not sure thought :(

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

    Compute for each pair of color i,j the cost of putting color i before j and the cost of putting j before i (number of inversions between the two colors), and add the minimum to the result.

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

      Are you sure this doesn't end up in a cycle?

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

        I didn't prove it, but I couldn't find a counter-example, it felt true, and it gets AC so it should be good ? Kudos if you find a hack or a proof :-)

        It's faster also, just the complexity of precomputing inversions in 20 * 4e5

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

          Unfortunately, I'm not in division 1 right now, so I can't hack your solution; but your assumption fails with:

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

    DP on bitmask, like travelling salesman problem, except this time the distance is number of inversions.

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

      Is there a way to precompute the number of inversions? My submission got TLE on test case 7

      • »
        »
        »
        »
        5 лет назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится
        	for (int i = 0; i < n; i++) {
        		for (int j = 0; j < 20; j++) {
        			inversions[values[i]][j] += counts[j];
        		}
        		counts[values[i]]++;
        	}
        
    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      can u explain briefly how u did this problem!! it would be a great help

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

        Ok, so you know that normally the answer is the number of inversions if you just want to sort the array, right? So the idea is that we want to create an ordering of the 20 different colors so that sorting it requires the minimum number of moves. This means we want to find the ordering with the minimum number of inversions. What we do is precompute the number of inversions between each pair of numbers. Then we do a bitmask DP with complexity 20^2 * 2^20. Each state in the bitmask represents "we have considered these certain digits", and when we transition to another state with other digits, just figure out how much this will "cost" us -- it is the sum of inversions where (items in bitmask) < (next item). Then just take the minimum of dp[(1 << 20) — 1] and that's the answer.

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

Lose in the contest and Ticket Game. :(

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

Я где-то раньше видел задачу E.

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

I will become specialist,);

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

For D, can somebody mathematically prove why the average possible value of first half must be equal to average possible value of second half for Bicarp to be the winner?

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

    if ? only on one side: Bicarp always can add (9-a) value on the same side where "a"=previous step from Monocarp

    If ? on both side: Bicarp always can add the same value on 2nd side like Monocarp on previous step on 1st side

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

how to do D,sos!!!

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

    I made some observations, but I may be incorrect.

    (1) If you remove a question mark from each half, the winner does not change. I could not fully prove this, but a partial proof is if Bicarp was the winner before, then adding a ? to each side means that any Monocarp's move can be countered by Bicarp by doing the exact same move on the other side. (2) So we can keep removing question marks until only one half has a question mark. Now if there are odd number then Monocarp has the last move and can always win. (3) Define difference as subtraction of question_mark half from other_half. If even then if the difference/9 = question_marks/2 then Bicarp wins, else monocarp wins (also difference%9 must be 0 and difference must be positive). This is because any move Monocarp makes, Bicarp can make a move so that the sum of their moves goes up to 9.

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

      Intuitively it hit me that it has something to do with average value of both halves. I calculated sum1= sum of first half by replacing all '?' with 0,
      sum2= sum of second half by replacing all '?' with 0,
      max1= sum of first half by replacing all '?' with 9,
      max2= sum of second half by replacing all '?' with 9, Then observed that it was Bicarp who was winning if sum1+max1= sum2+max2 and it passed. Not able to prove it mathematically as to why this is happening.

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

        Proof:

        1, as above, we can assume there are question marks only on one side 2, assume that left half has no question marks. Suppose the right string is xxxxx????. Then if Monocarp plays any value i, then Bicarp can play 9-i, and can always make the string reach the average_value as you calculated. 3, Bicarp cannot make the string reach any other value, because then Monocarp would simply deviate.

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

      After you delete same number of question marks from each side the remainder of question marks is guaranteed to be even. Let s be the remaining number of question marks and f be the difference of both halves. Now first move is made by Monocarp as there was even moves removing question marks from both sides. Now for the last part if the remaining question marks are from the bigger half, Monocarp is guaranteed to win as you can't put minus digits. Now if from the lesser half, if (s / 2)*9 == f, Bicarp wins by putting (9 — (digit monocarp put)) every turn. In other cases if (s / 2)*9 < f Monocarp just puts 0 every turn and f is unreachable. Else if (s / 2)*9 > f Monocarp just puts 9 in every turn and f is surpassed.

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

Can someone give hints for problem C?

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

    Find (b,a) pairs, (such that first string has 'b' in that position and second string has 'a'), and use one swap to fix. Find (a,b) pairs and use one swap to fix. Then find the remainder (b,a/a,b) pairs if there exist, and use two swaps to fix.

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

      After reading your cooment and seeing some code, I got to know that string only contains alpha 'a' and 'b'. I wasted so much time on it after solving D. Is it possible to solve when each alphabet is allowed.

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

    Look for all pairs (i, j) of discrepancies such as s[i] != t[i] and s[j] != t[j] and s[i] != t[j], and swap them. If there is no such a pair now, swap s[i] with t[i]. Continue until all is fixed.

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

How to solve B ?

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

    Use dynamic programming — calculate the number of negative and positive substrings ended at each position. The accumulated value will be the answer.

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

    Define dp(i,+) as the number of arrays that end on the i'th array that are positive, and dp(i, -) as the number of arrays that end on the i'th array that are negative.

    Then the dp states are updated as follows. if the current number is positive then dp(i,+) += dp(i-1,+) + 1 dp(i,-) += dp(i-1, -)

    if the current number is negative dp(i,-) += dp(i-1,+) + 1 dp(i,+) += dp(i-1,-)

    (the + 1 is because the number itself adds to the answer if it is positive or negative)

    Final answer is sum of all dp(i,-) and dp(i,+)

    60616510

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

    my submission first go through whole array and count start from idx 0 and end at 0 to n — 1;

    and count if segment is negative or positive;

    neg, pos;

    set positives = 0, negatives = 0;

    and go through idx 0 to n -1 again.

    if current array element is positive 
    
        pos--;
    
    else if current element is negative
    
        neg--;
    
        swap(pos, neg)
    
    positives += pos;
    
    negatives += neg;

    time complexity is O(n)

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

back to green :)

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

Is there something wrong on score board?

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

Back to green :)

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

When I finished the program of problem C, the contest just had ended.I am too slow!What a pity! I need to practice more! Practice makes prefect.

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

    Exactly the same thing, half hour more and I would solve it also. Today with minor fixes my solution has passed.

    -rating but +knowledge

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

Is there something wrong with the rating board?

I can see my E,F both accepted in status,also when i click the -1 on the rating board.

But the rating board shows that they fail in the system test(FST).

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

Is it hilarious when your code get correct on the sample testcases and times up?

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

Wow, so many WA on D...

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

Just what the heck is D test case 23, literally hacked half the solutions.

Btw, How do we solve D, and what's the intuition for it?

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

    I solved D with greedy:

    Try to maximize left half, minimize left half, maximize right half, or minimize right half for Monocarp, then if at least in one case Bicarp can't make it equal, Monocarp win, else Bicarp.

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

      So basically we need to simulate the process of maximizing one part and check if the other part can still be equal?

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

        Basically i let Monocarp play his ceil(cnt / 2) turn with the mentioned strategy, and let Bicarp try to equalize. (cnt = number of ? in string).

        Actually checking first 2 case is enough.

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

    Split the string into two part, calc the sum of left and right parts (denoted as s1 and s2), and how many unknown digit for each sides(denoted as c1 and c2).

    Then this problem become: there is a number s=s1-s2, you can do c1 times plus operation and c2 times subtract operation, if the result is 0, then the second guy win, else the first one.

    Now it's still difficult, so let's transform subtract operations into plus operations. Because of subtract x equal to plus y-9 while y = 9-x.So now the problem is about a number s'=s-9*c2, you can do c1 + c2 times plus operation.

    It's easy to prove only when res = s' + 9 * (c1 + c2) / 2 equal to 0, the second guy will win.If res < 0, then first guy can always plus 0 in each turn, else plus 9 in each turn.

    I don't know whether the idea is right because I haven't submited it.

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

I

hacked other's problem D successfully during the contest;

I

on problem D got a FST;

I

wrote a "if(tmp==(a-b)/9)" while it's supposed to be "if(9*tmp==(a-b))".

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

Why is the submission 60623002 still running on pretest 8

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

Its seems like Testing System is stuck in something. It says 100% for a while (longer than normal). Is there anyone know the broblem?

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

So good pretests for D

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

    Probably BledDest and his team are fans of trash rounds from '...' with lots of hacks and being in love with bad pretests. OR THEY THOUGHT THAT IT WOULD BE EDUCATIONAL ROUND LMAO

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

    Many solutions on D failed because several contestants did integer division by 9. That works if Bicarp wins, but may give a false alarm if Monocarp wins.

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

I got a wrong on test 9 on problem B coz i wrote (int n) instead of (long long n ) . now I feel sad , I spent time on it and didn't get it till the contest is finished .

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

Me: ratings -110 in a weekend, life sucks

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

I wrote D in a different way.

Consider their moves, at first, it must be M try to enlarge the gap between the sum, and B try to make it smaller.

So we can brute force their choices, and just consider edge cases that they need to move on the same side. It is easy to find that the maximum gap and minimum gap can M create can calculate in O(1), so the problem can be solved.

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

On problem C, why this answer: 3 {1 3} {2 6} {7 8} is not good for this test 8 babbaabb abababaa ?? It seems ok....

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

On problem C, why this answer: 3 {1 3} {2 6} {7 8} is not good for this test: 8 babbaabb abababaa It seems ok...

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

А можно уже публично обсуждать задачи квала? (те, которых не было на раунде)

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

how to solve A? I didn't get the idea

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

    My solution: (not the optimal solution)

    For the minimum: Consider C is the number of players and k is the amount of cards a player can get before being banned. Every player can receive k-1 cards and still be in the game so you can give every player k-1 cards and since every player is one card away from being banned the number of cards left is the minimum number of players. min = min_team1+min_team2; (if minimum is negative result = 0 !!)

    For the maximum: you can pick the team with the smallest k and while players > 0 and n-k >= 0 you can pick a player then n = n-k; then same for the second team. you can do this with math equations but I find Greedy easier to understand

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

    A more naive solution: Just use priority queue to simulate the process.
    My solution can be found here.

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

The 3rd Test Case in C question . I think it can be done in 2 moves rather than 3.

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

Any idea how to solve problem C, if the strings are allowed to have any characters from lowercase English alphabet?

We can reduce the strings to atmost $$$26×25$$$ length by removing matching pairs and reducing similar non matching pairs like we did with all indices where $$$s[i]=a$$$ and $$$t[i]=b$$$ in problem C. Will greedy work after that?

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

    Well, one observation is that any operation must increase the number of matching indices (s[i] == t[i]) by at least 1. So we might iterate over all pairs of indices and check whether we can make an operation such that for one of those indices, say j after the operation, s[j] == t[j]. If we find such a pair, we remove j and continue. Otherwise, we stop and if the string is non-empty, then there is no solution.

    That works in time O(alphabet_size ^ 6), which seems to be well enough.

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

The 3rd Test Case for C question . Can it be done in 2 moves rather than 3 ??

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

can someone help me the case where my solution for B fails.. My-solution

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

    pref[i] *= arr[i] / abs(arr[i])

    We dont need array a we just need sign of a and if you do just pref[i] *= a[i] then after 3 iterasions with 10^9 it becomes 10^27 which doesn fit anywhere

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

Editorial?

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

The editorial is out!

I am really sorry for the issue with problem E. Looks like before the contest I was too inattentive to think about solutions without subset DP and how to eliminate them. After seeing this idea in a comment, I started stressing a test against it and simultaneously trying to prove it, but by the time the countertest has been found, it was already too late (something like 2 hours after the round).

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

    How were you generating testcases?

    Spoiler

    I found this is the smallest case that should prevent people from calculating cost the wrong way and it's only 7 digits long.

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

      I tried stressing on 3 different colours and small length of the input (from 5 to 15), and only after increasing length I actually generated something useful (a testcase with $$$n = 284$$$ which breaks these solutions).

      Maybe it was bad to choose a range of possible lengths instead of some fixed length.

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

Can anyone please tell why my B passed? When I looked at it after contest and ran it through some cases, It didn't make sense. https://codeforces.com/contest/1215/submission/60621363

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

    I also didn't understand your code at first and tried to come up with countercases, but I couldn't and in the process, I came to the conclusion that the algorithm was correct.

    So here's a small proof:

    First notice that pref[i] % 2 == 0 iff the product of numbers up to i is positive.

    When calculating the number of positive subsegments, you have 3 terms:

    • The number of ways to choose two indices, i and j, such that the products of numbers up to i (inclusive) and j (inclusive) are both positive / both negative. That means that, in both cases, there is an even number of negative numbers between i + 1 and j (we use a similar property when constructing prefix sums). Thus, the subsegment (i, j] is suitable.

    • The number of indices i such that the product of numbers up to i (inclusive) is positive. This means that the subsegment [1, i] is suitable (1-based indexing).

    So we proved that all those subsegments are positive. It remains to prove that we haven't missed any other positive subsegments.

    Let's make the proof by contradiction. Assume there is a subsegment (i, j] such that the products of numbers up to i and j (both inclusive) have different signs. That means that there is an odd number of negative numbers in the interval [i, j] (again, remember prefix sums), and the subsegment is negative.

    The number of negative subsegments is simply this amount subtracted from the total number of subsegments.

    Overall, B was a bit tricky, even though it's obvious that the problem is classic. It took me the longest to solve from [A, D], and I have only a vague understanding of why my code works.

    Hope that helped!

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

А вы выложите потом этот квал целиком в виде тренировки?

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

Can someone tell what's wrong with my solution for D. I've greedily simulated the game by M increasing the difference and B reducing it. Code

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

    maybe sometimes if M reducing the difference is a better choose. like this example:

    4 ??01

    if M choose write a number>=2 on the left sum(right)-sum(lift) will be negative,and M will win. but you code will cout B.

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

This is my code for D which simulates the game optimally .My code

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

Lovely contest. Keep up the work

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

Хотелось бы поблагодарить авторов за присутствие достаточно оригинальных и нестандартных задач на полном контесте (несмотря на то, что "всего лишь" квалификация — очень качественный набор получился, идейный и с естественными формулировками). Навскидку — про шарики, игра с билетом, фонари. Наверняка что-то еще упустил.

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

Still waiting for the editorial.!

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

When will the winners be announced? :3

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

The full Qualification Stage has been added to the Codeforces Gyms.

Note that the problem "The Number of Products" is different from the one used in the round.

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

Problem difficulties have not been assigned yet.