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

Автор diskoteka, 13 месяцев назад, По-русски

Привет! В 24.04.2023 17:35 (Московское время) начнётся Codeforces Round 867 (Div. 3) — очередной Codeforces раунд для третьего дивизиона. В этом раунде будет 6-8 задач, которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов. Мы постарались сделать приличные тесты — так же как и вы, мы будем расстроены, если у многих будут падать решения после окончания контеста.

Вам будет предложено 6-8 задач и 2 часа 15 минут на их решение.

Штраф за неверную попытку в этом раунде будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в пяти рейтинговых раундах (и решить в каждом из них хотя бы одну задачу)
  • не иметь в рейтинге точку 1900 или выше.

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

Спасибо MikeMirzayanov за платформы, а также Vladosiya за координацию нашей работы. Задачи были придуманы и написаны: diskoteka, pavlekn, playerr17, isosto.

Также большое спасибо: pashka, purplesyringa, Alexdat2000, I.Gleb, Serik2003, TkachDan, maksimb2008, _--, 74TrAkToR, Gornak40, ut-k8g, Rudro25, Jostic11, yorky, tolbi, AhmetKaan, Splatjov, BF_OF_Priety, vrintle, KoT_OsKaR за тестирование раунда и весьма полезные замечания.

Всем удачи!

UPD: Разбор задач

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

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

Problem A: find missing space

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

Really excited for this contest. Don't know why.(◠‿◠)

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

as a tester, I can assure that problemset is perfectly balanced , all problems are interesting and I recommend to read all the problems

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

As a participant, I will appreciate the work of authors and testers. Thank you for the contest!

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

As a !non-Tester, I tried to solve problems and give proper feedback. glhf

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

As an author, I wish all <1600 participants getting their free expert this round!

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

    practically and theoretically not possible

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

      :D

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

        Bro, That's surely a joke. No need to take everything serious in life. Chill out and enjoy every bit of it.

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

          :D :D :D From the downvotes, I think you're right.

          Lesson learned: Laugh at every nonsense on codeforces

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

            Don't think because of downvotes. I mean in general you should be not be serious all the time. It's not related just to codeforces. It applies to your daily life activities too. Just be chill and not serious all the time.

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

              1) You are saying not to take things seriously. but your username(handle) tells different story.

              2) I am 90 % sure, your spelling for LOSER is wrong.

              xD

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

this is gonna be my first contest! wahoo!

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

Как одна из тестировщиц раунда хочу сказать, что задачи интересны и приятны. Желаю всем участникам удачи и удовольствия от раунда!

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

As a participant, I will achieve a 4 long streak of losing rating in div3

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

it's not related to this blog :

can some one give me the list or easy to medium problems for DP to kickstart my learning ( like any difficulty wise or something ) for beginner level to medium and you can share any resources or suggestions ....

Thanks in advance!

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

Really excited for this contest. Looking forward to becoming a pupil soon:)

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

How can we be a tester? Plz don't downvote.

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

As a non tester....... how to be tester? (I thought only purple+ can test).

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

hope to become an expert

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

Give me contribution

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

How to hack a solution during contest?

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

    You can't in div3 or edu rounds. They have their seperate period of time for hacking after the contest.

    But for Div2 you can try that. Just lock the problems and go to room section. And start watching other people solution if you found some counter-testcase hack it.

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

    When the contest ends in some of them there is a phase called: The Open Breaking Phase. And it is in this phase that you must enter someone's solution and press the "Hack!" Soon you are given a choice on how you will hack: with a generator or a manual hack? For the generator you write the code for the test. For a manual one, you write the test by hand. But you can't hack during the contest, only after it.

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

yayyy my first contest!! let's so how it goes

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

    Welcome to the community on the behalf of specialist community Sir. Hope you have great time and learning.

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

Please provide hints and proofs for the problems along with editorials

It helps in upsolving and understanding concepts for beginners instead of directly jumping to solutions :)

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

This is my first round in Codeforces. I really want to get more ratings.

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

hoping for 160 + Delta. feels like mission impossible... xD

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

I'll try my best, wish me luck

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

