Автор awoo, история, 3 года назад, По-русски

Привет, Codeforces!

В 29.04.2021 17:35 (Московское время) состоится Educational Codeforces Round 108 (рейтинговый для Див. 2).

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Роман Roms Глазов, Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

Также от наших друзей и партнёров из Harbour.Space есть сообщение для вас:

Codeforces and Harbour.Space

Привет, Codeforces!

Пришло время для еще одной отличной возможности получить стипендию от Harbour.Space!

Мы стали партнерами PhazeRo, чтобы открыть двери для увлекательной карьеры в сфере технологий для самых талантливых людей.

В сотрудничестве с PhazeRo, мы предлагаем полную стипендию для обучения в магистратуре "Data Science" в Harbour.Space, во время которого вы будете проходить стажировку на позиции Junior Data Scientist в PhazeRo!

Условия для получения стипендии:

  • Степень бакалавра
  • Свободное владение английским языком
  • Знание интеллектуального анализа данных, математики и статистического анализа
  • Опыт работы с Tableau, SQL, и разными языками программирования (а именно Python, R, Java)

О стипендии:

  1. Учеба в самых интересных технологических городах Европы
  2. Размер стипендии до 22,900 евро
  3. Компенсация за стажировку в PhazeRo (700 евро в месяц)
  4. Возможность работать в PhazeRo на полную ставку по окончанию обучения

Codeforces and Harbour.Space

Некоторые из преимуществ работы в PhazeRo:

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

Ранее мы сотрудничали с другими компаниями, такими как OneRagtime, Hansgrohe, Coherra, и Remy Robotics, чтобы расширить возможности молодых талантов по всему миру и помочь им сделать карьеру в сфере высоких технологий.

Мы всегда рады видеть членов сообщества Codeforces, которые присоединяются к семье Harbour.Space. Подайте заявку сейчас, чтобы получить шанс учиться у лучших в этой области и начать свою карьеру!

Следите за новостями в LinkedIn, чтобы не упустить новые возможности. А так же загляните в наш Instagram, где мы делимся событиями студенческой жизни и историями успеха наших учеников.

Удачи в вашем раунде и до встречи в следующий раз!

Harbour.Space University

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

Место Участник Задач решено Штраф
1 neal 6 186
2 vepifanov 6 188
3 Um_nik 6 251
4 Farhod 5 65
5 noimi 5 76

Поздравляем лучших взломщиков:

Место Участник Число взломов
1 __ZMF__ 50:-50
2 mufeng.wei 24:-4
3 SSerxhs 22:-9
4 mahesh_dubey 13:-1
5 haminh0307 11:-5
Было сделано 463 успешных и 1684 неудачных взломов.

И, наконец, поздравляем людей, отправивших первое полное решение по задаче:

Задача Участник Штраф
A Geothermal 0:01
B turmax 0:02
C eecs 0:04
D abc864197532 0:04
E noimi 0:28
F rainboy 1:16

UPD: Разбор опубликован

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

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

I hope I get that scolarship ...

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

Надеюсь решу больше чем только А :)

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

I think preliminary rating change in educational rounds will be great.

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

    Wow! such big brain! and after every hack, rating changes of all 25,000 participants will be recalculated! No problem sir! I will put the word through to Mike

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

      Uhm no? Just do it twice. Once after the contest ends, and the second one when the hacking phase ends. Stop trying to act smart you idiot.

      PS — We have rating predictor extensions so prelim rating changes are not really needed.

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

9th rated contest of the month. Hail Codeforces!

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

A long break bruh, Codechef also postponed the Lunchtime.

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

i am very excited to participate the contest,wooooooo~

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

Almost every edu round I was "educated", but I still participate in every round...

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

"The penalty for each incorrect submission until the submission with a full solution is 10 minutes"

Does this mean that only time will be taken and there wont be a -50 or -100?

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

Today codeforces educational round. Tomorrow codechef lunchtime. Day after Tomorrow CodeJam Round 1C. Practice & Compete & Improve.

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

hope i remain expert after this contest :)

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

Time to start the vacations with an educational round. Excited!

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

I wish B/C not to be a observational shit like printing the array upto k and then upto n-k lol.

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

Hakcers will try to hack the solution in 12 hrs, while cheat busters will try to match the solutions in 12hrs.......

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

i hope i do best in the contest and happy coding to everyone

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

Have a great rating change

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

Nice contest!

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

Today's Problem Difficulty. Pls forgive me for not enlarging the image as I dont know how to do that.

