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

Всем привет!

Я рад пригласить вас на общий рейтинговый раунд Avito Code Challenge 2018, который состоится 27.05.2018 17:50 (Московское время). Задачи готовил я — Ильдар Гайнуллин.

Этот раунд проводится по инициативе и поддержке компании Avito. Avito — интернет-сайт для размещения объявлений о товарах и услугах от частных лиц и компаний, занимающий второе место в мире и первое в России среди онлайн-классифайдов.

Большое спасибо Владиславу winger Исенбаеву, Григорию vintage_Vlad_Makeev Резникову, Ивану isaf27 Сафонову,Александру AlexFetisov Фетисову и Shiqing cyand1317 Lyu за тестирование, Николаю KAN Калинину за помощь в подготовке раунда, а также Михаилу MikeMirzayanov Мирзаянову за системы Codeforces и Polygon.

Участникам будет предложено восемь задач и три часа на их решение. Разбалловка будет объявлена ближе к началу раунда.

Компанией Avito предоставлены подарки для участников ---- 30 лучших участников и 10 случайных с местами от 31 до 130 получат футболки.

Надюсь, каждый найдет для себя интересную задачу. Всем успешного раунда и повышения в рейтинге!

Удачи!

UPD,Разбалловка: 500 750 1250 1750 2250 2750 3250 3750

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

1) tourist

2) EvenImage

3) Radewoosh

4) Endagorion

5) Um_nik

Разбор задач

Обладателями случайных футболок становятся:

List place Contest Rank Name
6 981 36 snuke
31 981 61 Swistakk
40 981 70 yasugongshang
52 981 82 Xellos
62 981 92 shadowatyy
76 981 106 budalnik
80 981 110 kostka
88 981 118 pb0207
95 981 125 Noam527
96 981 126 xiaowuc1
  • Проголосовать: нравится
  • +565
  • Проголосовать: не нравится

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

For a moment there I thought it was "Aviato", you know, Erlich's company.

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

Таки кодефорсес подловил меня со временем. В течение десяти месяцев мне удавалось не пропускать рейтинговые раунды ценой прогулов, невнимательного слушания лекций/семинаров, посиделок в макдональдсе и на вокзалах, но в этот раз я ну никак не могу. Браво!

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

Will the difficulty of the problems be similar to other Codeforces Div1 & Div2 combined rounds?

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

is it rated?

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

I want t-shirt. But I think i could not have this rank

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

First Div 1+2+3 contest :D

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

Cricket lover's in dilemma..#IPL final

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

Guess I won't be watching the IPL final then...

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

when reading the Avito

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

T-shirts will be awarded for 130 from Div.1 + Div.2?

Give Div.2 a chance :'(

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

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

Will participants be able to do challenges(hacks)?

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

Yaa We will be there

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

Div1+Div2+Div3 contests at one time(8 problems) Yeah!!

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

Karuis is looser, how it is possible!!!!!!!!!!!!!

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

TIM_20180527081322

?

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

Рейтинги авторов раунда так и манят написать этот контест.

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

How many questions will there be?

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

T-shirts from Avito or from Codeforces?

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

Странная ошибка в русской версии анонса (

UPD: Исправлено

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

The random t-shirts will be selected as usual with the help of two scripts below and random from testlib.h. Seed is the score of the winner in the upcoming Codeforces Round 485 (Div. 1), the length is the number of participants between the 31-th and the 130-th places inclusive.

python code
c++ code
»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -6 Проголосовать: не нравится
»
8 лет назад, скрыть # |
 
Проголосовать: нравится +87 Проголосовать: не нравится

Delayed by 15 minutes :v

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

what's the problem codeforces every round we get delay of 10-15 mins. at the last moment? :v

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

Everybody now can watch IPL final for 10 minutes :)

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

.

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

I do not participate in the contest but I discovered that the point decrement speed is not adjusted?

This way a problem will only worth 28% of original score at the end of contest.

Edit: just saw the announcement

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

That's quite a lot of pretests. I like it (if they aren't mostly trash).

Not like I expect at least my F to pass, though.

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

Как решить D?

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

    Я решал так:

    1) посчитаем все возможные суммы на подотрезках и сохраним их в массив

    2) В цикле идем от максимальной степени двойки (2^63) к минимальной (2^0), на каждой итерации находим все суммы, побитовое и для которых с текущей степенью двойки не равняется нулю.

    3) Если из выбранных сумм можно получить весь отрезок 1..n тогда прибавляем к ответу текущую степень двойки, и удаляем из массива сумм те суммы, побитовое и которых равнялось 0.

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

In D why is this approach wrong? (Wa on test 5)

I have dp[begin][end][cuts]

and if cut is 0 it is just the sum of begin to end

