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

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

Привет, Codeforces!

Неожиданно для нас всех мы решили все-таки провести раунд на Codeforces.

Codeforces Round 402 (Div. 1) и Codeforces Round 402 (Div. 2) пройдут параллельно с Открытой олимпиадой Университета Иннополис для школьников по информатике, частично по задачам этой олимпиады. Раунд начнется в воскресенье 26 февраля в 11:05 по московскому времени.

Спасибо MikeMirzayanov, который добавил парочку троечку задач для контеста во втором дивизионе. Задачи подготовили: MikeMirzayanov, YakutovDmitriy, VArtem, FireZi, burakov28, pashka.

Надеемся порадовать вас задачами!

UPD:
разбалловка по задачам в div1: 500 — 1000 — 1500 — 2250 — 2250
разбалловка по задачам в div2: 500 — 1000 — 1000 — 1500 — 2000 — 2500

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

Топ-10 (Div. 1)

  1. bmerry
  2. ainta
  3. Marcin_smu
  4. kcm1700
  5. jqdai0815
  6. anta
  7. FizzyDavid
  8. Reyna
  9. dotorya
  10. gs12117

Топ-10 (Div. 2)

  1. Chiaki.Hoshinomori
  2. WhyamIhere
  3. 2021
  4. Schemtschik
  5. kiiiiii
  6. chakred_namor
  7. marcospaulo
  8. fushar
  9. safarisoul
  10. Panole233

Разбор тут.

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

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

Пересекается с Opencup GP of Wroclaw :(

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

    Причем это опенкап, которого не было в птз, его все будут писать.

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

too bad, I can't do this round :(

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

how many problemset sir ?

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

LOL!!

One problemsetter of each color

Now that's what I call justice

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

    there are two reds, no cyan, no green, no grey and no white

    Are you having Color Blindness :3

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

      there are one grandmaster, and one international grandmaster

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

        but it is the same color ;)

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

          only women can see the difference between these two colors.

          like this

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

            This makes no sense, "green-yellow" is the shade of green farthest from yellow here...

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

              You're still thinking in masculine color space.

              Feminine color space has three dimensions. It's like the transition from flatland to 3-space; impossible to imagine unless you already live there.

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

      VArtem is International Grandmaster and pashka is Grandmaster

      sorry man there's no thing called completely justice in this world :(

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

Do you mean Sunday, 26th?

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

Is there any reason that recently Codeforces Contests are announced in short time before contest start time?

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

    kind of a surprise :D

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

      It's not only surprise but also sad for me. The contest time is quite close to my training contest in group.

      In fact, I have moved the training contest time from Friday to Sunday because its original time overlap to CF #401...

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

Deleted

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

Nice time !

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

Wow! Another chance to get high rating! :3

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

I love it when there are contests on every 2-3 days. :)

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

It completely collides with Grand Prix of Wroclaw of OpenCup. Which one do you participate?

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

Why did codeforces start holding its contests at such an odd times? Earlier it was used to be around 16:00 UTC.

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

Why did codeforces start holding its contests at such an odd times? Earlier it was used to be around 16:00 UTC.

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

    Maybe because of this
    The round will run at the same time with Innopolis University Open, Olympiad in Informatics.

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