Today's Problem Difficulty

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

    B and D is almost same difficulty level though

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

      B<A<C<<D<<<<<<E/F

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

        C took me an hour... D took me 10 mins...

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

          How did you do it? I did similar to longest palindromic substring. fixed pivot for both odd length subarray and even length subarray and then extended both sides.
          Time complexity: n^2

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

            Basically, yeah, what you did.

            For each position in the array i I tried generating an even length subarray and uneven length subarray that begins with that position as the middle or one of the middle elements. At each iteration add one more in each end so that the new subarray is continuous. Notice that moving through them like this maintains the position of the ones inside, so you just have to see what difference the new ends would make. O(n^2) time, O(n) memory.

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

sometimes unexpected bruteforce works . Today it worked for problem C for me

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

    Can you wait till the end and not spoil solutions?

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

    Its not "unexpected" since its not hard to figure out why it doesn't tle

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

      yes and I coded only after I got n*root(n) bound for it :(. If we do only, take contribution from 1 to size of students in university for Ks. As, if the size of such universities is more than root(n), then their number will be less than root(n), so n*root(n) here and if the size of universities is less than root(n), then O(n) such universities can be there but k:1 to root(n) for such, so again n*root(n). So, overall complexity is n*root(n). The complexity might be less than this, but this was enough.

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

      He did TLE after the hacking phase with the additional tests

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

    i too did bruteforce in C. Got TLE. can you tell me where I went wrong? I can't think of any more optimisation. :/

    https://codeforces.com/contest/1519/submission/114607388

    link to my submission.

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

      Your brute force solution works in O(n^2) time as you try every n university for every possible k (which k==n), it won't pass since n^2 = 10^10 ~ 100 seconds. But if you observe the problem, you will see that after the number of people in university > k, you don't need to check it again as the number of teams will be 0. You can somehow remove that university from your checking list (effectively). This will improve the solution a lot. My submission: https://codeforces.com/contest/1519/submission/114578952

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

        But why doesn't n^2 work when time limit is 2 seconds. I have encountered this situation in some other problems as well. Sometimes, n^2 works for 2 seconds sometimes it doesn't. Is it because of the heavy calculations ?

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

          Whether n^2 works in 2 seconds or not depends upon the size of n. Although I would try to give a rough idea that what kind of solution can run in 2 seconds. In one seconds a normal loop would run near about 10^8 times in c++. It is only a rough estimation. In C the value of n was 2 * 10^5. If we square it, the result goes to 4 * 10^10. To run this solution at least, 400 seconds are required (again a rough estimation). So it definitly won't run in 2 seconds. Your assumptions that sometimes an n^2 solution runs in two seconds would be right when n is small. For n valued this large, an n^2 solution would never run, if the test cases are good.

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

      Probably You are getting TLE due to a very little mistake. Do check it out here. Link to Explanation

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

Speedforces

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

Does anyone with O(2*n^2) space got MLE in D?

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

    You will get MLE because final answer can be equal to 5*10^17 which needs to be stored in long long int. 2*5000*5000*8 contiguous allocation is not possible (In case you used DP).

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

      YA right but my O(N^2) python also getting MLE in 11 , I wonder why?

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

        Because Test 11 forces python into long arithmetic. If you will different algorithm to get rid of O(n**2) memory allocation you'll get TLE on 11 test. Then you'll need to do a little math, to get rid of excess of multiplication in your formula. Python often turn out to be pain here on codeforces :)

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

      Same happened with me. MLE

      AC

      cost me atleat 400 rank.

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

Memory limit was too short for problem D!

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

Probably there's like around 5 people right now writing "SPEEEED FORCES"(joking of course:)). I think this problem could have been avoided if E was more "div2-solvable", I mean around 60 people solved it and a good amount of them are red coders. There's no point I think in making A-D so standard(especially D) and E that hard.

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

    Pretty crazy variance. Solving A through D could either get you 60th place (with an implied rating of about 2250 according to cf-rating-predictor, which is orange), or as low as 2400th place (with an implied rating of about 1640, which is blue).

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

