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

Автор qoo2p5, история, 7 лет назад, По-русски
Задача A. Кнопочные гонки
Задача B. Число на доске
Задача C. Звёздное небо
Задача D. Палиндромная характеристика
Задача E. Игра пингвина
Задача F. Дороги в королевстве
Разбор задач Codeforces Round 427 (Div. 2)
  • Проголосовать: нравится
  • +120
  • Проголосовать: не нравится

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

I did a O(nclogX + QlogX) solution for problem C. Where X is the maximum coordinate. Answering each query in O(log X).

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

del

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

For problem C ,what I am doing is storing the cummlative sum of the value of all stars in a row x upto y at time instant t as cum[x][y][t] for all t<=10 and then for each query I am running a loop for i= x1 to x2 and adding cum[i][y2][t]-cum[i][y1-1][t] to the answer where t=t mod (c+1) .I am getting WA.Can anyone please help? code link : http://codeforces.com/contest/835/submission/29068753

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

Hi! In problem C I tried to do a Brute force solution with some optimization but getting WA for TEST 3. Can someone please look at my code. http://codeforces.com/contest/835/submission/29078375

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

    You must have ignored the possibility of having two or more star at one point.

    See carefully constraint for number of stars (10^5) is more than the grid (100*100)

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

Does this mean that the right half of abba is actually ab not ba? I was solving it as if the right half was ba.

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

    It is ba.

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

      I had a huge thing misunderstood during the contest, thanks for clarifying.

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

      So the condition was supposed to be "the left half is the reverse of the right half"? or am I understanding something wrong?

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

        I don't think you're right. In the statement: "Its left half equals to its right half", and this is the tricky part.

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

        No, it wasn't. But we can prove that it is.

        Let's prove that k-palindrome (k >= 1) is palindrome. k = 1 is by definition. k >= 2: s = t + c + t, where t is (k — 1)-palindrome and c is some character or empty string. s is k-palindrome. So, t is (k — 1) palindrome. And we know that t is palindrome. So, reversed(t) = t. And s = t + c + reversed(t) and it is palindrome.

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

Yeah the editorials for even other contests should be posted fast like this one! :)

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

Sorry for my poor English:) Can anyone explain problem B, forth test, i tried to think on it but my answer is also wrong, help me!!! UPD: I FINNALY UNDERSTOOD MY MISTAKE :D

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

Hello!For problem C.I looked through questions of contestants and my question is quite similar to those. I just can't understand why i got WA on 3 Test. I took into account case, when stars are in one spot, but it didn't help me. It will great help to me if someone will find bug in my code: http://codeforces.com/contest/835/submission/29064634

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

Задачу D можно решить с помощью рекурсии с запоминанием, вот код: http://codeforces.com/contest/835/submission/29073244

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

For problem C, what I did was storing the brightness of stars in the array and accumulating the (brightness + t) % (maxBrightness+1) inside a given rectangle. Suppose maximum brightness is 4 and the query is (1,1,1,2,2).
The brightness of stars are stored in a following manner:
0 0 0 0
0 1 2 0
0 0 0 0

I am checking from (1,1) to (2,2) and and it produces: (1+a[1][1]) % 4 + (1+ a[2][1]) % 4 = 3 What seems to be a prolbem?

I would appreciate if someone point out the logical defect on the idea. http://codeforces.com/contest/835/submission/29073973

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

    There can be multiple stars at a point. Also, it seems that you are looping through the rectangle of each view, which might be too many operations to fit in the time limit.

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

In D we should make m = [(l+r)/2]-1 only if length of substring is odd, otherwise m= [(l+r)/2]; By the way, how to use special symbols? like [ ]?

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

For problem C,I have a question:why sorting x and y,then lowbound and upperbound their rang ,but test3 was so strong,that I can't find my error..I need help http://codeforces.com/contest/835/submission/29072180

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

Can someone explain what is bad with input/output in my solution of E?29084972

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

    You need to flush the output every time you print. Some languages back up all printing operations into a buffer until there's enough (because printing takes time, so printing a single large string is faster than many small strings). This makes the grader to not be able to see your output; flushing forces the language to actually print it out to the output no matter whether the buffer is full or not. It's also written in the problem statement.

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

      Nope, it doesnt help (in java println workes like flust). I tried to use flush after every print and only after printlns, nothing helps. I dont get where is mb mistake...

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

Proof that 19 questions is necessary for E:

At the worst case, n = 1000, so there are possible answers. You need to find the single correct answer. Each question you ask will give 2 possibilities, so k questions will give 2k possibilities. Of course, you need 2k ≥ 499500, otherwise some answers to the questions will have lump multiple possibilities together. Thus k ≥ 19.

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

For Problem D, I found a simple solution using Palindromic Tree, which runs in O(|s|) time and uses only O(|s|) memory.29085544

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

    In fact I found this problem quite similar to another Codechef problem Here, but in this problem the range of |s| is much smaller.

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

    Do you mind explaining your panlindromic tree solution?

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

      It's hard to explain the whole idea of palindromic tree here, this tutorial may be useful.

      First let's define the palindromeness of a palindrome S as the maximum k that S is k-palindrome. In this problem, actually we need to calculate the palindromeness and the number of occurrences for each palindrome.

      The second problem is a basic application of palindromic tree which can be found in the blog above. To deal with the second one, for each palindrome S we need to know the longest palindrome prefix P whose length doesn't exceed , the palindromeness of S equals to the palindromeness of P + 1 if . It equals to 1 otherwise.

      So the only remaining problem is to find P for each palindrome. And it's easy to cope with that with similar method of calculating the longest prefix palindrome. You can take a look at my code (where half[S] presents P) for more details.

      Sorry for my poor English, hope you can get what I mean.

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