glhf

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

Hope everyone after this contest will change color:)

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

I've participated in more than 5 rated contests and my rating is <1900 why I'm not in the official standings table?

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

    This is a div 3 contest which is rated only for accounts having less than 1600 rating.Your rating is greater than 1600,so you're not an official participant.

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

      The blog mentioned 1900, right? 2nd bullet in 5th paragraph?

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

        That just mean that your are a trusted participant

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

        You are a participant of the third division if and only if you currently have rating less than 1600. This can be seen in the fact that only < 1600 rated participants are rated in a Div.3 contest.

        If you are a trusted participant of the third division, it is assumed that you must be a participant of the third division (i.e. have rating < 1600). The two constraints are extra for determining if you show up on the official leaderboard.

        Here "do not have a point of 1900 or higher in the rating" means that if you have reached 1900 rating and then dropped back to < 1600 rating, you will not be considered a trusted participant of the third division and you will not show up on the official leaderboard. But the contest will be rated for you.

        You are not a participant of the third division; thus you don't show up on the official leaderboard.

        I agree that the wording is quite unclear.

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

is there anyone else who did not read the problem C properly and just guessed the solution from sample test cases?

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

did g and f leak? Sudden increase in submissions for both

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

When can you submit in practice?

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

How to do G2?

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

    Trick : number of factors of a number (10^9) that are perfect squares is less than 100

    Somehow iterate over those factors...

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

    $$$a[i] \cdot b \cdot b=a[k]$$$

    if $$$a[i] \leq b$$$ then $$$a[i]^3 \leq a[k]$$$

    if $$$a[i] > b$$$ then $$$b^3 \leq a[k]$$$

    So you can solve problem in $$$O(N \cdot M^\frac{1}{3} \cdot logN)$$$

    My solution works ~1200 ms.

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

    You need no fancy algorithms. Casework on if the common ratio is greater than the first term. For each $$$a_i$$$, enumerate the common ratio from $$$2$$$ to $$$(a_i)^{\frac{1}{3}}$$$ to count the number of triples where the common ratio is less than the first term where $$$a_i$$$ is the greatest term, and then if $$$a_i\le 10^6$$$, enumerate the first term from $$$1$$$ to (and excluding) $$$(a_i)^{\frac{1}{2}}$$$ to count the number of triples where the common ratio is greater than the first term and $$$a_i$$$ is the middle term. Remember to add the case of three equal terms.

    This runs in $$$O(MAX^{\frac{1}{3}}n)$$$ using a custom hash unordered map. Implementation at https://codeforces.com/contest/1822/submission/203344438

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

Thanks a ton for such a contest. Getting to Expert in style :)

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

Is G2 based on the fact like finding all unique GPs of common ratio upto 30 then doing some trick(no idea) to find GPs of ratio greater than 30 also using the GPs of common ratio upto 30?

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

Finally Expert this time.

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

Such a great contest, really loved it, Problem F was the nicest and cute problem!

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

As a pupil I'm becoming a newbie

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