Really liked $$$E$$$. I wonder if everyone solved it the way I did.

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

    Interesting. I just used a known algorithm, which is given a graph cover it with paths of length 2 using a DFS. Seems most other people did it this way as well.

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

      Can you describe said algorithm? I wasn't aware of it's existence.

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

      Interesting! I didn't know about this algorithm.

      As I understand (after reading the Editorial to the task dorijanlendvaj posted), to apply this algorithm you transform the task in the following way: Each line through the origin will be a node. Each Point will be an edge and it connects the two lines to which it can be moved. Now we want to find edge-pairs which are connected to the same node. Those pairs should be mutually disjoint.

      While I was thinking about this problem I somehow was only thinking about the other way round: For me each point was a node. Two nodes are connected, if the corresponding points can be moved onto the same line through the origin. Now I tried to find the maximum amount of disjoint node-pairs connected by an edge. (This is the Line Graph of the first interpretation).

      So what I learned: Sometimes you should switch edges and nodes in your analysis/interpretation of a problem, maybe this will make the problem easier.

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

        If we consider the points as vertices and connect two vertices iff they'll lie on the same line passing through origin after shifting them. Then this problem will reduce to finding maximum matching in the graph, right? But that is too general. As in our graph let's say a is connected to b,c,d then a is a part of at most 2 cliques which is ({a,b,c,d}) or ({a,b},{a,c,d}) , or, ... etc .

        So by considering a line as a vertex, we have somehow used this property, right?

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

          Hey Zura,

          Theanks for pointing me to the maximum matching problem . That is exactly what should be solved in the second interpretation!

          Im not sure about your other comments though. Which property do you mean? I feel like we lose properties by looking at the linegraph, because the problem can't be solved with a simple DFS anymore.

          Maybe it's good to look at an example? e.g. {(1,2),(2,3),(3,4),(4,5),(5,6),(1,6)} (The first 5 points all can be moved on the main diagonal, and the 1st and 6th point can be moved on a common line) would have those two graphs in the corresponding interpretations:

          Image

          The possible solutions are the same in both cases. Could you explain again what you meant, possibly with the example (or an own example)?

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

            1st and 6th can't be moved on the same line as the first ones' slope would be (2+1)/1=3 and for 6th it is (1+1)/6=1/3.

            Other than that as I was pointing out 1,..,5 forms a clique.

            If 6th point were (2,5) and 7th were (3,8) then 1 is contained in two cliques 1,..,5 and 1,6,7. So by considering when we use a line as vertex we are basically accounting for this whole clique.

            I am unable to understand any further than that though, so waiting for the tutorial.

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

        Why switch if you reduced problem to kuhn-munkres algorithm? You mean that you could do better with dp than O(n*m)?

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

          No, The property that I stated in the previous comment, at most 2 cliques, will help us as we have not utilized all the components of the problem. I don't know how to model this property, but these additional bits help us, and hence we can do better than Blossom's as that is for general graphs.

          Blossom's is for general graphs.

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

          Could you elaborate? Do you mean kuhn-munkres ? This sounds to be an algorithm for bipartite graphs, but the second interpretation doesn't yield a bipartite graph.

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

            Yep, you are right. My mistake.

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

              You can use the Blossom Algorithm though with $$$O(V^2E)$$$ or $$$O(\sqrt{V}E)$$$ with "the much more complicated algorithm of Micali and Vazirani".

              Guess we should stay with the first interpretation, or somehow use the information that the graph in the second interpretation is a line graph of some other graph (of the first interpretation).

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

                Couldn't get it when I read it first time, (an0nym0us_m0use, czhang2718) but now I think I understand :) Looks like it will really work greedily with every connected component as stated above: While doing DFS on a graph until you met visited vertex or deadend-vertex, then you come out of current vertex and connect all unconnected pairs of children (those that were left unconnected when you left them). And if there 1 left — you connect it to current vertex, else — you return in to it's parent as "unconnected" yet. Then parent repeat the process. And the number of unconnected points in answer will be the number of even-numbered-components.

                And that will work for any of two graphs. It's nice that they delayed editorial :)

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

                  Yes exactly that! I also did my submission 114692979 that way and it got accepted right away. The DFS-logic is in the "dfs" method and does exactly as you explain. :)

                  But what do you mean with "any of two graphs"?

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

B destroyed my confidence.

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

Could we solve D with $$$n$$$ times FFT? My $$$O(n^2 \log n)$$$ solution can't pass this TL :(

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

    Numbers were very large, how will you apply FFT?

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

      Just brute-force points of the reversed subarray $$$[L,R]$$$.

      For each $$$R \in [1,n]$$$, we calculate $$$C = A[0..R-1] * B[0..R-1]$$$, and $$$*$$$ presents convolution. Then $$$C[i-1]$$$ is the value of reversed subarray $$$[i - R + 1,R-1]$$$, it's easy to calculate the max contribution of all reversed subarray ended at $$$R-1$$$.

      The single round's time complexity is $$$O(n\log n)$$$ and the total is $$$O(n^2\log n)$$$. You can see my code here: 114607269

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

        Yes, you are right. I wanted to say that FFT will have precision issues while handling large numbers. The sum can go upto $$$10^{19}$$$ for subarrays. Such large values cannot be handled.

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

          I found that issue later xD. At first I even didn't consider precision,and long double has no hope to squeeze in this TL.

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

    FFT has a large constant factor. But also, for $$$n=5000$$$ I think it should be quite difficult to get any $$$n^2 \log{n}$$$ solution to pass, much less FFT.

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

    my solution didn't pass also. 114602456 . looking for a AC solution with FFT. or its impossible with such time limit !!

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

how to solve D

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

