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

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

985A - Расстановка шахмат

Разбор
Решение (Vovuh)

985B - Переключатели и лампы

Разбор
Решение (Vovuh)

985C - Бочки Либиха

Разбор
Решение (adedalic)

985D - Замок из песка

Разбор
Решение (PikMike)

985E - Коробки с карандашами

Разбор
Решение (PikMike)

985F - Изоморфные строки

Разбор
Решение (adedalic)

985G - Командные игроки

Разбор
Решение (adedalic)
  • Проголосовать: нравится
  • +80
  • Проголосовать: не нравится

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

Okay, formulas got better.

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

In problem D, for n=5,H=2, why is [2,3] wrong? I seem to be missing something here

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

Problem D binary search on h the height becomes h,h-1,h-2...2,1,0 and if h>H make it becomes H and change the height on the right too. if H=5 There are two case: 1. [9,8,7,6,5,4,3,2,1,0][ 5,6,7,6,5,4,3,2,1,0] Sum=(9+1)*9/2-(4+2+0...) 2. [8,7,6,5,4,3,2,1,0][5,6,6,5,4,3,2,1,0] Sum=(8+1)*8/2-(3+1+0..) find the smallest h that sum>=n Note: 1+3+..n=[(n+1)/2]^2=tmp 2+4+..n=tmp+n east to calculate

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

Can you please explain this- "Otherwise, for each i from 1 to n let's take no more than k smallest staves from this segment in the i-th barrel, but in such way, that there are at least n - i staves left for next barrels."

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

    Every barrel will have atleast one stave from the range [1,rg) otherwise there will be two barrels whose volume difference will be greater than l.

    So for each barrel i from 1 to n, start picking up the staves (smallest first) from [1,rg) until you reach the required number of staves (k) or if there there are fewer than n-i staves left in the range [1,rg) because you still need to build n-i barrels and each of these needs atleast one stave from this range

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

Correct me if I am wrong.

In the first example for problem C:

4 2 1

2 2 1 2 3 2 2 3

Isn't [1, 2], [2, 2], [2, 2], [3, 3] a valid solution with answer 8?

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

How the solution for 985A works? what principal/logic is this? I'm struggling to understand.

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

    You have to first sort the positions of the pieces because in one move you can either move left or right. We need to sort the positions to get optimal answer. Now the there are N positions and N/2 pieces. These N/2 pieces can be on black position or on white position since we need to place them in same color. Black positions are odd numbers till N and white pieces are even numbers till N (BWBWBW....BW) . Now the number of steps required by each piece is the absolute difference of required position where it should be and initial position of the piece given in the array. Thats what they have done for N/2 pieces. They are taking the minimum steps when placing in white position and black position.

    My Code : http://codeforces.com/contest/985/submission/38496335

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

In author solution of problem F, is the mt19337 random generator unpredictable enough?

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

    If a seed of generator is fixed, any random generator will generate same sequence every time. So it is necessary to set a seed with diffenent values.

    On the other hand, as author, I would like to have a deterministic solution which will not depend on time it was started.

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

      I guess it is OK to use hash without unpredictable random in author solution (if the hash is strong enough, like the 8-modulo hash in author solution for F). No one beside author can see the solution and generate the anti-hash testcase until the end of the hacking phase.

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