What was the logic in problem C? I guessed from the test cases.

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

    for D also, I found the pattern, but couldn't solve it

    Am I becoming a pattern recognition model?
  • »
    »
    13 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Same i just copy pasted from oeis.

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

    For C, I saw that:

    • There are 4 edges with length $$$n$$$, which are the edges of the square as well.

    • In the square, the length of each adjacency edges is decrease from $$$n - 1$$$ to 1, and $$$n - 2$$$ to 1.

    • In the middle, there is an edge with length 1.

    In conclusion, the formula I used without simplifying is: $$$4 * n + sum(n - 1) + sum(n - 2) + 1$$$ (Note that $$$sum(k)$$$ is the sum of the sequence from 1 to k).

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

    n * (n + 1) + n + 2 I reached at this after a lot of rough work but its sad to see people directly guessed the test cases or used WolframAlpha/Oesis to guess the pattern.

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

      Personally I also used WolframAlpha, because I didn't remember how to solve recurrence relations. I think this is a weakness of CodeForces, maybe especially in the lower ranks: a lot of problems are really math problems more than coding problems.

      Incidentally, the problem could also be solved by brute-force without finding a closed-form solution.

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

        it seems to me it gets compiler optimized, because otherwise this would be O(max) which is too high.

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

          The compiler has optimized it somewhat (in a pretty impressive way actually) but it has not eliminated the loop, so it is still O(max). You can see the optimized code here: https://gcc.godbolt.org/z/K413jocrE

          The inner loop is still present but it's very compact:

          .loop:
                  add     rdx, rax
                  add     rax, 2
                  cmp     rax, rcx
                  jne     .loop
          

          This is fast enough to do a billion iterations in 3 seconds on a reasonably modern CPU.

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

      Is wolframalpha a math formula solver website? And Oesis is for finding sequences?

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

        OEIS is the Online Encyclopedia of Integer Sequences: https://oeis.org/

        Wolfram Alpha is a solver for mathematical functions in a very broad sense. For this problem you could feed it 26 + sum x=5..n (2x + 1) or f(4) = 26, f(n) = f(n - 1) + 2n + 1 and it would calculate a closed-form expression for you.

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

I saw problem E before in codechef but with minimum difference prob

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

Why TLE?

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

    There are two problems here:

    1. a check like mp[v[j]*r] > 0 is relatively costly because it will insert an element into the map if it didn't exist before. It would be better to use map::count() or map::find() to check if an entry is present without modifying the map contents.

    2. you should probably break out of the inner loop when v[j]*r*r is larger than the maximum value in v, otherwise you end up doing 1000×N = 100 million iterations in the worst case.

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

      AC Thanks A Lot. 3900 ms.

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

Problem G1 :

when I use vector freq((int)1e6 + 1);

I got TLE

after replace it with int freq[(int)1e6+1];

I got Acc

How can this happens?? If I use array by luck I got Acc!! it's bad tests

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

A: If a[i]+i-1<=t we can choose the i-th video.

B: First we can choose (i, j) where a[i]*a[j] is the maximum product and remove all other elements. We sort all non-zero elements in a[i] and consider the maximum non-zero product. If there's less than 2 non-zero elements, the answer is 0. If there's 2 non-zero elements, the maximum non-zero product is their product. Otherwise, there must be 2 elements with same sign, and their product will be positive. We need to pick 2 elements with same sign and maximum absolute value to get the maximum product.

C: The answer is (n+1)^2+1 (by looking at examples), but how to prove it? Well, if we change the size of a cinnabon roll from n-1 to n, we need to add 2*n+2 chocolate outside, add 1 chocolate and remove 2 chocolate inside, so we have ans(n)=ans(n-1)+(2*n+1). Therefore we can get answer by induction.

graph explanation

D: First if i>1 and a[i]=n, we have b[i]=(b[i-1]+n)%n=b[i-1], so b[i] cannot be a permutaion, then we have a[1]=n. If n is odd, (n+1)/2 is integer, then we have b[1]=a[1]%n=0, b[n]=(1+2+...+n)%n=(n*(n+1)/2)%n=0, so b[i] cannot be a permutaion. If n is even, let a={n, n-1, 2, n-3, 4, n-5, ...}, then b={0, n-1, 1, n-2, 2, n-3, ...} is a permutaion.

E: If n is odd there's no solution. If there's any char c that there are more than n/2 occurences of c, there's no solution because by the piegonhole principle, there are n/2 pairs of symmetric positions and there are more than n/2 occurences of c, so there must be a pair of positions occupied by c. Otherwise, solution must exist. To calculate the minimum number of operations, let's see what can we do in one operation: For something like ..a..b..|..b..a.. (where '|' denotes the axis of symmetry), we can swap (ba) to turn it into ..a..b..|..a..b.. and remove 2 bad pairs; for something like ..a..b..|..b..c, we can swap (bc) to turn it into ..a..b..|..c..b and remove 1 bad pair. In other words, we can remove 2 different bad pairs or 1 bad pair in one operation. So we can calculate the number of bad pairs of chars from 'a' to 'z' and then we can get the answer.