In E, I was able to group together the points that can be taken together in one move. But, how to make pairs? is it some sort of matching problem?

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

    I'm not sure what intended is, but we can do tree DP: think of each point as connecting two slopes. Then, create the DFS tree from this graph. Now, the question is what's the maximum number of 2-length paths we can partition this graph into. Then, for each subtree, let's greedily partition it. Let dp[x]=whether we need to reserve the edge going to x's parent. Then we can greedily match x's immediate children with DP value 1, and back edges leading up to x. dp[x]=[whether the count of such nodes is odd].

    Now, we can easily obtain our answer by keeping track of which edges refer to which original points. This is optimal because the number of extra/unused edges at the end is 0 or 1.

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

Video Solutions for problems A — D can be found here: Video Solutions

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

D was so easy compared to C

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

    can you please explain your approach

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

      There are n^2 subarrays, get answer for all of them and print the max

      Probably the best way to iterate over them is by iterating all possible centers

      Use the fact that you can calculate answer for A[0:10000] for O(1) if you know the answer for A[1:9999]

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

    Pls don't make me feel stupid :(

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

      Maybe you need to work on your dynamic programming skill a bit? I personally just thought dynamic programming initially and then realised I can do without the extra memory.

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

        Can you tell me how to do D without extra memory?

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

          In D, i think the best solution is iterating over centers of subarrays and calculating the difference between new and old values. It takes O(n^2) time and O(n) space complexity (just a and b arrays). My submission is here: 114594546

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

    D is simple implementation once you see how the dp works. But getting that idea is not so simple.

    C on the other hand is the opposite. The idea is simple to see, but the implementation has some pitfalls.

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

      The opposite for me

      Took me quite a while to get the idea what to do in C to avoid time limit

      And instant idea in D

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

Nice problems

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

Is Question E a MCBM problem? I was thinking of modelling both of the possible moves as a fraction x/y then try to do matching between points with the one of the same fractions. However, this is potentially O(n^2) so I am not sure if there is a way to optimize it.

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

memory limit was too tight in problem D

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

    Am I the only one who did it in O(n) space?

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

      no

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

      Yeah, you can do it O(n) space and O(n^2) time complexity. Iterate over all points as pivots and iterate over length of subarray to reverse. Then do the same for all gaps i.e. even length subarrays.

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

    No additional memory other than the original array was needed actually.

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

      well , my O(n^2 * 2) DP didn't pass , but I realized after the contest was over that I can change it to only n^2 space , and i coded it and got AC. welp , thats my rating going.

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

      could you please elaborate on how to do this. I used two addition arrays of size $$$n$$$ to store answer for subarrays of size $$$i-2$$$ and $$$i-1$$$. This is because we need to have answer for subarray of size $$$i-2$$$ if we are going to calculate answer for subarray of size $$$i$$$.

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

I used n^2 Space to solve D but it exceeded memory limit. I still wonder how it is possible.

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

    try to replace the vector with an array

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

    In D, any n^2 memory takes 200 MB in worst case. So even if you had 2 such types of memory, it will MLE.

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

    My O(n^2) Space and time dp passes all TC. Video explanation

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

      I will be thankful if someone makes video editorial of E. Why everyone posts editorial of problems solved by 1000's of people.

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

        Actually, You can see I 've just posted for only Problem D for this contest, and I'm trying to post for video explanation of problem E too asap.

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

        Because there 8000 people interested in A and B, 15000-19000 in C and D, and only then there 2000 who solved D and interested in E, and 50 interested in F :)

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

How to solve Problem C. I ran into TLE. This is my solution using Heap. I also tried using sorting the vectors, which too ran into TLE. Kindly help

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

Hi, Can someone help me with my submission for problem C . I am getting a run time error for the first test-case which is already given but running that test-case on my laptop is not giving any error and the output is also correct . The link to my submission My_Submission. Thanks in advance.

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

Problem D was super not Python friendly. This is the shit I did to get accepted 114611359.

The reason for the TLEs in Python is basically that PyPy2 and PyPy3 is only 32 bit on Windows. So on Problem D you are forced to use big integers everywhere, which is super super slow. However in the latest update of PyPy (version 7.3.4), PyPy switched to supporting 64 bit on Windows.

MikeMirzayanov Would it be possible to update the PyPy version (to version 7.3.4)? All of these issues with big integers would go away, and it would make PyPy a lot more useable and beginner friendly.

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

too strong memory limit in D (

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

In question C, the description was ambiguous, there were not exactly 'n' universities always, rather nothing should've been mentioned about universities!:)

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

    Why not? They never said each university had a competetive programmer. It is possible for a university to have no competetive programmers.

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

      Ohh..I got it now....thanks for clarifying.....I forgot this statement of yours!:)

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

Hello everyone, this was my first ever contest on any coding platform , and I was able to solve just 4 questions and got around 1500 rank. Can anyone tell me whether it is considered good performance or not? Also , what should I do in order to improve? Thanks a lot.

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