i dont understanf why i am getting TLE in problem C my code

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

    Java's inbuilt Arrays.sort() uses a double pivot quick-sort whose worst case is O(n^2), So, it can be hacked by a testcase specially designed to break it. Some O(nlogn) sort like Merge sort or heap sort could be used or radix sort. You can also add a random shuffle before Arrays.sort or use Integer instead of int so that java's inbuilt Arrays.sort() over Objects(timsort) will be used.
    TLE with Arrays.sort()-38492535
    AC with Arrays.sort() over Integer- 38524250

    My Java solution also TLEd due to same reason :(

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

      thanxx man, got it!!! and does it only happen in educational rounds or in normal rounds we should take care of Arrays.sort()

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

        Usually normal rounds are of small length, so this kind of hacks rarely happen. But creating a custom sort function which first randomly shuffles the array and then sorts or some other sort should be on the safer side.

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

Can Somebody explain DP part of Solution E

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

    Same question xD

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

    Also, Necrozma

    Maybe the code of O(n2) solution will help a bit more?

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

      Hey, by checking i+1-j>=k, you basically check if i and j can be taken in a segment, what if the jth is already taken in some previous segment and taking i,j together "disturbs" it?

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

        You update from dpj and that is the state for the first j elements being distributed. j-th element is the first one not taken.

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

can anybody help in understanding div 2 C,i havent got the idea n-i stacks to be left for each i??

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

    First, sort array in non-decreasing order.

    We must have a barrel which contains a1 stave. So each maximal total sum of volumes of barrel cannot be larger than a1 + l

    let C = (number of stave which has length  ≤ a1 + l) - N.

    If C < 0, then answer is 0.

    Otherwise, While picking staves, if C > 0, pick the smallest stave you have, and decrease C by 1. else, pick the largest stave you have.

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

How to solve F with LCP?

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

awoo, Can u give me any practice problem link similar to DP involved in Problem E?
P.S : I am new to DP.

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

    Huh, you know, this is such a basic dp usage. No particular problem comes to my head. I can recommend to search some dp trains on e-olymp, they have lots of great contests on certain topics.

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

В задаче B дано условие: "В следующих n строках содержится по m символов. ai, j равно '1', если i-й переключатель включает j-ю лампу и '0' в противном случае". И дан тест(номер 4): 2000 2000 10110011000101110100100110001011001000000100011010011110100101001101011110010001100110101011101100000110000001001010100001011010101000011010110001111011010010000111100101100100000011100001001000011100100010101001011111100111000110100000100111100001110010011101111001101111100110100001011001010111101001111111100000000010101011010011010010001111011110111100010101010110111100000001101011111011101010110111001110010001111010110001101111001011011011100100111111010111011101100000010001010110100010100010... Я не вижу здесь 2000 строк. Я не прав?

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

    Так как размер входных данных слишком большой(2000 строк), они поставили в конце "..."

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

Well it is annoying that the third problem WA on test 13

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

После несколько дней без результативное попытка, наконецто решил задача G.

Почитал разбор задач 100 раз !!!

38612482

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

По задаче F, если я правильно понял, хэши ускоряют получение ответа "No". Но как быть с ответами "Yes"? Совпадение первых встречаний, очевидно, не достаточное условие. Извините, в код лезть не стал)

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

    Там не хэш сравнивается, а сравнивается пара (cnt, hash) для каждого символов. где cnt — это кол.во вхождение символ в интервал, а hash — это его хэш сумма в этом интервале.

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

    Первые встречания используются только для установки изоморфизма между алфавитами подстрок. Хэшами же проверяются совпадение всех вхождений в подстроку соответствующих букв.

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

in problem F. More over, if we sort all positions posis for all distict characters in s and sort all positions posjt for t, then posis must be equal posit for any i.

can someone expalain this?

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

    If both strings are isomorphic, then the first occurrence of character X in S MUST be the first occurrence of some character Y in T.

    So if you sort the positions of first occurrences of distinct letters for S and T, they will be exactly same (only if they are isomorphic, also the reverse might not be true).

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

About problem 985E — Pencils and Boxes. I was thinking about proof. For "YES" condition its fairly simple. But what about "NO". Can'nt we get other segments. other than what is describe by DP solution.

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

    Usually, there is next idea behind this type of task: (solution exists)  →  (author solution finds answer) !(author solution finds answer)  →  !(solution exists).

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

Another approach in problem E is to first sort the whole array. My approach- https://codeforces.com/contest/985/submission/54277798 Now start from back, I am using 0 based indexing, now mem[j] stores if from index j, I can have a soln. or not. Base case is mem[n]=1 and mem[j] can be known as we need to know nearest location after k indexes from where mem[i]==1. or just look at my soln.- In my soln. mem[j] stores if from index j ican construct a soln. or not. nr[j] stores nearest index >=j where mem[i]==1.

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

can anyone please help me in A problem...how you come up with the idea of this formula

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

In second question if you enter 2x3 matrix 1 1 0 0 1 1 so answer will be yes or no ???

Tutorial's code give yes but answer will be no!!

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

Can someone explain to me how the O(n^2) solution is working in case of ProbE Pencils and Boxes? I am facing a lot of difficulty in understanding how the given solution is taking care of the constraint that every box contains at least k elements.

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

I have an alternate (simpler?) solution to $$$Problem D$$$: we binary search over the answer:

Can $$$x$$$ be the answer? First, notice monotonicity of this boolean upto $$$x \leq n$$$. Now, lets fill up the range with maximum possible stones (can be found by easy math). It will be obviously of the form $$$h_1 ≤ h_2 ≤ ... ≤ h_k ≥ ...\geq1=h_x$$$. If the sum of $$$h_i$$$ is less than $$$n$$$, obviously NO $$$x$$$ can't be the answer. Otherwise, we prove by construction, that it is.

For while $$$n$$$ is less than sum, decrease the sum by $$$1$$$ by removing one from the height of the greatest pile. It obviously maintains the invariant $$$|h_i-h_{i+1}|\leq1$$$.

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

My $$$\mathcal{O} (N \log N A)$$$ TLEs. Interesting that authors made such tight constraints (easily fixable).