there is always a pole between you and things you love to do
this pole is my school :(
I'm not gonna participate in this round tomorrow

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

Five problems as usual ?

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

8:00 am GMT +6 is the best time!

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

Благо ко мне приходят уведомления с почты, иначе пропустил бы раунд...

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

Is it rated?

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

is it rated?

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

Is this the first time that the two divisions have different number of problems?

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

UPD : I didnt send that message,this guy send it with my account. I know that it is rated :D . pls stop down-voting me . my contribution was +3, but now -25 :'(

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

0.0

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

    cmp function must not return true on both cases cmp(a, b) and cmp(b, a).
    if cmp(a, b) = true then cmp(b, a) must be false.
    if cmp(b, a) = true then cmp(a, b) must be false
    but it is possible to return both false (which is mean that a is equal to b).

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

Hack for DIV — 2 B ???????

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

How to solve Div2D?

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

    Binary search

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

    I did Binary Search.

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

    can you explain a bit?

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

      You binary search on the number of elements to delete from the string (just mark the indices in a boolean array). Then, if the string I'm looking for is a subsequence of the original string with modified characters then it's possible for her to continue playing so I try a higher value. If it isn't a subsequence then I have to try lower. Checking if it's a subsequence can be done in O(n).

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

      Suppose i is the answer then it is possible to construct the pattern for any value less than or equal to i. So we can form a sequence like TTTTFFFFF (t=possible f=not possible). We have to find the last T where it is possible to construct pattern. Which can be done through Binary Search.

      25045586

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

    Binary search(O(log(n))) on length of permutation and check till which index there exist a subsequence 'p' in it (in O(n)). Hence resultant complexity is O(n*log(n))

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

      Hey, shouldn't we include the time it would take to delete the elements as well?

      Also, are you using some other method for deleting? Because otherwise, the deletion itself would take O(n) time.

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

        You don't actually have to delete elements from the string, replace characters at required indices with some special character and check for subsequence(which can be done in O(n)). Refer to my code to get the idea.

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

    I think It can be done using hashing + BIT or hashing + Seg tree.
    Link: String Hashing
    If you read this you can link strategy to this problem. Of course, binary search is easy one solution but It would be worth to learn so it can be applied many problems like this( Sometimes it is easier to implement String Hashing than other Solution).
    PS: Accuracy of Solution depends on Probability of collisions.

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

    Really cool binary search.

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

Как решать F? Я стабильно получал ML14, и никак не мог от него избавиться.

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

Ideas on D div.2?

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

0.0

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

    Hey guy stop it please

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

    Usually I'd use a "strict <" in function "cmp". It could be the problem. Just a hint for you to dive in.

    However, please do not post your code everywhere, especially in unrelated posts.

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

    share your code using idone or just give the link of your submission :| Dont spam the page

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

Seems like problem E's parsing is harder than task itself lol.

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

I misread problem E. I could have solved it :(

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

From problem E, how do you handle cases like this?:

3 5
a := 10100
b := a OR ?
c := b XOR ?

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

    Notice that each bit for ? can be decided independently. So, for each column of bit, just try 0 and 1 and take the optimal one.

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

    For every bit in every variable, you should know it's value, for when the corresponding bit in ? is 0 and for when the corresponding bit in ? is 1. For example:

    a = [[1, 1], [0, 0], [1, 1], [0, 0], [0, 0]]

    b = [[1, 1], [0, 1], [1, 1], [0, 1], [0, 1]] (you calculate this using just variable a)

    c = [[1, 0], [0, 0], [1, 0], [0, 0], [0, 0]] (you calculate this using just variable b)

    E.g. the emphasized array in c means that if ? = "..0..", then c = ".. 1 .."; and if ? = "..1..", then c = "..0..".

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

I believe that a large number of chinese can solve Div2E, for a similar problem has appeared in NOI2014. The similar problem's chinese name is "起床困难综合征", you can find it on many websites. NOI is olympics in infomatics in China. Sorry for poor english.

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

How to solve Div1 C?? Thanks in advance :)

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

    I used DSU on tree technique. Removing character at index p is equivalent to removing all edges at depth p in the trie. The hash of a vertex is the hash of the string formed when I go from the root to this vertex. For each vertex v, I store the hashes of all vertices in its subtree.Then I can easily find out the number of distinct hashes in its subtrees after removing edges from v to its children.

    Code

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

      the link is broken.Please check it

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

        Fixed. :)
        It's working for me. If it's still not accessible to you, just google "DSU on tree codeforces".

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

      Okay, so, at some point, you will have a set S with the hashes of all vertices in the subtree rooted at v (using DSU on tree). But how exactly do you remove the edges leaving v? I imagine that you pass through each element of S applying some hash-related operation to remove the first edge, then you'll get a new hash and you'll put it in another set S'. After this pass over S, the size of set S' is the answer. Is that it? If yes, what is the hash-related operation to remove the first edge? Thanks for the help!

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

        Suppose I am at vertex u. And the heaviest child is v. After I have processed v, the global map I use already has the hashes of all nodes in the subtree of v. I need to check other subtrees of u. Let us consider node w in some subtree of u (let that be x) such that w is not the heaviest child of u. Now, I need to calculate the hash of w assuming that the edge u->x does not exist. This is equivalent to calculating the hash value of w assuming the edge u->x has the same character on it as the edge u->v. I do exactly this in my code. Then the number of nodes which remain after deleting the edges from u will be equal to the number of nodes in the trie-1 (because it includes v too which must be subtracted).
        The above explanation is very specific to my code.

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

    I solved it in , where k = 26, the alphabet. Solution idea is pretty simple  –  "Let's try and merge all child tries of the current node and see what total size we get". You can merge two tries in time proportional to the size of lesser one, and it is well known that in worst case each node will be in mergers.

    So, the algorithm:

    1. Iterate over all nodes, and also compute their depths in order to update answer for correct value of p.
    2. Merge all child tries of current node and compute the size of this merged trie, then add size change to the answer for corresponding p.
    3. Roll back the changes and go to the next node.
    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +7 Проголосовать: не нравится

      Could you elaborate why it is O(n k log n)? I thought of the same approach, but wasn't sure it would work.

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

      I've tried to implement the similar approach but failed with the "rollback" part, could you please give some detail on that?

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

        One of the simplest ways: every time you change any variable, push back {what was changed, what value it had before} into a vector, then reverse it and apply the same operations backwards.

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

      I practically copied your code and submitted it without the nodes' size verification (i.e. the swap(u, v) in merge()) and the runtime was 200ms. Any idea why?

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

      i thought your solution will fail on a test with binary tree where every left edge is "a" and right is "b" (quite a few vertices will be merged then), but it didn't. however, i also ran solutions of top-10 and only half of them where fast enough on my computer, some even getting 40s+.

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