Else i can cut it at any of the location from begin to end and see the cuts from begin to cut_position and cut_position + 1 to end.

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

    There is no guarantee that when choosing to cut at some point, the optimal AND value is obtained by the maximum possible values for the resulting two subarrays. Consider the pairs [5,5] and [5,2]. [5,2] gives us a better AND value (7), but your solution would choose [5,5].

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

      How to solve D?

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

        I did a bruteforcey solution with recursion every time I switch to a new bookshelf. With a few optimizations it passed in the time limit. (Mainly, don't recurse if the AND so far is less than the best cost you've seen so far) Update: Test case #61 begs to differ, got TLE

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

        Start from the 55th bit, let now be 0. If you can get and value equal to now + 2^i, add 2^i to now. It can be done with easy dp.

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

        Find the answer bit by bit. Start with answer equal to zero. Then for i from 60 to 0, check if you can obtain a solution with answer + 2i. If you can, just add.

        Checking if there is a solution with a fixed answer can by done with dp[position][parts]. To compute a state, try to fix a new position and consider dp[newposition][parts + 1] if the sum in the interval [position;newposition] contains the bits of the fixed value as a subset, in other words (sum&FixedValue) = FixedValue.

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

        What I did:

        set<long long> dp[i][j] = The set of possible values obtainable when books are put into first i shelves, where first j books are used.

        It is trivial to show that in first i shelves, there should be i books in minimum and i+n-k books in maximum, and so the dp array is only valid in such range. A complete dp[i][j] can be computed by [all values in dp[i-1][i-1~j-1]] & [appropriate range sum of input array].

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

    you got 1000 & 0100 < 0111 & 0001, when both 1000 > 0111 and 0100 > 0001

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

I think G is too easy to be 3250.

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

Can someone explain how to solve E?

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

Can someone, please, explain how is updating the current set of active segments done in E? I couldn't reduce the complexity from O(Q2 * N / 64) for the whole second half of the contest. Or is the intended solution completely different?

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

How to solve G?

I tried to do it with O(n log(n)^2) segment tree beats but got TLE'd (pretest 15). Is there a better way?

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

    I don't remember what segment tree beats are (other than that the name evokes someone beating a segment tree with a stick), but my solution was keeping sets for all intervals containing x for each x, using it to extract intervals of multisets to multiply by 2 and intervals of multisets to add 1 to; these 2 types of queries (+ get sum) can be handled with a fairly normal lazy segment tree. since there are only O(Q) intervals to update.

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

How to Solve 3rd Question , Tree Decomposition .

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

jtnydv25, name is enough to understand who is he?

one of my most favourite coder...

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

Why do tasks on Codeforces have to be like this http://mirror.codeforces.com/contest/981/problem/G and this http://mirror.codeforces.com/contest/981/problem/H instead of like this https://agc024.contest.atcoder.jp/tasks/agc024_e and this https://agc024.contest.atcoder.jp/tasks/agc024_f >_>? Kinda obvious what to do more or less and then codecodecodecodecodecodecodecodecodecodecodecodecodecodecode and carefully work out details

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

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

Love these statements

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

Simple O(N2) solution to A is pretty cute. I don't know why author gave N <= 50 and ruined the fun :p

And I really liked problem F. thanks to authors!

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

Is it really necessary to have 130+ tests for A?

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

What kind of pretests are these XD?

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

How to solve F? First binary search, then reduced it to some matching problem with circular segment, then what?

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

    I solved it by using Hall's theorem. Check segment instead of subset is enough!

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

    Here's a more detailed editorial: binary search on the answer. For each bi, expand it to an interval ci = [bi - x, bi + x]. Now we need to see if there's a matching between the ai and these intervals ci where a point and an interval can be matched if the interval contains that point.

    If this were a line, it would be easy: sweep through the intervals left to right, pick the first point in the interval. However, we're on a circle, so intervals that cross the origin are tricky. To simplify it, "unroll" the line and double it. If an interval was originally [l, r] with l ≤ r, then add intervals [l, r] and [l + L, r + L]. Otherwise, just add the single interval. Now we have at most 2n points and intervals and run the linear matching algorithm as described above. Hall's theorem tells us that this unrolling is equivalent to a matching on the circle.

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

      Thanks for the details! I don't really get why Hall's theorem says that the unrolling is equivalent. Could you elaborate?

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

        Sure.

        Initially, we have two sets of length n, A = {a1, a2, ..., an} and B = {b1, b2, ... bn}. Now when we do this unrolling process, we get two new sets A' = {a'1, a'2, ... a'n, a'n + 1, ... a2n} and C = {c1, c2, ..., cm} where a'i = ai%n and ci = [bi - x, bi + x]. Note that we use m instead of n because bi might map to two ci. n ≤ m ≤ 2n.

        We have a perfect matching between A' and C. Let's apply Hall's theorem. Consider some set S', which is a subset of these a'i. Then because we have a matching, |S'| ≤ |N(S')|, where N(S') is the set of ci that are connected to some node in S'.

        Now, to prove that there's a perfect matching between A and B, we use Hall's theorem in the other direction. Choose some subset of nodes in A, call it S. Then what is |N(S)|? Let's define S' as a subset of A' having BOTH copies of ai for every ai in A. Then we know by the previous paragraph that |S'| ≤ |N(S')|. Since 2|S| = |S'| and 2|N(S)| ≥ |N(S')|:

        |S| ≤ |N(S)|, so there's a matching in the original graph.

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

          I think it's wrong proof.

          1) Forget about the case, when |C| = 2 × n, because in this case there are no intervals, that crossing the origin and this case can be easily solved, as mention above.

          2) But if you have at least one crossing the origin interval, that it means, that |C| = m < 2 × n. After that you are not able to have perfect matching, because the sizes of components are different.

          3) So, I suppose you want to say, that you have the matching, where one part is covered by matching full. But again you told: "Consider some set S', which is a subset of these a'i. Then because we have a matching, |S'| ≤ |N(S')|, where N(S') is the set of ci that are connected to some node in S'.". If you take S' = A', than you have: , but , contradiction.

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