Why was B so easy? Usually B is twice as good as A(even for an edu round). We can basically induct on $$$m+n$$$ and B is solved.

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

    That's once you guess what the answer is. And then you can defer the proof until after the contest.

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

Question regarding Problem B: How can we prove that no matter which path we take it will always result in the same cost of N * M — 1 ?

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

    We can prove by induction that regardless of the path you chose, the cost at any point (x,y) along that path will be x*y-1.

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

    The path can be described by a sequence of R (right) and D (down).
    It's easy to prove that swapping a R and a D doesn't change the answer.
    You can reach any sequence, starting from a fixed sequence (e. g. RR...RRDD...DD), with a finite number of swaps.

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

    You can visualize it by realizing that at each point $$$(x,y)$$$ of the path the cost is equal to the area of the rectangle with a diagonal $$$(1,1) -(x,y)$$$ with cell $$$(1,1)$$$ removed. When you move right you add a column to the rectangle, and when you move down you add a row.

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

    You can also prove it like this:

    Consider the conservative field $$$\vec{E}=y\hat{i} + x\hat{j}$$$. Observe that the value required is just the work function. As potential function is $$$U = xy$$$, work done will always be $$$nm - 1$$$.

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

      A stupid question — are you applying continuous calculus to a discrete problem?

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

        Yes. I proved that work done will be same regardless of how you move the particle from $$$(1, 1)$$$ to $$$(n, m)$$$. The problem just asks to consider specific ways to displace the particle, using only the vectors $$$(1, 0)$$$ and $$$(0, 1)$$$.

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

Can someone please explain the proof why for problem B, the answer is k==(n*m-1)?

I solved with DP and got surprised to see it could be formulated.

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

    Consider any RD from (x, y) to (x+1, y+1), you can see that changing the sequence to DR does not change the cost, and thus any sequence will have the same cost.

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

    Prove by induction. You can assume the proposition true for m×n grid , and establish for (m+1)×n grid.

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

      Can you provide the inductive proof please?

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

        Inductive hypothesis: path value is x×y-1 for any grid such that x <= m && y <= n.

        We try to prove the same for (m+1)×n grid.

        Suppose you are at m×j cell and take downturn to (m+1)th row.

        You need (n-j) more right turns to reach (m+1)×n cell.

        Total : (m×j-1) + j + (m+1)×(n-j) = (m+1)×n-1 , which was to be proved.

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

    I did some few examples on paper and found out that the answer is unique, for every n, m. I couldn't find the formula so just calculated it step by step and checked the cost if it equals k.

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

      I calculated the way going through two opposite corners (algebra), got that both were $$$n \cdot m - 1$$$, and then didn't bother trying to prove it.

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

    Proof for problem B that answer is k==(n*m-1).

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

    Another possible proof:

    Instead of it costing $$$x$$$ or $$$y$$$ burles, say that it costs $$$x+y$$$ burles and then you get $$$y$$$ or $$$x$$$ burles back.

    In each move, $$$x+y$$$ increases by 1 so the total sum of $$$x+y$$$ is $$$\frac{(n+m-1)(n+m)}{2}-1$$$, the total amount of burles you get back with the increase of $$$x$$$ is $$$\frac{n(n-1)}{2}$$$(you do one with each $$$x$$$ from $$$1$$$ to $$$n-1$$$) and the total amount of burles you get back with the increase of $$$y$$$ is $$$\frac{m(m-1)}{2}$$$(you do one with each $$$y$$$ from $$$1$$$ to $$$m-1$$$). In total the cost is $$$\frac{(n+m-1)(n+m)}{2}-1-\frac{n(n-1)}{2}-\frac{m(m-1)}{2}=nm-1$$$.

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

      oh,nice. I made it hard for myself.

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

      You are using wrong currency.

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

      Consider an arbitrary path from $$$(1, 1)$$$ to $$$(n, m)$$$.

      We claim that at any point $$$(x, y)$$$ along that path the cost will be $$$x \cdot y-1$$$.

      Proof by induction.

      At the start the cost is $$$1 \cdot 1 - 1 = 0$$$ — the condition holds.

      The induction step.

      Assume that the statement is true at a point $$$(x, y)$$$ along the path. The next point in the path is either $$$(x,y+1)$$$ or $$$(x+1, y)$$$.

      In the first case the cost will be $$$x \cdot y-1 + x = x \cdot (y+1) - 1$$$. Similarly, in the second case the cost will be $$$x \cdot y-1 + y = (x + 1) \cdot y - 1$$$.

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

What is the meaning of the Problem B title?

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

    I guess constraints make this ques harder. If it were around 1e9, all would have tried to thought of general formula.

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

Very happy to see some good ad-hocs like ABCD.

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

Только мне показалось, что системное тестирование с 0% до 99% дошло за секунду?

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