I almost solved problem E (DIV 2). but time ran out. I am such a slog. Treat each bit independent of other m-1 bits!!!

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

How to solve problem D in Div.1?

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

    any ideas? What was the approach?

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

      I read some AC codes and found this excellent idea: The operation is reversible and so we can try to turn both the current configuration and the desired configuration into a configuration like:

      UUUUUUUU

      DDDDDDDD

      UUUUUUUU

      DDDDDDDD

      UUUUUUUU

      DDDDDDDD

      and then you can combine the two sets of operations to get the final operations. Sorry for my poor English..

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

        the idea works because each time we try to fix the top-leftmost block to be LR, if the block is originally UD then we fix the next block to UD and turn, and if the next block is LR then the block below it is LR(done) or UD and so on... eventually we will have a "ladder" and this ladder cannot continue indefinitely, so there will always be solution.

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

Is there anyone else with WA77 in task A (div. 2)? Because I solved B-E correctly, but A failed on 77 text..

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

Was it intended to fail MNlog(N) solution on Div 1B?

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

    You have O(M*N*log(N)*len(var)) ~= 1/2 * 10^9. That's a lot to STL

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

    I changed map to unordered_map after the contest and got AC. How do you tell when unordered_map is faster?

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

      unordered_map is generally (quite a bit) faster if nobody is attacking your hash (to cause collisions) and when you have sufficient buckets (check out c++ stl reserve()).

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

The only thing that made problem E tougher was the input format. Takes loads of time to write the code to process the input variables.(String splitting n all). I missed solving it by 2-3 mins due to this.

The crux idea of the problem was not that difficult according to me. Complexity of N × M × 2 is good enough.

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

http://codeforces.com/contest/778/submission/25048949

My solution to D.

I just keep changing every LR to UD, and then every UD to LR, recursively, until it is done.

Is this solution correct?

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

    It's not the solution that we expected, I don't know how to prove it but it looks like it's correct.

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

    Suppose m is even. Let's call 'step' changing avery LR to UD and then every UD to LR, as done in matthew99's solution. We want to show that eventually all cells become L or R.

    A cell is 'stable' if it is L or R and it stays the same after performing an arbitrary number of steps. Suppose by contradiction there is a cell that never become stable, and consider the first one which has this property (it means that all the cells on the left and those placed in some preceding row eventually become stable. We can assume they are already stable, provided a sufficient number of steps has been performed). This cell must be U, and we can also determine the type of many other nearby cells, as shown:

    ****************
    ****ULR.........
    ....DULR........
    .....DULR.......
    etc...
    

    (asterisks denote stable cells, dots denote unknown cells).

    The same pattern must continue in diagonal until the border of the grid is reached. But this is impossible because there's no way to tile the cells above that diagonal using dominos (if you color them like a chessboard, the number of black cells and the number of white cells would be different).

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

Even after getting good rank my rating won't go up just because there were 3000 people in the contest. Bad day!!!!

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

    The fact that you got a good rank was because there were only 3000 people , if there were more people it would proportionally increase :P

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

    roz shankar bhagwaan ko ek lota jal chadao, rating badhegi bacha! bum bum bhole!

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

Div2E TL on 33 test
Replace map with unordered_map
Accepted
Just why....

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

-removed

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

