Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

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

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

Всем привет!

Завтра в 12:35 по Москве состоится Codeforces Round #376 для второго дивизиона. В это же время в Москве будет идти Московская командная олимпиада школьников, и, уже традиционным образом, на её основе мы составляем для вас раунд на Codeforces. К сожалению, сформировать хороший комплект подходящих задач для первого дивизиона в этом году мы не смогли, но, как и всегда, мы приглашаем участников из первого дивизиона написать раунд вне конкурса.

Задачи для вас готовили timgaripov, platypus179, wilwell, Flyrise, ipavlov и vintage_Vlad_Makeev под моим руководством. Также хочется поблагодарить членов жюри основной олимпиады Endagorion, Е. В. Андрееву и GlebsHP, который выступает также в роли координатора со стороны CodeForces. Не забудем и про стандартные слова благодарности в адрес MikeMirzayanov за систему Polygon, которая значительно упрощает процесс подготовки задач и координации деятельности большого количества вовлечённых людей, и за прекрасное сообщество, членами которого мы все являемся.

Вам будет предложено 6 задач на 2 часа. Всем удачи!

UPD Соревнование завершено, всем спасибо за участие! Разбор задач будет опубликован позднее.

UPD2 Прошу прощения за задержку с разбором. Наконец, он доступен здесь.

Поздравляем победителей раунда:

  1. DmitryBelikov
  2. ljsss
  3. kehKeLenge
  4. dilsonguim
  5. UoA_Menma
  • Проголосовать: нравится
  • +226
  • Проголосовать: не нравится

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

An automorphic Round (376)

376 * 376 = 141 376

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

Am I the last AC submission ?

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