F: Let ecc[i]=max(1<=j<=n)(dist(i, j)), then the cost of the tree rooted at i is k*ecc[i], and the cost of moving root from 1 to i is c*dist(1, i), so the answer is k*ecc[i]-c*dist(1, i). We can calculate dist(1, i) by BFS, and to find ecc[i] we can find a diameter of the tree, if (u, v) is a diameter, then ecc[i]=max(dist(u, i), dist(v, i)).

G1: The number of good triples where b==1 is sum(cnt[t]*(cnt[t]-1)*(cnt[t]-2)) where t iterate over all values of a[i], so we assume b>=2 for other good triples. For each possible value of k, we can see the maximum possible value of b is not greater than sqrt(a[k]), so the contribution of k is sum(cnt[a[k]/b]*cnt[a[k]/(b*b)]) where 1<=b, b*b<=k. The complexity is O(n*sqrt(A)).

G2: To optimize the solution of G1, we can see that if a[k]/(b*b) is integer, let c=a[k]/(b*b), we have a[k]=b*b*c, then we have b<=cbrt(a[k]) or c<=cbrt(a[k]), so we can find all possible combinations of (b, c) in O(cbrt(a[k])). We can solve the problem in O(n*cbrt(A)) using Hashmap or O(n*log(n)*cbrt(A)) using Treemap for checking cnt[t].

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

    I don't really get the difference in ACC between G1 and G2, the difference in difficulty does not seem that big.

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

      Because many people thought it would be related to some advanced topic like convolution and left

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

    For E, I did i = [0, n/2] and if ( s[i] == s[n-i-1] ) count++; Now, return ceil(count/2). What's wrong with this?

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

    really nice solution for G2!!

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

    Hi, for G2, isn't O(n*log(n)*cbrt(A)) around 1e9? I tried the method and it indeed passes, which is really weird to me. Another weird thing is I used std::map in G1 initially and it TLEed (complexity is O(nlogn sqrt(A)), so should be same, as in G1 A=1e6 and in G2 A=1e9), so I guess the test cases are built such that O(n*log(n)*1000) passes for G2 (and only in G2)?

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