Screencast with commentary aka Um_nik staring at problem F for 40 minutes in silence

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

My python submission for problem C is getting TLE on Tc 5, I tried implementing it as the same way other people implemented and got AC. MY SUBMISSION FOR PROB C

please help. Thanks in advance.

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

    Your code takes O($$$n^2$$$) time because of

    for ii in d:
      for k in range(1,n+1):
    

    If you change it to

    for ii in d:
      for k in range(1,len(d[ii])+1):
    

    then the loops run in O($$$n$$$) time 114686648.

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

I think the official generator for task E is broken since none of the 26 pretests have n > 1e5! Therefore, It'd be best if the authors cut the limit on n to 1e5 and rejudge all the solutions to respect the spirit of competition. awoo

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

    Knowing that there were 26 pretests for E find it strange as well, it's common sense that the only fair option is to reduce n to 1e5 and rejudge everything, if not including max tests in pretests was intentional then the authors are sadistic and should die a painful and slow death.

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

    Nah, I don't think that's necessary. I admit I made a mistake while generating tests, but you aren't really promised the strongest tests anywhere. The constraints are in sync with what the validator checks, so I see no issue.

    Sorry that you got caught by it, be careful the next time.

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

This contest was actually educational for me. I learned 2 things: 1) Never trust the ceil function. 2) Don't write iterative dp like it's recursion, always check the order of computations... goddammit D.

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

I solved problem b but not able to solve a :(

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

Hey! In C problem, I was using comparator on a vector of vectors. When I used '>=' in the comparator it gave a runtime error while using only '>' gave the 'Accepted' verdict.

Runtime code : https://pastebin.com/WQwxwrCd

Working code : https://pastebin.com/sf1e1BTk

Both codes are same except on the 18th line where there is difference of '>' and '>=' in the respective codes. Can anyone explain why this happens?

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

How to get rid of MLE in problem B using Dp can anyone please help? Here is my submission 114621015

Thanks in advance :)

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

speedforces ;)

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

speedforces :P

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

Can anybody tell how to optimize my C's solution further ? 114617580

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

    There can be n lists of size == 1, but you'd still check every of them for i = [2..n]. That would be O(n^2) ~ 10^10. Kick them off from map when their len == i, and stop cycle when i > max_len(m[i]) (map should be empty at this time). But first kick those with len <=2.

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