Most of the schools are open at that time in Iran (and maybe other countries) :(

Missed four consecutive rounds just for the unusual time :(

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

Am I the only one feeling tired of reading comments like "Unusual is the new usual"?

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

downvote me plz

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

I hate this new usual time :(

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

Most of the Middle East universities are open in this time :'(

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

Did anyone notice a sudden increase in contribution points? My contribution went from -30 to -3 in less than 3 days, without any wave of new upvotes.

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

In contest invitation mail Zlobober isn't legendary!

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

The time is very good for Chinese competitor.

But it is a pity that the beginning time of this round is just the ending time of Dalian regional contest.

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

In the registrants list, Div. 1 participants are not marked as unofficial participants. Is that normal?

Update: it's fixed, actually.

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

why div 1 participants are not unofficial ?

Update : fixed

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

    What part of "Unfortunately, this time we weren't able to come up with a good problemset for a first division contestants" do you find hard to understand?

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

The round starts 1.5 hours after Google APAC 1D ends.

Will have to eat quickly, rest in that time and be ready for the round. :D

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

    Oh boy, I literally dieded.

    I almost reached rank 200, but my computer hung at the last second and it costed me 16 points. Shouldn't have submitted the code after the contest, that was freakin painful.

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

Love the timing of recent contests. Usual timing is 2am for me, so am happy to actually be able to participate in a few contests.

But I understand that others may not agree :)

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

Zloy bober

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

I'll join. It's my first time.

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

haha This time is good !

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

score distribution?

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

6 problems for 2 hours.Hopefully problem set will be easy at least 3.

Best wishes everyone.

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

10 minutes Late:)

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

Start delayed! How unusual!

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

Score distribution?

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

Типо на 10 минут ещё перенесли начало?

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

Upvote me, please!!!

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

    Во-первых, вы написали по-русски и англоязычные пользователи не увидят вашего комментария.

    Во-вторых, зачем?

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

Why Delayed ?

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

I just don't get what is this problem which happens right in the begin of the contest and can be fixed in 10 minutes !

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

800+ unrated users registered today we all know whats gonna happen

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

could some one say problem B more clear ? ! i cant understanr it : ( pleaseee ...

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

Problem B, Could He uses both coupons and discount at same time? like if it is 50 pizza, could he use 48 coupon and 1 discount?

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

    Well for B, you can use discount only if you are buying 2 that should solve it :| explanation sucks

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

    If he should buy 3 pizzas, he can buy 2 pizzas with discount and 1 pizza with coupon.

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

My submission for D is in queue for 5 mins. Still waiting.

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

Am I the only one feeling tired of reading comments like "Unusual is the new usual"?

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

i hacked on F with complexity n*n for n=10^5. It failed ! Does the new server support 10^10 ??
Edit: Got it ! My test case wasnt good enough !

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

How to solve C?

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

    Hint: think about DFS

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

    dsu i think

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

      I too thought of dsu, but it kept failing at pretest 5. Any reason why it might not work

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

      Can anyone illustarate smooth dsu solution

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

        build a graph with undirected edges from each l[i] and r[i].now socks at indices l[i] and r[i] must have same color.now use dfs to find the connected components.its just like a normal dfs on undirected graph with edges from l[i] to r[i].each connected component should have same color.after finding components,for each component find the color which exists the most number of times and paint all other socks with this color.this minimizes the required number of paintings.for reference you can see my code.21497227

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

          Damn, I spent about 1.5 hours on this problem and couldnt solve it. How do you guys think up these solutions? I understand it, and it is quite simple, but why does it actually work? "find the color which exists the most number of times and paint all other socks with this color.this minimizes the required number of paintings" — I understand that sometimes you just see the pattern and cant prove it, but how to see this pattern... :( I failed many problems just not being able to see the pattern. How can I improve this skill? Thanks in advance

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

            me too couldn't solve it during contest and i realized it later. I think it all comes with practice.

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

            From my practice experience, whenver I think of a strategy in a scenario I go through steps like this:

            1. Come up with preprocessing ways that helps you analyze the situation.

            2. If it's a game then most of the time it is minimax considering it is the most frequent one that pops up.

            3. Go for greedy, enumerate a few test cases that I think that could be tricky to handle. If greedy still works, then go for it.

            4. If not, see if there is a dynamic programming relation between the states. Go for dp if it is available.

            5. If there is still no solution, then you are probably missing some major observation. Dig deeper into the sample cases for inspirations. Also check if the constraints are small enough for more naive solutions to pass.

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

    Build a graph like this : If you have socks l[i], r[i], then add undirected edge from l[i] to r[i]. Now for each connected component in this graph, you must have 1 color. So we can solve each component independently. It's optimal for each component to change colours of all nodes in that component to the colour that appears the most in that component.

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

      I used DFS....as u said.. But someone hacked me.. How? here is my solution solution

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

        for(i = 1 ; i <= N ; i++){ if(visited[i] == 0){ for(j = 1 ; j <= K ; j++) countcolor[j] = 0; _max = 0; ll v = dfs(i); ans += (v-_max); } }

        It works only with a few components count. I guess if theres maximum N and M — min, for instance 1, this would be N*K, while N = 2*10^5 and K = 2*10^5, which is TL, obviously.

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

        you are looping through color array every time.here your worst case will be N*K.instead just use a map and you can clear the map every time you run dfs.

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

    Consider socks as nodes and pairs as edges. Now in this graph,paint each component with the color which have highest frequency in that component.

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

    For input
    5 3 5
    1 1 3 4 5
    1 2
    2 3
    4 5

    You can split all the socks into groups (sets):
    S1 = {sock1, sock2, sock3},
    S2 = {sock4, sock5}

    All the socks in group S1 should be painted in a single color and all the socks in the group S2 should also be painted in a single color (probably, different from the color of S1).

    For the group Si we count the most frequent color among the socks and paint all the rest socks in that group to that color. In my example the socks in the group S1 have following colors:
    S1 = {black, black, red}

    The most frequent color in group S1 is black, so we paint the remaining sock (which is red) to color black. After repainting the set will look like that:
    S1 = {black, black, black}.

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

How to solve F?

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

    Maybe you have to learn how to solve A and B, too early for F ..

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

      It seemed interesting, because for small constraints it works but I got TLE for large ones which means I was doing something really wrong. So I am interested in learning.

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

      Lets not judge just by looking at color of handle :)

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

    I used some prefix array to know in O(1) time how many graphic cards are there with power from i to j.

    Then for each available power of graphics, for example for power 2, i was checking prefix array every 2 (2,4,6,8) and i was increasing max result for this power by (cards in this interval)*(current value/power i was checking(2) ).

    O(nlogn)

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

    Consider every distinct tape as the leading tape and calculate the answer for this using sieve-like technique. Consider tape a[i], then all elements in range i*a[i] to (i+1)*a[i] will be added as i*a[i]. Number of elements between a range can be calculated using a precalculated array since the numbers are less 10^6.

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

please explain C I tried to do it bfs but it doesnt seem to be like that

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

    I did it using bfs, i made disjoint sets, and tried to find out the most repeated color in each disjoint set, and subtracted that value by size of the disjoint set.

    • »
      »
      »
      8 лет назад, # ^ |
        Проголосовать: нравится -30 Проголосовать: не нравится
      #include <stdio.h>
      #include <map>
      #include <queue>
      #include <memory.h>
      using namespace std;
      int n, m, k;
      int color[300000];
      map<int, map<int, int> > tree;
      map<int, map<int, int> > sorted;
      int index[300000];
      int index2[300000];
      int visited[300000];
      int cnt[300000];
      int ans, p;
      
      void bfs(int col, int s)
      {
          queue<int> q;
          q.push(s);
          int i;
          while(!q.empty())
          {
              int now=q.front();
              visited[now]=col;
              sorted[col][index2[col]++]=now;
              q.pop();
              for(i=0; i<index[now]; i++) if(visited[tree[now][i]]==0) q.push(tree[now][i]);
          }
      }
      
      int main()
      {
          freopen("input.txt", "r", stdin);
          scanf("%d%d%d", &n, &m, &k);
          int i, j;
          for(i=0; i<n; i++) scanf("%d", &color[i]);
      
          for(i=0; i<m; i++)
          {
              int l, r;
              scanf("%d%d", &l, &r);
              tree[l][index[l]++]=r;
              tree[r][index[r]++]=l;
          }
          int cur=1;
          for(i=1; i<=n; i++)
          {
              if(visited[i]==0)
              {
                  bfs(cur, i);
                  cur++;
              }
          }
          for(i=1; i<cur; i++)
          {
              memset(cnt, 0, sizeof(cnt));
              p=0;
              for(j=0; j<index2[i]; j++)
              {
                  printf("%d ",sorted[i][j]);
                  cnt[color[sorted[i][j]]]++;
                  if(p<cnt[color[sorted[i][j]]]) p=cnt[color[sorted[i][j]]];
              }
              ans+=index2[i]-p;
              printf("\n");
          }
          printf("%d", ans);
      }
      
      

      this was my code, when i realized that it fails sample test 2 please help me what is wrong?

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

        Can u copy send link to your solution instead of copy code ? This seem inconvenience. sory fo my bad E =)

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

    BFS works fine. The input is just not usual. For example, the input li = 10, ri = 42 may be repeated:
    10 42
    ...
    10 42

    this may lead you to insert 42 into adjacency list twice:
    adj[10].push_back(42);
    adj[10].push_back(42);

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

How did people use graph solution for problem C? What if graph is really dense ? It should go out of memory..

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

Что аномального в F? Почему так много участников прошли претесты на самую сложную, по мнению авторов, задачу? UPD: У меня второй контест подряд нулевое изменение рейтинга, лол. Стабильность — признак чего там? :)

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

    Я думаю, что у очень многих участников F не пройдет системные тесты.

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

    она использует очень стандартную идею, когда ты понимаешь, как её сюда применить, задача становится очень простой

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