global arrays >>>> unordered_map<int, int, custom_hash> :(

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

deleted

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

Can someone explain why my solution to G1 is timing out? https://codeforces.com/contest/1822/submission/203347556

Basically I check all possibilities for the middle element. For each distinct element a, I go through all factors x of a and add up (# of a/x)*(# of a)*(# of xa). This should take O(120n) since each number in [1, 10^6] has <=120 factors, which should pass; however, it TLEs. Can someone help? Thank you.

  • »
    »
    13 месяцев назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится
        for (int x=1; x<=1000000; x++){
          if (c[x]>=3) T+= c[x]*(c[x]-1)*(c[x]-2);
        }
    

    This code block will be executed for each testcase, and there can be 10^4 testcases, so the code will run for 10^10 times.

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

Problem statement C was very hard to understand. At least for me.

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

Небольшие заметки о том, как решать все задачи из этого контеста с ссылками на исходники на C++.

Задача A
Задача B
Задача C
Задача D
Задача E
Задача F
Задача G2

Скопипастил то, что Slamur написал в Telegram-канал:

Задача F от Slamur за линейное время без структур
»
13 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Could someone explain problem D?

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

    There is to cases : n is even or odd, if it is odd the answer will -1, odd numbers will give two same numbers in mod operation so there is no solution, the corner case of odd numbers is 1 because it has legnth 1, the second case : if it is even the answer will begin with n then n-1, and flip between odd and even numbers from 2 and n-3, this is a valid solution like test case 4.

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

      For the case that n is even, I can't figure out the way to assign the permutation with $$$n, n - 1, 2, n - 3, 4,...$$$ like that. Is there any trick to come up with it?

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

I want to ask why the problem G1 my code's time complexity is (2e5*ln1e6) , but I get several times Time Limit Exceed? Can someone help?Thank you very much! This is my code:

#pragma GCC optmize(3)
#pragma GCC optmize(2)
#pragma GCC optmize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
const int N=1000010,mod=1e9+7;
int a[N],n;
long long c[N];
int b[200010];
void solve()
{
	cin>>n;
	int mx=0;
	for (int i=1;i<=n;i++)
	{
		cin>>b[i];
		c[b[i]]=-1;
		a[b[i]]++;
		mx=max(mx,b[i]);
	}
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		long long res=0;
		if (c[b[i]]!=-1)
		{
			ans+=c[b[i]];
			continue;
		}
		if (a[b[i]]>=3)
			res=res+(a[b[i]]-1)*(a[b[i]]-2);
		for (int j=2;j<=mx/b[i];j++)
			if (b[i]%j==0)
				res=res+a[b[i]/j]*a[b[i]*j];
		ans+=res;	
		c[b[i]]=res;			
	}
	for (int i=1;i<=n;i++)
		a[b[i]]=0;
	cout<<ans<<'\n';
}
signed main()
{
	cin.tie(0)->sync_with_stdio(false);
	int t=1;
	cin>>t;
	while (t--)
		solve();
}
  • »
    »
    13 месяцев назад, # ^ |
    Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

    If $$$b = [1000000, 1, 1, ..., 1]$$$, then $$$mx = 1000000$$$ and $$$mx / b[i] = mx$$$ for every $$$b[i] == 1$$$ which means that the inner for loop iterates from 2 to $$$mx$$$ on every iteration. Your complexity is $$$O(n * mx)$$$.

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

      But I have the code' if (c[b[i]]!=-1) continue' to skip the repeat b[i],so every b[i]==1 just can operate one time.

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

        Oh, I missed that line. But the complexity of your code is still at least $$$O(test cases * mx)$$$ though. Consider $$$1e4$$$ test cases of the array $$$b = [1000000, 1]$$$. Your inner for loop would make $$$mx$$$ iterations every time since you are resetting $$$c$$$ in every test case.

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

hacked :(

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

What is the expected rating of problem E?

»
13 месяцев назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится
  • What is the expected rating of problem E?
  • What is mostly rating range of problem E in Div 3?
  • What is mostly rating range of problem D in div2?
»
13 месяцев назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Wonderful div3 round,i learned new things this round.Thanks to problemsetters!

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

Any hint or idea for problem D ?

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

    for i > 1; let a[i] = n; thus, b[i] = (b[i — 1] + n) % n = b[i — 1]; not possible since b is permutation; thus a[1] = n and b[1] = 0;

    if n is odd : b[n] = (n*(n + 1)/2) % n; n + 1 is even; b[n] % n = 0 but b[1] = 0; thus no "-1" if n is even : b[i] — b[i — 1] must be unique; here i think you need to use pen paper to observe or just check the last sample case;

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

Why does G1 has to have so tight constraints I submitted it in python and got that question hacked. Please make it fair for all languages. Atleast try to make in python and c++ many beginners use python.

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

    Actually it's not about python speed. In fact, pypy3 is fast enough to pass this problem. it is because someone generate a special test case to make python code that use dictionary to be TLE.

    You can sort the array before putting them into the dictionary, and it will be accepted. Here is your accepted code: 203372619

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

A rated round should not have had problem F. Its a blatant copy of the general standard problem of finding max distance of a node from each node of a tree. https://cses.fi/problemset/task/1132.

I highly doubt setters were unaware of this since its literally in cses. Please unrate the round in the future before pulling such schenanigans. Contest is not meant to copypaste submission and modify 2- 3 lines to get AC. (I say this as someone who got the problem in under 4 mins due to this exact reason)

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

    is not wanting cses problems to appear in cf rounds bad? :(

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

      It is not a good problem, but there is no reason why the round should be unrated, espically since div. 3 rounds are supposed to be educational anyways. The problem is also not a copy of the cses problem and no evidence suggests that.

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

        I didn't say the round should be unrated, rather such a problem shouldnt ever show on rated rounds, a minute difference being that i dont call for this round to be unrated, just any future ones trying to use cses problems.

        As for the copying part, cses problem : find max distance from each node, div3 problem : find max distance from each node, call it dist, and output max(k * dist — c * depth) instead

        Adding one extra step makes it non copied? (I do not joke when i say i only had to change 3 lines in my cses code aside from clearing global arrays due to this being multitest)

        Educational rounds can manage without having problems directly from cses, im sure div3 can too.

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

    This problem had same thing https://codeforces.com/contest/1805/problem/D.
    My solution which uses the cses questions code https://codeforces.com/contest/1805/submission/200411445.

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

      that problem required many other observations, div3F was more of a direct copy.

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

      I dont agree actually, yes that problem had a subpart which was basically that cses problem, but reducing it to that was a step, and not a small one to me.

      This problem is just directly asking for the ezact same thing as the cses one.

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

    It is quite standard, but not a direct copy, so there should be no reason to be unrated

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

Could please someone explain why this submission of G2 TLE's

My calculation of complexity
  • »
    »
    13 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    First of all, $$$2 \cdot 10^9$$$ operations may TLE regardless due to the high constant factor of std::map. The reason why your solution gets TLE is due to multitest cases, which your calculation does not take into account. The test that your code failed on is just $$$10000$$$ copies of this test:

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

My current rating is 401. I've submitted solution of 5 problems of Codeforces Round #867 (Div.3), and all submissions was accepted. a This is my 2nd contest, but still my rating is not increased. Can anyone tell why?

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

To be honest ,I still do not understand Problem C,but just by observing the test cases,I came out to the solution

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

    check out YocyCraft solution above in comments. He's explained it pretty well.

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

    Just add 4n (outer layer), Σ(n-1), Σ(n-2) and 1. You can observe the pattern of the chocolates. But yes, it was decipherable from the test cases.

    On the other hand, I got problem-D AC by guessing the pattern from test cases. Odd numbers dont have solutions, and for even, start by placing n at the beginning, and n/2 in the middle, and on both sides of n/2, place the numbers n-1, n-2, n-3, etc, but in alternating order on left and right sides

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

Is there anyone like me who like Div 2 rounds more than the Div 3 ones?

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

    Yeah, me. I was able to solve A-D in this contest, out of which A,B were very easy, and C,D were guesswork from testcases. I got good rating change, but didnt teach me anything.

    On the other hand, altho I usually lose rating in Div 2 rounds, There's always something I learn, either during the contest or after it.

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

I'm new in contestant in Codeforces. I wanna clear that is Codeforces Round 867 (Div. 3) was a rated contest? I solved two problem(A & C) but my rating/rank is looks like that...

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

    It is a rated contest. Since the rating change is not completed yet, it doesn't show the rank. It will be updated as soon as the rating change is completed.

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

This is the first time ever I solve a div3 F instantly. I can't believe that there was a time when I struggle to solve div3 E. It feels pretty amazing

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

no way,i think e is harder than f and g1 XD

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

Hello friends, I have uploaded the video editorial of this contest from A to F. Editorial. If want, You can watch it!!!

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

I feel like problem C and D are just "guess correct solution" problems / see pattern. Is this kind of problems okey for you guys?

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

can i reach expert from current rating of 1529 rank in standings is 1189

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

Hello! I'm kinda new here so please don't be soo critical T_T for the first problem this works fine on my codeblocks but for some reason it gives different outputs when submitted https://codeforces.com/contest/1822/submission/203327103

and what is more confusing is that the output change when I change the variables type from int to ll Can someone please help me T_T

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

    This line - for(int i=0;i<n;i++) { cin>>b[n]; } should be- for(int i=0;i<n;i++) { cin>>b[i]; }

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

I don't know why i am unrated even though it's division 3 and I'm a newbie who participated first contest in Codeforces. can someone explain why for me?

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

    It's not unrated for you. You are just not a trusted participant yet. You need to participate in atleast 5 contests to be a trusted participant. The round will still be rated for you, it's just that you will not be in the official standings for the contest.

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

Is the round unrated? I am below 1600 and have participated in a lot of CF contests, still it is unrated for me, anyone know why?

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

Can someone explain why my code got accepted in the contest, now after system testing it's showing TLE there weren't any pretests as far as I remember.

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

    New test cases created/generated by participants during the hacking phase are added to the original set of test cases. During system testing, the solutions are rejudged with this new set of test cases. Your code might be failing on the new test cases.

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

    after the contest ends hacks and more test cases are added to the original test cases

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

Why I did not get contest rating points despite solving 3 problems?

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

when will my race get updated?

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

when will updated??

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

Pretty bad systests for G2 O(sqrt(a[i])*n*log(n)) with some small constant optimisations is AC

[upd] all hash tables(with custom hash also) instead of map give TL, which is quite funny

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

    Yeah the tests are really weird.

    Edit: Wait you mean sqrt instead of qbrt? That would be roughly 1e11 right? How on earth can this pass.

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

Has anyone solved Problem F using Rerooting?

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

Can someone hack these solutions? solution1 solution2

They both failed on this test case:

Spoiler

UPD:Thank's pavlekn for hacking them

»
13 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
#include<bits/stdc++.h>
//#pragma GCC optimize(3)
#define int long long
using namespace std;
const int N=200005;
int a[N],n,T;
map<int,int> mp;
signed main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;
		mp.clear();
		for (int i=1;i<=n;i++)
		{
			cin>>a[i],mp[a[i]]++;
		}
		sort(a+1,a+n+1);
		int ans=0;
		for (auto u : mp)
		{
			int x=u.first,res=u.second;
			ans+=res*(res-1)*(res-2);
			//cout<<x<<" "<<res<<endl;
			if (1*1!=x) ans+=mp[1]*res*mp[x*x];
			for (int b=2;b*b<=x&&b*x<=1e9;b++)
			{
				if (x%b!=0) continue;
				if (mp.count(x/b)&&mp.count(x*b)) ans+=mp[x/b]*res*mp[x*b];
				if (b*b!=x&&mp.count(b)&&mp.count(x*x/b)) ans+=mp[b]*res*mp[x*(x/b)];
			}
		}
		cout<<ans<<endl;
		//cout<<mp.count(2)<<endl;
	}
	return 0;
}

This is my code for problem G2, it got Accepted. But if I use a std::vector to traversal all numbers,it
get TLE 203456289. Why std::vector is so slow and std::map is efficient?

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

For problem F, I only considered one endpoint of the diameter and didn't consider the other one, but it still passed tests. Why does that work? The endpoint I considered was the furthest node from 1.

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

    If you are already on the diameter then the cost to get to the closer end will be <= to the cost to get to the furthest end (and it's obviously optimal to stay on the diameter).

    If you aren't on the diameter every move will change the distance to both ends of the diameter by the same amount until you reach the diameter (at which point you move to the closer end).

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

I think i have used ideone in public mode by mistake and I was absolutely unaware that someone can see my solution there because of which my solution has been copied by somebody/ or it can be an absolute coincidence! Sorry for this but I will take care of it from next time while using ideone. Please have a look into this . MikeMirzayanov . Question F of the recent div3 round caused this issue :( . Please revert back my ratings . 203313670 Submission ID for the question . Please revert back my ratings

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

So my solutions for B and C have been reported as cheating, since they are too similar to others (from https://codeforces.com/profile/KudoConan) B: Mine: https://codeforces.com/contest/1822/submission/203276161 His: https://codeforces.com/contest/1822/submission/203330555 C: Mine: https://codeforces.com/contest/1822/submission/203281804 His: https://codeforces.com/contest/1822/submission/203329843

As you can see they are almost excactly the same. I don't know what to do now, since i have not shared my code with anyone and as you can see my submissions have been an hour before his. Since the solution are very "easy" and there isn't much room for different approaches in Python it feels like there should be a lot of similar solutions for these problems.

Well I guess the only evidence I have is that his A is different from mine and that I also solved D and E, still I am not sure what to do, if there is anything I can provide please let me know.

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

I got TLE on problem G1: https://codeforces.com/contest/1822/submission/212707167 I find that max divisor up to 1e6 = 240. So time complexity should be O(n*(max_divisors + logn)), which fits the time limit. can someone help me with this?

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

Can someone explain that how we reach to the permutation in D.