I know my code for D is not very efficient, but after testing 5000 'a's in custom test and it runs under 2800ms, I decided to submit it. But it gets TLE on test 30. However I submitted the exact same code after contest it passed. Does anyone knows the reason? Thanks.

Code in contest: 29067565 Code after contest: 29086375

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

Here is a trap in Problem C: There maybe two stars with the same pos! I got WA for many times because of this!

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

I was wondering if problem C could be done using convex hull? Can somebody please explain why not and if yes then how.

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

    Your queries are rectangles so it doesn't make any sense to use convex hull.

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

D можно решить с O(|s|) по памяти и O(|s|2) по времени хешами

29093349

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

    Хэши в этой задаче совсем не нужны. Все предпосчёты, если они вам нужны, можно сделать за O(|s|2).

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

Looking For recursive solution For Problem D..

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

For problem D, would anyone like to prove OBS1? i know it's kind of obvious but i still wonder why :L

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

    I explained it this way: divide our palindrome into 2 halves, while they are identical, i.e. abacaba <- aba <- a. Length of this chain is k, every member in it can be represented as 1-palindrome, so our initial string can be [1..k]-palindrome. (if we assign aba as 1-palindrome, abacaba would be 2-palindrome, if we assign a as 1-palindrome, abacaba would be 3-palindrome)

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

    By induction, just assume that for any n <= k, n-palindrome is a 1-palindrome, then prove it for n = k + 1. So, let's take (k + 1)-palindrome, left and right halves of it must be same k-palindromes, which are 1-palindromes by our inductive assumption, thus the whole (k + 1)-palindrome is also 1-palindrome.

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

      but whole k + 1 palindrome is also 1 palindrome doesn't prove k palindrome is k - 1 straightforwardly,right?

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

        Oh, sorry, I incorrectly understood OBS1, my bad:)

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

        Ok then, just change the assumption, now by the assumption for any 1 < n <= k n-palindrome is (n — 1)-palindrome, too. The prove will be the same, the only thing to deal with is the base case for k = 2.

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

    We can prove by induction on k

    Theorem: if s is k-palindrome, s is also (k — 1) palindrome, k > 1, |s| > 1.

    Case |s| = 1, it's 1-palindrome = palindrome, since there's no definition of a 0-palindrome, there's nothing to prove.

    Base case for induction: k = 2.

    If s is 2-palindrome, s can be written as s' + c + s', s' is 1-palindrome, c is some character, possibly the empty character. Since s' is palindrome, s' + c + s' is also a palindrome, so every string which is 2-palindrome is also a 1-palindrome.

    Induction hypothesis: Every string s which is k-palindrome is also (k — 1) palindrome, |s| > 1, |k| > 2. The hypothesis is recursive until k = 2.

    s is k-palindrome so it can be written as [k — 1] + c + [k — 1], where [x] denotes some string which is x-palindrome.

    Induction step: Let t be a (k + 1)-palindrome string.

    t = [k] + c + [k], c is some character, possibly the empty character (check above the meaning of the [k] notation). Our induction hypothesis says that a string [k] is also (k — 1)-palindrome, so we can replace [k] by [k — 1], so:

    t = [k] + c + [k]

    t = [k — 1] + c + [k — 1]

    A string is k-palindrome if can be written as [k — 1] + c + [k — 1], we just wrote t as this way so t is k-palindrome and the induction is finished.

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

In Problem D,I thought of the solution above. However, I am afraid of the time limit because dp costs O(|s|^2) time and we must compare the string to make sure it's a palindrome, so I think the time is more than O(|s|^2), is this true?

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

    After understanding the solution c++ code,I understand. Just ignore,please. I can use the result before to decrease much time complexity.

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

I do not understand the description of problem D clearly.

how is the answer for 2nd sample test case calculated? abacaba => 12 4 1 0 0 0 0

thanks in advance :)

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

    If a string is K-palindromic it will be (K-1)-palindromic as well. That means that for a[1] = 12 we count every possible palindromic string. You can check that there are exist 12 palindromic strings. a[3] = 1 because only abacaba is 3-palindromic string. a[2] = 4, because {aba, aca, aba(2nd time)} are palindromic string but don't forget to add {abacaba} as well because it is 3-palindromic so it is 2-palindromic too. So a simple solution is to find the a[i] table and after do that operation a[i-1] += a[i].

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

Problem E

It can be proven that in the given constraints you can't solve this problem in less than 19 questions.

Really interested to know how to prove such a lower bound! :D

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

In problem D, why hashing TLE? I think the complexity of my solution is O(n^2 * log(n)) which is very small (correct me if I'm wrong) .

My submission: http://codeforces.com/contest/835/submission/29868893

Can anyone help me?

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

    Hashes are slow. The constant factor of your solution is too large.

    The intended solution is O(n2) and you don't need hashing in it.

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

Can anyone please see my code for problem C? I am getting TLE on test 8. This is my code Please help me.

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

Problem F has almost exactly the same model as CF-515-E, and can be easily cheesed using a segment tree.

https://codeforces.com/contest/835/submission/197225410

(note to self: write explanation later)