Was F easy or there are some tricky cases waiting in system testing

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

ПО ЗАДАЧЕ С — АВТОРЫ ВЫ ЧЕГО КУРИЛИ,ЧТО БЫ ПРИДУМАТЬ ТАКОЕ УСЛОВИЕ.НОСКИ,БАНКА КРАСКИ,ДЕЛОВЫЕ ПЕРЕГОВОРЫ,ПОЙТИ ИГРАТЬ В КРУТУЮ ИГРУ,МАТЬ УЕХАЛА В ТЕПЛУЮ СТРАНУ.

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

I will fail b because I declared N to 1e5 and not 2*1e5, horrible mistake but I'm wondering why pretest doesn't cover such case!

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

Very interesting round to me !

I saw a lot of random solutions for F and some greedy for E... It will be a lot of WAs.

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

Can F be solved with a fenwick tree, and summing contents of the intervals between each power? I think that is O(n (log n)^2), is that fast enough?

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

How to solve F?

I noticed that the main card should be a prime, or 1.

Then I wrote a sieve and a map to insert a number along with its index (in sorted input) in the map for each of its prime factors.

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

D was really interesting. I got AC it using BIT. First of all, ans can be in range [0, c - 1]. For every successive interval, I found what intervals can lead to correct sorting order(handled by L and R), and what intervals cannot(handled by BIT). I maintained the interval [L, R] that contains the answer, and also BIT stores what index cannot be our answer. Finally, for any L ≤ i ≤ R, if BIT allows this to be an answer, print it. Otherwise answer doesn't exists.

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