For ques B

Is this a valid test case ?

4
1 10 
2 6
3 5
4 2
4
1 1
2 2
3 7
4 8

If yes

what is the answer for this test case

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

modulo 998244353

I see this line and I feel sick. I see this line in two problems and I want to leave competitive programming for another year.

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

    I guess H is FFT problem so author wants to hidden it by letting that modulo in G :)

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

    On contrary, I always pay respect to problemsetters who put this modulo in their problems. By putting it in problems where any modulo is sufficient we obfuscate which problems need FFT.

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

      I think giving 109 + 7 in every single problem, including FFT ones is better way to obfuscate it. No one should use NTT anyway.

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

        Giving 109 + 7 makes it harder to give larger constraints like 105

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

          Then the model solution just sucks, author should come up with better algorithm.

          I don’t understand how can mod 998244353 ever be a good idea. The author requires large constant factor to solve the original problem, and to overcome it they use some peculiar modulos that is known to be useful for a limited number of audiences. For someone to easily solve that problem, they should knew that “magic number” beforehand, and the fact that they have good primitive roots. Sounds pretty bad to me.

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

          I doubt that. Splitting numbers in two groups is still faster than making computations modulo some number. And it works for every mod.

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

            Karatsuba works for every mod, doesn't need too many modulo operations, has a nice constant, works exactly (no doubles) and if the use of FFT is complex enough — the problem isn't just reduced to a single FFT or one of garden variety D&C+FFT versions — the constraints are often long enough that Karatsuba can pass. Its only disadvantage is asymptotic complexity. Actually, even D&C+Karatsuba has complexity equal to Karatsuba only.

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

            I disagree. Modulo is faster than splitting and then doing computations on pairs of doubles.

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

        I don't like problems that require FFT with 109 + 7 modulo. Why is it better? Only because simple fractions like looks nicer? Not a big argument.

        NTT has much shorter code, which is important in ACM-style contests, where you don't have any prewritten code, and it works absolutely with same speed. When I tested FFT vs NTT, difference in execution time was about 20%, and one of them was faster on G++, and another was faster on mingw, so they are absolutely equal in my opinion (only FFT requires slightly more memory, which can be critical in some cases).

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

I saw a possibly incorrect submission (see 38668742) for 981D - Bookshelves, while I have no idea how to hack it during the contest time.

The solution is simple, for dp[index][count], maintain the top 20 bitwise-and sum that ends at index with count blocks. It seems true to me that there exist cases which fail this solution(cases which you need some smaller and-sum in the middle-way).

So, can anyone suggest a way to generate the hack? Or there are some ways to prove that this solution is indeed correct?

PS. I hope these kind of submissions will fail systest... I mean, I hope the systests are strong :D

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

Can someone explane me how I got WA on test 5 in final testing and someone got WA on test 13 during the contest ?

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

Где разбор?!

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

What can be the cause of Wrong Answer for this solution of D ? Link:

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

Can someone help me find bug in my code question D.

http://mirror.codeforces.com/contest/981/submission/38676475

for every possible index idx, and count c I chose a perfect j to maximise the bitwise and sum and forming k subset.

Please help coders....

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

I have no idea about the complexity of my solution for G. Only that is not bigger than O(n * q)

Link

But I got AC))

I have one main segment tree for calculating the answer and also store additional segment trees for each of the values 'x'.

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

Hi everyone.

For problem D , Initially I read like, we can divide 'K' subsets in any order. (Not necessarily contiguous segments of array) .

Is it really possible to solve it ?

In last 25 minutes I read it again, and figured out Greedy-DP solution. which seems like HACK to me. And still the solution passed. I was hoping this solution to fail. Can someone tell me, is it possible to hack this solution ?