Div2 round was a race to see who types faster =(

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

Amazing problemset.

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

At problem div1E, is 47th test particular in any way? I am getting WA on it with an answer pretty close to the expected one...it must be something special about (47 is magical, isn't it:)) ) because I passed 46 tests and the solution makes sense.

LE: I found a test that I was failing and now I have AC. So, if at any time, there is anyone in need of a test that might have some similarities with 47th test (or of a strong and really small test as it proved itself to be), here it is:

1
2
9
99
4 1 0 0 0 0 0 0 0 0

The answer should be 14, but my almost perfect program was returning 13

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

This is the first time I solved 4 and I'm getting my ratings reduced :(

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

For div2-F/div1-C I saw a few submissions using dsu on tree technique.Can someone please explain the approach briefly.

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

Can someone prove complexity of this solution? 25040913

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

    So let's prove asymptotic O(26 * n).

    2 vertex have merged, so they won't be merge again. So my solution works 26 * O(count of merges).

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

      For each level O(N) merges, not?

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

        for each level O(len(h)), sum(len(h)) = n

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

          Solution complexity is , right?

          And check(i) complexity is , right?

          And dfs(i) complexity is , right?

          So, depth is O(N). Then  =  N.

           =  ,

          Since depth  =  O(N), solution complexity is

          UPD: I think that this piece of code in dfs reduces depth to log2(N)

          if (v.size() < 2) return 0;
          

          If there insted of this if will be this one :

          if(v.empty()) return 0; // v.size() < 1
          

          apparently your code will take TLE

          So I think that complexity of your solution is . Isn't it?

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

            f(n) — complexity of sum dfs with n nodes.

            m <= 26, sum(s_i, i <= m) = n — 1, f(n) = max(sum(f(s_i)) + m * min(s_i)) if (m = 1) f(n) = 1

            let's prove f(n) = n log2 n

            if (max(s_i) <= n / 2):

            1. sum(f(s_i) < n ((log2 n) — 1)
            2. m * min(s_i) <= n
            3. f(n) <= n log2 n

            else:

            1. if m > 2, when we can found f'(n), that using m <= 2 and f'(n) more than f(n)
            2. so we need to prove, that (g(n) = a log a + b log b + min(a, b) * 2) g(n) = n log2 n. I didn't prove last step, but i checked it for n <= 1e5 and it is working
            • »
              »
              »
              »
              »
              »
              »
              7 лет назад, # ^ |
                Проголосовать: нравится +18 Проголосовать: не нравится

              Idea of your solution is: "merge subtrees of each vertex". Due to if (v.size() < 2) return 0; it works like a well known technique, when we return set in dfs and merge smaller set to larger, and in your case it merges smaller subtree to larger. So it does O(NlogN) operations of merging single element, and in your implementation it is done by dfs, for each iteration of which you create 26 vectors and in total it works O(NAlogN).

              In worst case (binary tree) you do more then 200N calls of dfs(): http://ideone.com/ngO6lG

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

Can some please explain how to approach problem E of DIV 2 ?

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

    For bitwise operations (like AND, OR and XOR), this sort of optimization problem can be solved independently for each bit. Just evaluate and sum all variables for all (two) possible choices for bit i.

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

      to calculate sum means to maximize the sum , mth bit of sum should be 1 , and to minimize the sum mth bit should be zero ?

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

        No, I mean the sum of the i-th bit for all variables. If the variables have values 0xf, 0x7 and 0xd, then sum(0) = 1+1+1 = 3, sum(1) = 1+1+0 = 2, sum(2) = 1+1+1 = 3 and sum(3) = 1+0+1 = 2. Now consider only sum(i). Let a = sum(i) when choosing the i-th bit of '?' as 0 and b = sum(i) when choosing the i-th bit of '?' as 1. Choose 1 for the minimum only if b < a. Choose 1 for the maximum only if b > a.

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

          Didn't get this part Let a = sum(i) when choosing the i-th bit of '?' as 0 and b = sum(i) when choosing the i-th bit of '?' as 1. Choose 1 for the minimum only if b < a. Choose 1 for the maximum only if b > a. Could you please explain why you are doing this ?

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

            Simulate the process taking ? as 0, the number of 1's is a. Do the same taking ? as 1, the number of 1's is b. Choose 1 for the minimum only if b < a. Choose 1 for the maximum only if b > a. Do this for all bits.

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

            Remember that where xj, i is the i-th bit of the j-th number. Then . So minimizing/maximizing is the same as minimizing/maximizing for all i. Since bitwise operations do not have carry-in or carry-out (they're bitwise!!!), we can evaluate the i-th bit for all variables (xj, i for all j) for both choices of a bit (0 and 1) and minimize/maximize for each i independently. This is why I do what I'm doing in the part you didn't get!

            Edit: And sum(i) = .

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

Can someone tell me why I got WA on the contest 25046285 and why I needed to getline() one extra line?

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

      Thanks for reply. can you explane me problem with input ? I will change my code to get AC easily.

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

    getline() takes input till end of line character. If you have input
    2 2
    abc
    def

    If you do cin>>a>>b and then getline(), you are actually taking empty string input terminated by EOL character of 1st line, not the 2nd.

    If you want to take line input n times, you should do
    cin>>a>>b
    getline(cin, str)
    for(i=0;i<n;i++) getline(cin, str)

    I have used getline() in my submission for this contest's Div-1 B.

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

      Thanks I understood story about getline(), but again I am not sure about WA, actually for me it looks that our inputs are same. Len added onlyonr getchar more and it changes result. I understood it is for new line, but again I am readin n+1 lines.

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

Hello! I tried to solve problem C-Div2 using C++ by sorting the objects by their a-b value. The complexity should be O(N*logN). I tried both sort from <algorithm and an iterative quicksort, but I got TLE on pretests 8, respectively 9. Could you please help me figure out what I did wrong?

EDIT: Code with STL sort, TLE on pretest 8: http://pastebin.com/ZkrnPpXG

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

    A code is usually nice to post here, if you're expecting help :) The idea is correct, though. One of the common mistakes you might have, ensure that your comparator to sort returns FALSE on equal objects.

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

I really like this round. I think Div.2 A has a little difficult, but B and C are easy. And my classmate FizzyDavid (Codeforces.com/profile/FizzyDavid) is Div.1 rank 7 and he becomes red. My rate also has a little rise! Congratulation to him!

-- Sorry, I am a Chinese, so my English isn't good. Sorry for my bad English!

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

Will editorials be published for this one?

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

While this is not a huge concern in competitive programming, is there a straight forward way to read a line of input into a vector/array in C++? (Just like foo = input.split() in python)

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

    I don't think there's a very simple way.

    I usually do this:

    char tmp[1000111];
    gets(tmp);
    stringstream ss(tmp);
    
    vector<int> v;
    int u;
    while (ss >> u) v.push_back(u);
    
    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I am also using stringstream for the task, but feeding the string back into a stream after reading it seems to be unnecessary intuitively. :/

      (Is there a less "simple" way, but we can feed it straight into the stringstream?)

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    string s;
    getline(cin, s);
    

    should just work, since in most cases string works just like a vector

    However, be careful when using this method:

    // Input:
    // 5
    // abc
    int n;
    cin >> n;
    string s;
    getline(cin, s); // here s would be ""
    
»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hey guys. How to solve this problem https://www.e-olymp.com/ru/contests/7949/problems/66445? I can't get this prob.

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

    Treat the cells as elements of a segment tree with range modification (add C to L..R) :)

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

с нетерпением жду разбор задач

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

Can anyone help me figure out what I am doing wrong for div2E / div1A ?

submission

I'm trying a simple binary search on a, coupled with a linear time check to see if p is part of t. It fails test 7.

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

    shoud be left = mid and right = mid not mid+1 and mid-1 int case left = 2 right = 3 => mid = 2 and after that right = 1

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

Why the first one gave runtime error but second passed? 25061791 25061827

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

    In first solution you use comparator which is wrong. It should not return true for cmp(a, a). Compare is used as a function object which returns true if the first argument is less than the second, and false otherwise.

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

Why isn't the editorial still out?

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

waiting for edutorial~ brute force for F seems available- -but why?

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

    If you merge always merging the smaller subtrees into the largest one, the complexity will be O(n*logn*number of characters) as said here: http://codeforces.com/blog/entry/50658?#comment-346232 The proof is something like: You have a subtree of size 1, to use it on the merge you need some subtree of size at least 1, now you got size at least 2. Do the same, now you got 4... It's clear that you'll use some node at most logn times.

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

where can I get editorials to div 1 problems?

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

Can somebody explain 402 D div2 in laymen trms with some test case or proper approach?

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

    Notice that if you take out k letters from the string and you can still form the other word, then, if you take out less than k letters from the string, you can still form the other word. Then, you could see what happens if you take 1, 2, 3, etc. letters from the original string and see if even without those letters, you can form the other word. Of course, this is too slow to pass. Then, we have to binary search the amount of letters we can take, while being able to form the second string. For each length, evaluate if the original string minus the first k indexes still contains the objective string. If it does, you can take out more indexes. Else, you must take less indexes. My submission: 25066942

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

screenshot screenshot

My submissions did not get judged by system test but got rank-changed. I register late in the extra registration after contest start. Is this an intended system behavior or a bug?

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

    This does seem like a bug. I have joined in on extra registration before and rest of it is completely normal, Post Tests should have run for your submissions.

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

it should be unrated

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

Why haven't we got the editorials till now ?? They should have been uploaded by now :)

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

Sorry I mistake

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

Can someone please explain the statement for Div1 C? Is it necessary that after eliminating the pth letter all words to be different? So that the language will have the same amount of words?