Is the following approach for D right? I implemented this algorithm but it doesn't pass some pretests. Where is the mistake in this solution? Take two adjacent words, find the first position where letters are different. If the first letter is greater then we need to turn the wheel by minimum (c-a[i]) so that it becomes smaller than b[i]; if the second letter is greater then we can turn the wheel by maximum (c-b[i]) or else a[i] becomes greater. Store the maximum of the minimums and the minimum of the maximum and if the second value is less than the first then print "-1", else print the first value.

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

    I also did similar. However "if the second letter is greater then we can turn the wheel by maximum (c-b[i]) or else a[i] becomes greater. " This is incomplete. There is another case.

    Eg:

    5 -> 6 -> 7 -> 1

    7 -> 1 -> 2 -> 3

    (c = 7)

    As you see you could also rotate it 3 times and still ordered.

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

    i implemented this too, but there's a catch!

    Suppose n=2 ,c=6 1 2 1 3

    (the numbers are 2 and 3)

    Then according to the above logic you can turn max:3 times but if you turn 5 times it again becomes valid. Hope it clears the doubt!

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

    You have missed out cases.
    Let a be the char of the first word and b be that of the second word, at the first point of difference.

    If a < b, the valid range is [0, c-b] U [c+1-a, c].
    If a > b, the valid range is [c+1-a, c-b]

    Then from the valid ranges of all the pairs of adjacent words, you can choose any common value. If there is no point which is common to all the ranges, answer is not possible.

    Also, apart from these, if the second word is a prefix of the first one and is shorter than the first word, answer is not possible.

    Code

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

      Shouldn't the valid range for a<b be [0, c-b] U [c+1-a, c-1]. The problem statement expects an ans in [0, c-1] and the changes in c steps in fact reflect those that can be done 0 steps. Seems the test cases are weak.

      Code

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

        It doesn't matter since if [c] is available then [c%c=0] is also available, and the smallest solution always get chose first.

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

I used DSU for DIV2 C but I am getting TLE on pretest 6.http://codeforces.com/contest/731/submission/21488359

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

I solved the C problem with DFS, but I got TLE... How to optimize my code? http://codeforces.com/contest/731/submission/21484127 Or is it just recursive vs queue? XD

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

    If the graph is empty, your codes is O(N2), because of this:

    memset(colNow,0,sizeof colNow);
    
  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    The problem isn't in dfs i think. But in

    memset(colNow,0,sizeof col)
    

    Think when there are many connected components, it will get tle.

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

    In the worst case memset would be called 2*10^5 times , which is basically O(N^2) . Use a map instead .

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

    you can save the vertices that you go to them in dfs ,in a vector and after dfs make the colnow of them equal zero or dfs again and do it

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