Basically I am picking up best 8000 values for each dp[i][j] , where 'i' is index, and 'j' is number of shelf's being used till index 'i'.

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

Крутой контест! Классные задачи

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

I enjoyed the problems, even if I didn't well. Thanks to the author.

Out of curiosity, am I the only one who found problem C easier to understand by translating the Russian version to English with Google Translate?

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

How to solve problem F?

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

No test cases with 1<k<n-1 for H? Top two both fail with such k...

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

can some one suggest whats wrong in this code for D, thanks in advance ~~~~~

include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll dp[55][55];

ll ar[55]; const ll inf=(1LL<<60)-1;

int n,m;

ll foo(int i,int j)

{

if(j>m)

return 0;

if(i==n)
{
   if(j==m) 

   return inf;

   else

    return 0;
}
if(dp[i][j]!=-1)

return dp[i][j];

ll p=0;

ll ret=0;

for(int k=i;k<n;k++)
{
    p+=ar[k];

    ret=max(ret,(p&foo(k+1,j+1)));
}
return dp[i][j]=ret;

}

int main() {

memset(dp,-1,sizeof(dp));
cin>>n>>m;
for(int i=0;i<n;i++)
{
    cin>>ar[i];
}
cout<<foo(0,0);

}

~~~~~

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

Your crafting.oj.uz ratings are updated!

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

Will there be editorial for this contest?

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

Can anybody please explain their approach for problem D.

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

    A observation first: We will see if we can obtain in the final sum, every bit from 60 to 0. (We must find some configuration such that every shelf contains in the sum of the values that bit)
    If we can obtain a bit, then we add it to the answer, and when we try for a new bit, we always respect the bits that are already found.

    I have solved it using dynamic programming dp[i][j][h] -> true or false, if we can put the first i books into j shelves such that each shelve has the bit h in its sum. (And also respects all the higher bits found previously)

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

      I am not clear with this part "And also respects all the higher bits found previously" Can you please explain what do you mean by this line

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

        Let's say for example that you are at bit 5, and you know that you have found good configurations that can have bits 8, 10 and 15. (The answer until now is 28 + 210 + 215). When computing dp[i][j][5] we have to find some index i2 (smaller than i) such that sum(i2, i) contains 25 + 28 + 210 + 215, and dp[i2][j - 1][5] is also true (which means that the first i2 books can be put in j-1 shelves such that their total sum contains 25 + 28 + 210 + 215)

        My code: 38668315

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

Where is editorial's link ??

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

Thanks for great contest!

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

How to solve H? Where's the solution?

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

How to solve D ? Cannot understand the approach listed in the comments

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

How about the Editorial????

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

Editorial ??

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

Hello

English editorial will be ready in 2-3 days, sorry for inconvenience, i am busy with some school exams now

Now you can translate russian version with some translator like yandex

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

When will the editorials be posted?

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

Does anyone have an editorial for the problems in this contest :(

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

Can anyone please help me find a mistake in my solution for D.

Here is what I did:

dp[s][e][j] — stores the maximum possible beauty of j shelves when they contain books from as to ae

if(j == 1)
     dp[s][e][j] = sum(a[i]) for i = s to e
else if(e-s+1 == j) means j books in j shelves
     dp[s][e][j] = bitwise and (a[i]) for i = s to e
else 
     dp[s][e][j] = max(sum(a[s]...a[i-1]) & dp[i][e][j-1]) for i = s+1 to e-j+2

The answer to the problem is dp[1][n][k]

Here is my code.

Thanks in Advance

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

    First,s = (s&a[i]);must be s = (s&a[j]);.

    Second,This test case:

    4 3 11 6 1 3

    Answer:3.Your output:0

    11&(6+1)&3=3.But in your solution,dp[2][4][2]=4.(6&(1+3)).

    It means that it not necessary to use the maximum value in[L,R].

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

    This problem is not greedy in that way you assume. dp[s][e][j] = max(sum & dp[i][e][j-1]) doesn't always hold.

    E.g. take a look at the following example. If you want to make two bookshelves using the books [7, 1, 12], then the best you can do is (7+1) & 12 = 8. However if you add a book [4, 7, 1, 12] and want to make three bookshelves, then the best you can do is 4 & 7 & (1 + 13) = 4. Here you have to take a smaller value for the subset [7, 1, 12], namely 7 & (1 + 12) = 5, to get a bigger end result. Because otherwise 4 & (7 + 1) & 12 = 0.

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

In China. The contest in provinces is called NOIp. And we have two tests. The first test is printed on papers and one part is to read a program and write what it outputs. And then when I was taking a mock test and doing the part. I see the following four lines of the code:


/** * author: tourist * created: 27.05.2018 18:26:43 **/