I guess, the test cases were weak for problem C. Sorting the vector of vectors based on their size and stopping once the size becomes less than K can get your solution accepted.

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

    There's an explanation for that actually. If you iterate from each $$$k$$$ from $$$1$$$ to $$$n$$$, you will find at most $$$\frac{n}{k}$$$ vectors that have size at least $$$k$$$.

    That leads to a known sum which is $$$n logn$$$.

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

      There is a trick to even get it down to O(n).

          out = []
          for k in range(1, n + 1):
              teams = [t for t in teams if len(members[t]) >= k]
              score = 0
              for t in teams:
                  score += prefix_sum[t][k * (len(members[t]) // k)]
              out.append(score)
      

      This part will run in O(n) time, not O(n log n). This is because a team with $$$m$$$ members will be filtered out of teams after $$$m$$$ iterations. And since the sum of the sizes of all teams are $$$n$$$, the code runs in O(n) time.

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

        I did like that in my ugly code, its good to know that it is O(n), i thought it would be something like N*sqrt(N).

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

        Nice trick. Wouldn't it be "cheaper" to kick them from the set, instead of generating new list all the time?

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

    This is probably the intended solution and it's $$$O(nlogn)$$$. It's not about the test cases, it is indeed $$$O(n)$$$ except sorting. Because, if done so, we will consider a university with size $$$s$$$ in only $$$s$$$ different $$$k$$$'s. Since the sum of all $$$s$$$'s is $$$n$$$, complexity is $$$O(nlogn+n)$$$, that is, $$$O(nlogn)$$$.

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

Please explain how to make problem C using Two points method, i made it using Prefix sums.

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

    I guess you'll need prefix sums anyway. From now on, assume that the universities are sorted in non-decreasing order by size. The thing with the "two pointers" must be that when you encounter a university with size smaller than current $$$k$$$, you have to move your "left pointer" (you shouldn't evaluate universities on the left of the left pointer because their size are smaller than $$$k$$$). As with the right pointer, it just doesn't exist.

    P.S. : It is my understanding of this tag.

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

How to solve D?

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

    Maintain a 2D DP array. Here, $$$dp[i][j]$$$ means the value we'll get in interval $$$[i,j]$$$ if we reverse the interval $$$[i,j]$$$. It is not hard to see that $$$dp[i][j] = dp[i+1][j-1] + a[i]*b[j] + a[j]*b[i]$$$ because when we reverse an interval $$$[i,j]$$$ , interval $$$[i+1,j-1]$$$ gets reversed and we swap $$$a[i]$$$ and $$$a[j]$$$. Now, maintain a prefix and a suffix array $$$pre$$$ and $$$suf$$$. Here, $$$pre[i]$$$ denotes the answer for prefix $$$[1,i]$$$ without any reversing and $$$suf[i]$$$ denotes the answer for suffix $$$[i,n]$$$ without any reversing. The answer is maximum of $$$pre[i-1] + dp[i][j] + suf[j+1]$$$ for all intervals $$$[i,j]$$$.

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

Can someone explain why the first submission gets TLE while the second one gets accepted?

114581044 114630025

Only difference is how I sort a vector.

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

    In the first submission, you have used a lambda expression to sort the vector. The problem here is that you have 'captured' the variables using "=" which is slower. I replaced that with "&" and uncommented the "#define int ll" line. The code gets AC after this.

    114639136

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

    Capturing variable using = is by value which means you copy a new vector every time the sort function compares two numbers. Use & to capture by reference.

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

How to solve C ? I solved using factorization in O(nsqrt(n)) but it seems lot of people have solved in some different way.

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

    idk

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

    You can solve problem C using Prefix Sums . Divide all the students by their corresponding cities . For each city , if number of students in my current city is $$${m}$$$ and size of teams is $$${k}$$$ , then $$${m\%k}$$$ lowest skilled students will be not be in any team .$$${\newline}$$$ So for each city , sort the array of students ,calculate the prefix sums , and then iterate over the size of teams ($$${1}$$$ to $$${m}$$$ ) , take sum of skills of all students who can be teamed up ( $$${pref[m]-pref[m\%i]}$$$ ) and add to the final answer array .
    Hope it helped !
    Submission Link : https://codeforces.com/contest/1519/submission/114643205

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

      So, let say there are $$$n$$$ university and each university has only $$$1$$$ student then don't you think your solution will be $$$O(n^2)$$$? I was trying to do same but this case stuck in my mind

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

        The the number of students is $$${n}$$$ , the only thing I did is distribute those $$${n}$$$ students across the cities . There are two loops but the sum of total operations of the inner loop is still $$${\mathcal{O}(n)}$$$ (because I am iterating over the students and only n students exist across all the cities ) .

        In your example case , the inner loop will perform $$${\mathcal{O}(1)}$$$ operation for each outer loop iteration , summing upto $$${\mathcal{O}(n)}$$$ . (Also you'll need to account for sorting , which takes $$${\mathcal{O}(nlogn)}$$$ ).

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

Speedforces.

Many people solved ABCD.

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

Need Help in problem D: **** I have solved Problem D using Python. i wrote the same logic in two different ways 1st way got Accepted but the 2nd way got TLE. both are exactly same as other only I changed the calculation part of the code and I believe it should not affect the run time. please help me out.

TLE Submission : https://codeforces.com/contest/1519/submission/114646999 Accepted Submission : https://codeforces.com/contest/1519/submission/114647073

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

weak test in C

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

Can anybody please tell me why i'm getting TLE in C? Like i used the same approach as many the people who got accepted did, till today morning my solution was accepted by now it's showing TLE
here is the link to my submission https://codeforces.com/contest/1519/submission/114596588

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

    I too had same problem. But, the thing here is, for each k you are checking each university even if k>sizeof(university[i]). This makes your solution time complexity O(N^2).

    Better approach is to go for each university and then add its answer to k( which is less than sizeof(university[i])). To do this we need only O(N) time complexity.

    Here are my solutions:

    This is similar to your approach but got TLE: https://codeforces.com/contest/1519/submission/114653177

    Here I modified it as stated above and got AC: https://codeforces.com/contest/1519/submission/114659364

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

      if it's becoming O(n^2) then how come it passed TC:7 because which is some what similar to TC:8(on which i'm getting the TLE)

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

        Let's define n as the max number of the students in one university and m as the number of universities. The last loop in your submission will run n*m times. It seems that there is only one university which is numbered 200000 in the 7th testcase. However, there may be 100000 different universities in your TLE testcases, where the first university has 100001 students and every other university only has one student.

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

OH C ! You broke my little heart

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

Can Someone figure out why I am getting random values instead of 0, for problem C MyCode(https://codeforces.com/contest/1519/submission/114659037)

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

when the ratings update cannot wait for more time??

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

In Problem E, why doesn't the following greedy solution work?

I first order lines by their angles with Ox and iterate them by counter-clockwise order. For each line, find two points that can reach the line, and always take points under the line first. Of course, I remove selected points after each step.

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

    I did the same but got stuck on test 7 because there's a test case that ruins this approach. Let's say a specific angle has 3 points and other have 4 points and another one with 1 point. You're gonna choose any 2 of the 3 but what if the 2 points you choose were in the other 4 points ? It won't be chosen there (at the 4 points's angle). So, you have to choose 2 points out of the 3 that won't interfere with the 4 points to get the maximum number of moves and it would just interfere with that 1 point because it won't be chosen anyway. Hope you understand my explanation.

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

Time limit exceeded on test 8 :(

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

C was a pretty cool problem. Never seen anything like it, requires some thinking, yet not too difficult. Props!

Why not just pick n=2000 for D, so it can be solved in Python? Now I had to go back and rewrite my solution in C++ for no particular reason, just because the Python implementation barely times out. I actually thought it was a very nice problem other than that annoying detail.

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

    I assume n=2000 might have allowed some O(n^3) solutions to pass by virtue of vectorisation. That might be the reason setters kept n=5000.

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

Is it rated?

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

Problem C raises my doubt about how vector<vector<int> > works in different versions of cpp compilers. After calling push_back() for serveral times, sometimes the result is unexpected but sometimes it looks fine. It seems that this error is related to the version of the compiler. Could someone please explain why?

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

MikeMirzayanov Please update the rating change, please...

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

I've got a nasty bug in the implementation of D which gives WA on Test 27. Can somebody help me figure it out ? 114670308

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

Does anyone know why the rating change in the CF predictor is so different from the actual rating change?

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

hm? why so big delta between predictor and real rating changes?

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

Finally, after 14 months and 57 contests I have reached CM. Feels good :)

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

Why is the rating change so less than cf predictor?

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

How come CF-Predictor is showing +79 rating change but the actual rating change is only +48 for me while there are other accounts who have seen increase in their actual rating change :(

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

I think the positive delta is really low even after getting 2899 rank considering My previous ratings i should have got +120-130 but i only got +81. is it normal ?

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

    No.. of all the contests I have given this is the first time I have seen the actual rating change is less than the predicted rating change..

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

About the ongoing discussion about rating predictions in cf-predictor being wrong, I'd like to say something. The ratings of the people I've checked (including mine) are not up-to-date, that's probably the reason why the calculations of deltas are incorrect.

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

    By not up-to-date do you mean there will be a rating roll back soon and new ratings will be published ?

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

      I mean, I'm talking about "cf-predictor extension" and the calculation of yesterday's contest is based on our previous ratings, like the system is literally missing two last contests' rating changes. I don't know about any rating roll back and I didn't mean that.

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

Can anyone explain how did my code pass the tests on problem B? I accidentally wrote: int dp[102][102][250]; instead of: int dp[102][102][10100]; The submission: 114572709 The problem: 1519B - The Cake Is a Lie

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

    Your program used 102 as the size of the array instead of 101 so that you have some unused memory(1*102*250=25500>10000),so when you use index out of bound like dp[100][100][10000],the program actually use dp[101][40][...] without getting an Runtime Error.

    However,I think it will cause some reuse of the element,but I don't know how to hack it so far.

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

Why does my solution for problem C TLE in java?

My code is clearly O(n*log(n)) (the log is from sorting, O(n) otherwise) because when I reach k > than the size of a university I don't revisit this university just as other people (above) described. The exact same code in C++ gets AC. I know that Java is slower but usually in problems like this it should pass the time limit...

Java Submission: 114570376 CPP Submission: 114677079

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

Can anyone tell me why I'm getting TLE in the 8th test case in Problem C.

Here is my code:-

https://codeforces.com/contest/1519/submission/114668130

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

    Your last working cycle runs mx*n == n * n = 4*10^10 times, because in this test case it looks like there 200K students from only one university and you are checking n-1 empty universities n times.

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

    Consider a case where n/2 students are from university $$$1$$$ and the rest are from distinct universities. In this case, mx = n/2 and tmp = n/2+1. So your last loop takes O(n^2) time to run which exceeds the time limit.

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

Hello I'm new here. where can I find editorial for this contest? Thanks in advance.

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

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

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

Not in the top of the best hacker :(

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

    "+102 : -364" ?

    That was quite some effort! :O But maybe the ranking also takes the proportion right/wrong into account?

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

Can anyone help me in identifying the mistake in Problem D , the approach is similar to longest palindromic substring. It is failing in the 11th test case.

Link to the submission: https://codeforces.com/contest/1519/submission/114709341

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

    The question does not ask to compute the answer modulo $$$10^9 + 7$$$. Apart from that there are some issues with type conversion. I defined a and b as long long vectors and it got AC.

    114725389

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

Can anyone tell me why I'm getting TLE in the 8th test case in Problem C.

Here is my code:-

My code

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

    The loop that's looping on the universities should start with the lowest possible greater or equal to K, I mean when K = 4 you shouldn't iterate over teams that has number of people less than K, unless if you do iterate over them it would be O(N^2) a time limit for sure.