kudos to the author for such a nice contest!

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

What's the idea for solving E ?

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

    What I did was this.

    Let DP[1][i] be the max score which can be obtained by Petya, if in his next turn he has to choose a prefix of length at least i and let DP[0][i] denote the same for Gena.
    Let S[j] denote prefix sum till j, i.e. arr[1]+arr[2]+arr[3]+...arr[j]
    Petya tries to get the maximum value possible and Gena tries to get the lowest value possible.

    DP[1][i] = max(S[j] + DP[0][j+1]), j>=i
    DP[0][i] = min(-S[j] + DP[1][j+1]), j>=i

    The answer is given by DP[1][2] (1-indexing is used).

    Code

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

    Dynamic Programming on prefix sum array

    check this:

    http://codeforces.com/contest/731/submission/21488865

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

    Let S[i] be the sum of the numbers from 1 to i.

    Let D[i] be the optimal maximum difference for the current player if the leftmost sticker contains the sum of the numbers from 1 to i.

    Then D[i] = max{S[j] — D[j]} for i < j <= N.

    But since S[j] — D[j] is independent of i, we can just keep track of the maximum S[j] — D[j] and update it at every loop, leading to O(N) solution.

    code: http://codeforces.com/contest/731/submission/21495276

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

      How you are taking account of the two persons , please elaborate?

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

        The best play for one person in a certain configuration is the same as the best play for the other.

        "Then D[i] = max{S[j] — D[j]} for i < j <= N"

        S[j] is what you get from choosing up until the sticker j

        D[j] is the best play on the configuration j

        So you choose the best play possible for every situation.

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

As I see, problem F easier than problem D & E, problem B easier to WA then problem F :)) funny contest

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

Hopefully become Expert:)

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

I think problem C can be interpreted in 2 ways.
1. Counting cost of colouring of both left and right pieces of i-th pair of socks as 2.(Counting colouring of each left and right sock seperately)
2. Counting cost of colouring of both left and right pieces of i-th pair of socks as 1.

During the contest, I have implemented assuming case:1, which failed on pretest 3.
After the contest, I see that I was supposed to assume the other case.

Here are my submissions with only difference being which assumption was considered among the above.
Assumption-1 : 21492459 Failed
Assumption-2 : 21493466 Accepted

Should have got this clarified during the contest :(

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

can someone identify the mistake in my submission for "C", i keep getting WA on 6.

code = http://codeforces.com/contest/731/submission/21492734

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

Rating Updated!

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

Got TLE for C at test case 33 mysolution . I tried with DSU. Could somebody help?

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

    there's a small thing that needs to be considered .i think you are clearing the count array every time you run dfs.instead use a map and clear it.

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

Сейчас бы за F 3000 давать

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

Finally I'm Cyan !!, and I solved 3 problems from the first submission.
Self confidence is rising here !
thank you Zlobober very much for the nice contest

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

No hacks this time :-)

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

http://codeforces.com/contest/731/submission/21485811 WA in test case 66 :( Can anyone help ?

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

    I also unintentionally did the same mistake...Since the values of array may not be distinct. So, we should avoid calculation for same elements , otherwise if we calculate for value say, 1 or 2, for many times, then this will lead to O(n*n)...I had sorted array, then was trying to escape repetition, but forgot to do that while coding,, finally, which causes TLE :( .

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

How do you solve problem B? I wrote "something" which passed the pretests but it doesn't work it some cases. What's the normal solution for this problem?

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

    Iterate from left to right . If arr[i] is even we can use coupons and we are done . But if arr[i] is odd , arr[i+1] should exist and should be positive . If not print NO else do arr[i+1] -= 1 .

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

      Thanks, that's so easy and obvious...I actually thought the same but then was misled by some example which I treated incorrectly.

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

anyone can find my code bug for problem C ????? I'm using DSU , calculating all socks needed minus the largest number of colors for every parent. http://codeforces.com/contest/731/submission/21491376

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

:'( F gave TLE on 26th test passed just by fast I/O Yeah Life is unfair!

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

I don't know why, but I found Problem B very tough (I solved it somehow though :P). Can anyone suggest a simple solution?

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

    Here is mine:

    • For i = 0...n-2 (skips the last) ---> if a[i] > 2 then a[i] %= 2 ---> after that, if a[i] == 1 and a[i + 1] == 1 then reduce both of them.

    The result is 'YES' if sum of remain elements in a is 0. Otherwise, it is 'NO'. Hope this helps.

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

    Break the array wherever 0 is present. Find sum of each part. Answer is YES if sum of each part is even.

    Code

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

There is something mystery in this contest for my case. My code for solving problem C returns 2 for Test 5, which is correct, on my computer. But when I upload the code, it became 3, which is wrong answer.

Because it's correct on my computer so that I have no idea where it went wrong. Please take a look: http://codeforces.com/contest/731/submission/21493963

Many thanks. P/S: Picture proof.

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

Nice round.. I think problem F was overrated ... it should have been a C or a D. however it was an interesting round. thanks

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

3 points from getting blue :C Anyways, can someone please tell me the solution for problem F?

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

    Let f(x) denote the number of integers that are  ≥ x. Then, if we fix a number i as leader, the total sum will be f(i) + f(2i) + f(3i) + ....

    We can precompute f(i) for all i ≤ 200000 by using the same method as sieving primes. The time complexity is .

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

      Interesting, I didn't think about that.

      If you don't precompute f(i) you can use binary search to find it, making the complexity O(n*logn*logn) but without the need to worry about precomputation.

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

      Very nice solution, thank you.

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

      Interesting solution :)

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

      I don't understand even if you precompute f(i) for all i<=200000, then also you have to sum it for i, 2i, 3i, ... (200000/i) elements. Why isn't it O(n^2). Here's my solution along the lines suggested by you, it's getting time limit exceeded and the reason I could think of is the above. Am I missing something.

      http://codeforces.com/contest/731/submission/21516249

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

        Make sure you don't visit the multiples that you have already visited and it should get accepted. You took care of the case with repeated ones but look at the one you got TLE'd (repeated twos)

        Edit: it is worth noting the reason why this is O(nlogn).

        If you don't visit the same number twice, it takes at most N+N/2+N/3+...+N/N.

        That's the same as N(1+1/2+1/3+...+1/N). That sum is bounded by ln (look for the integral of 1/x from 1 to n) so the complexity is O(n*logn).

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

    deleted

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

Spent an hour and 2 wrong submissions on C because I thought you had to color socks dynamically every day and not just all of them at once beforehand. :D

Good thing I went and solved F before realizing how easy C actually was.

Just wondering, how to solve C if you can color socks dynamically?

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

anyone knows why my solution for c fails? http://codeforces.com/contest/731/submission/21498239

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

Can someone explain the solution to Problem D?

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

    Here is my approach:

    For each block i (0<=i<n-1), compare them in lexigographical order. It should fall under one of these cases: (Let j be the position where a[i] and a[i+1] differs)

    1. a[i] is a prefix of a[i+1] — Great! We don't have to do anything, a[i] < a[i+1] is always true.

    2. a[i+1] is a prefix of a[i] — Great! Now we are screwed! The door is always locked.

    3. a[i] is currently lexigographical smaller thatn a[i+1] — Then calculate when will a[i] and a[i+1] go through the cyclic shift at j. During the period where a[i+1] has gone through the cycle and a[i] haven't, a[i+1] will be smaller than a[i].

    4. the reverse of case 3 — We will also calculate the cyclic shift time. This time, only the period where a[i] has gone through the cyclic and a[i] haven't will allow us to open the door.

    You can see that there will be intervals where you can open (or not open) the doors. Now all you have to do is check for the earliest moment where you can open the door.

    (You can use the range fill technique to invalidate a time interval. See my code here http://codeforces.com/contest/731/submission/21498917 )

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

      Can u please elaborate the last part of your solution. Means how you are using the chk[] array to check for intervals where we can shift the lock ??

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

        Let's say we are counting the amount of intervals at a certain point. The most naive solution is to increament each of the points within the interval by one — but this takes O(n) time to mark each interval.

        Instead, we can increase the start of the interval by one, and the point near to its' end of it by one, and calculate the prefix sum after we have mark all intervals, and this will tell us how many intervals lie on a certain point. Why does this work? Consider each interval individually, the prefix sum will cause all points on interval [left,right] increase by one, yet since [right+1] has a value -1, therefore it gets canceled and the interval [right,n) remains uneffected.

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

mfw practicing and see F only have the "brute force" tag.

 Dude What

nvm they fixed it. =]

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

I liked how none of the problems used complex data structure and algorithms.

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

quite surprised about the AC number of each problem.
I think E is quite easy, the idea is easy and very easy coding.
D is a little complicated to code, but the idea isn't hard.

F is hard for me, I didn't figure out a way by myself even after contest.

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

I hope for an editorial for this contest, as well as for Technocup.

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

plz upload the editorial!!!

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

I Can't get What is wrong on my solution... Solution I get Pretest Passed at 1:59.. but failed to pass Main test at Test22.

Please Let me know Why my solution is not working on this test case like 19999 10001 10002 10003 10004 ...

I solved The Problem F bruteforce. 1. sort input 2. from the small number to large number in the input, vec[1...n], Iterated if the mainpower key is v[i], if v[j] % v[i] == 0, pass. or not, v[j] -= v[j]%v[i] ( to make secondary power) 3. print the answer

  • »
    »
    8 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится
    200000
    100001 100002 ... 101000 200000 200000 ... 200000
    

    The answer is 200000 * 199000

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

    You should say, "I submitted The Problem F bruteforce" instead of saying, "I solved The Problem F bruteforce", since all of your submissions for F got WA!

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

i think there maybe some mistakes of problem F. the two same codes, the first code, define maxn=1000100,it AC;21510847. the second code, define maxn=200100,it WR on31;21510692.

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

21506585 — > What is my off by one error? :(

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

Could anyone comment the Problem E example 2?

input: 1 -7 -2 3
a)
turn 1: A takes 1 -7 -2, puts -8
turn 2: B takes -8 3
totals: A - B = (1 -7 -2) - (-8 + 3) = -3
b)
turn 1: A takes 1 -7, puts -6
turn 2: B takes -6 -2 3
totals: A - B = (1 -7) - (-6 -2 + 3) = -1

Why (a) is corrent answer? (b) is better than (a)!
  • »
    »
    8 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    B is not playing optimally in b)

    turn 1: A takes 1 -7, puts -6

    turn 2: B takes -6 -2, puts -8

    turn 3: A takes -8 3, puts -5

    A's score: -6 + -5 = -11

    B's score: -8

    diff = -11 — -8 = -3

    Sometimes you can force a turn on others and thus reducing their scores. >=]

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    Could you dig a bit more please?
    Why -8 in (1) is considered "optimal" but -21000 in (2) is not?
    input 1: 1 -7 -2 3
    input 2: -6000 -5000 -4000 -3000 -2000 -1000
    
    • »
      »
      »
      8 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      optimal moves for input2:

      turn 1: A takes [1,5], S= -20000. turn 2: B takes [1,2], S= -21000.

      Difference in score= +1000

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

When will the editorials be up!?

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

Where is the tutorial?

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

@Zlobober Please add tutorial to the box names [→ Contest materials] on the righ_bottom of web-pages of the problems. Thank you.