Vladosiya's blog

By Vladosiya, history, 14 months ago, translation, In English

Hello! Codeforces Round 903 (Div. 3) will start at Oct/12/2023 17:35 (Moscow time). You will be offered 6-8 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have a rating of 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ICPC). Thus, solutions will be judged on preliminary tests during the round, and after the round, it will be a 12-hour phase of open hacks.

You will be given 7 problems and 2 hours and 15 minutes to solve them.

Note that the penalty for the wrong submission in this round is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them)
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Problems have been created and written by our team: myav, Gornak40, senjougaharin and Vladosiya.

We would like to thank:

  1. MikeMirzayanov for Polygon and Codeforces platforms.

  2. SomethingNew, rniya, zwezdinv for red testing.

  3. makrav, snowysecret, AlexanderL, KseniaShk, pavlekn for yellow testing.

  4. gigabuffoon, EgorUlin, KerakTelor, Pa_sha, I_love_geom, petyb, MinaRagy06, toniskrijelj, FynjyBath for purple testing.

  5. Abo_Samrah, dan_dolmatov, pedrosorio, ezdp, azureglow, Chrisedyong, Apachee, arseny2606 for blue testing.

  6. t0rtik, Sergey140146659, hader239, Modern for cyan testing.

  7. mkshh, petertromso for green testing.

Good luck!

UPD: Editorial

  • Vote: I like it
  • +243
  • Vote: I do not like it

| Write comment?
»
14 months ago, # |
  Vote: I like it +4 Vote: I do not like it

Waiting for that round. Hopefully, It will be a great round for me. Best of luck to all contestants :)

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I hope This contest to be my promotion contest, I wish (:

»
14 months ago, # |
  Vote: I like it +25 Vote: I do not like it

As a green tester I can ensure green participants that they will enjoy this round!

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why's this not on the home page yet?

»
14 months ago, # |
  Vote: I like it +3 Vote: I do not like it

As a tester I hope, that contest will be very interesting for all participants!

»
14 months ago, # |
  Vote: I like it +10 Vote: I do not like it

As a tester, I hope that this contest will be enjoyed by all participants. Read all problems and good luck! ฅ^•ﻌ•^ฅ

»
14 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Deleted

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

sory i can`t get a think in line 11 you sed"do not have a point of 1900 or higher in the rating." but in line below it you say "Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you." so is that contest rated for experts or not ?

  • »
    »
    14 months ago, # ^ |
    Rev. 2   Vote: I like it +10 Vote: I do not like it

    It's not, it's just people who at least once reached 1900 will not get in the official standings(though if their current rating is below 1600, the round still will be rated for them).

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Ez Expert for me

»
14 months ago, # |
  Vote: I like it +2 Vote: I do not like it

At least we know that there will be no bitset problems :)

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Waiting eagerly. Best of luck to everyone :)

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I'm not welcome for Div.4 anymore so I must bring out my best in Div.3!

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hoping to become an expert this round.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Your graph looks exactly like mine!!!! OMG :)

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Do you guys give contests together? /s

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        what do you mean? I am from lebanon, bro is from india...

»
14 months ago, # |
  Vote: I like it +2 Vote: I do not like it

Need more div.2 rounds

»
14 months ago, # |
  Vote: I like it +3 Vote: I do not like it

As a tester, I hope the problems will be enjoyable for you!

»
14 months ago, # |
  Vote: I like it -8 Vote: I do not like it

For the life of me, I will never understand why a Div3 contest has 4 times the Expert+ testers as cyan/green testers. Who are these contests even aimed for?

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone else who just saw a message that the contest has started right now?

»
14 months ago, # |
  Vote: I like it +29 Vote: I do not like it

As a late "as a tester comment", I beg for contribution

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Going to become Expert.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    hack like 20 people and it is very possible predictor says you are 3 points short

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      make it 2000 people cause your solution to A got hacked

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        We don't get points for hacking in div 3.

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Never felt dumber with a div3C.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

First time to solve till F, my best performance in div3 :)

Guess which problem took my time most
»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve D ?

  • »
    »
    14 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Prime factorize every number and count all the primes. if all the prime count is divisible by n then yes

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How did u come up with this? Is there any reference?

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Note that over any operation, product of all numbers is invariant. Thus, if the final state of all numbers is $$$g$$$, then $$$\prod_{i=1}^na_i = g^n$$$. Thus, for the final state to be achieved, product of all numbers must be a perfect $$$n$$$-th power. Turns out this is sufficient as well. (Why? Hint: Think of how primes will be distributed)

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      would clarify the relation between N and number of all primes ?

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        You can find out all primes no more than N in O(N) using Euler sieve.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Find the prime factors of each element and count the total number of occurrences of each prime factor. If all the total number can be divisible by n, then output YES.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Anyone found the A,B,C much annoying problems.. this div3 contest must have focussed on the problems D,E,F ... rather than keeping the participants to got stuck at A,B,C these days...!

»
14 months ago, # |
  Vote: I like it +16 Vote: I do not like it

C was so annoying , D < C

»
14 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

D, E, F were interesting but i found A a little difficult for div3 A unless there is a trick that i couldn't see. Edit: Thanks got it.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    A was just bruteforce, that is usually the case, you can just add s to itself a few times until you get to a fairly big size where you are sure the substr won't appear again and use .find() to check if m is a substring. The strings can only get to like 100 so checking till 200 does the trick.

  • »
    »
    14 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    You could just naively check for at most $$$12$$$ operations or so. Time complexity would be $$$O(2^{12}nm)$$$ which is definitely not optimal, but anyways there are not too many testcases so it can't hurt to try too much

    UPD: $$$k=12$$$ got hacked, maybe try something smaller like $$$k=6$$$

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Any Hints for F? I was finding max and smax ( max and smax will be maximum and second maximun marked node from children ) and considering maximum distance from a node will be max( max distance from children (max) , distance from parent + 1 (max+1 or smax+1) ).

  • »
    »
    14 months ago, # ^ |
    Rev. 27   Vote: I like it +8 Vote: I do not like it

    Problem F

    Hint

    Claim

    You don't need to calculate distance from every marked vertex. Just calculate distance from the two marked vertices x and y, such that distance(x, y) >= distance(i, j) for all pairs i and j where 1 <= i, j <= n' and 'i ≠ j. This is sufficient.

    Proof

    Let's assume that x and y are the two marked vertices with the maximum distance between them.

    Now, suppose there exists pair of vertices v and z in the tree such that distance(v, z) > max{distance(v, x), distance(v, y)}.

    We can claim that: max{distance(z, y), distance(z, x)} == distance(z, v) + max{distance(v, x), distance(v, y)} > distance(x, y).

    However, this statement contradicts the fact that x and y are the pair of marked vertices with the maximum distance between them. That means there's no such z and v.

    So, you only need to calculate distances from vertices x and y to satisfy the given condition.

    Formula

    $$$f(i) = max(distance(i, x), distance(i, y))$$$ where $$$(1 \le i \le n)$$$ and $$$(x, y)$$$ are the two marked vertices with the maximum distance between them.

    Time complexity: O(n) at most 4 tree traversal. two for finding (x, y). two for calculating distances.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

What is the level of complexity of problem E in terms of rating? Is it like the 1600 problem?

»
14 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Many of F solutions have been done using some segtree, or dp....
But mine i just did tree trimming....

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

i feel E tests are weak (check my solution)

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hi can anyone help me check my solution for D why it WA3? I had to change the loop to a get prime factorial function but I don't see where this one goes wrong. Thanks in advance https://codeforces.net/contest/1881/submission/227896125

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    you should write clear code and use different variables , your loop conditions might get altered because of value of n.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You're only storing the factors which are <=1000. But there maybe factors >1000 for the given constraints. Try as an example [2182, 2186], the output should be NO, but your code gives YES.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

It is very sad to say that I have solved B and C, which is normal for a 'pupil', BUT I couldn't pass A :(

Can someone tell me which test case can spoil my code ? 227915244

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    most probably try larger value of i, like 5 or 10.

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I have tried after the contest and got wrong answer. 227927816

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can you try this?

      My Code

      Also please note, it's a logarithmic function.

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it +5 Vote: I do not like it

        Yeah! I replaced my check function with

        bool check(string s1, string s2) {
            if (s1.find(s2) != string::npos)
                return true;
            return false;
        }
        

        And I got accepted. Thank you

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    If x="abc", s="cabcab", your code will get a wrong answer.

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Isn't the answer 2 ?

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Sorry, I gave a wrong example. I think you should modify your check function. Once s1[i]!=s2[j] and j!=0, maybe you should change i to i-j+1.

        • »
          »
          »
          »
          »
          14 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          I tried to use this:

          bool check(string s1, string s2) {
              if (s1.find(s2) != string::npos)
                  return true;
              return false;
          }
          

          And it works. I am so sad for what I did. It is a silly mistake :( I hope I don't turn to grey again.

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        For example, if x="abcabcabd", s="abcabd", your check will fail when i=5, j=5, and then you only change j to 0, but i is still 5, which makes you can't find the right match: i=3.

        • »
          »
          »
          »
          »
          14 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Oh okay, Thank you for your illustration sir

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    How did you solve B >_<

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Your goal is to make all values similar to the smallest value in the given array. This makes you use less steps otherwise, you need to use more than 3 steps for sure. Let's call the smallest value in the array ('mn'). Also you have to make sure that all values in the array are divisible by 'mn'

      Check my code 227853520

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

is the contest not rated for div4? made account on cf few weeks back and still a newbie, though i solved 2 problems but my rating didn't change

»
14 months ago, # |
  Vote: I like it +7 Vote: I do not like it

A — Annoying.

»
14 months ago, # |
  Vote: I like it +8 Vote: I do not like it

balanced contest overall. it's disappointing i wasn't able to solve E because i haven't learned dp yet :(

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can problem F using bfs many source?. I can't implement it during the contest

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +7 Vote: I do not like it

    Multi source bfs gives nearest red vextex not farthest

»
14 months ago, # |
Rev. 2   Vote: I like it +15 Vote: I do not like it

I felt that today's E was similar (in terms of statement, not solution) to 1798E.

Also, great problemset!

»
14 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Is there a more elegant way to solve F than some very annoying-to-implement tree DP? (Check my submission for my details)

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +19 Vote: I do not like it

    You need to calculate the diameter of tree (say $$$d$$$), considering the marked nodes as the ends. Now, intuitively the required node should lie in between this diameter, so distance would be $$$\lceil \frac{d}{2} \rceil$$$

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Not as annoying as mine XD (227924103)

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve C?

  • »
    »
    14 months ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    let ip= n-i-1 , jp = n-j-1. cells with indices (i,j) , (j,ip) , (ip,jp) , (jp,i) should be equal for each 0 <= i, j < n

»
14 months ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Can anyone tell me the 371st test for test case 2 in Problem G?

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

If someone prefers video explanations or interested in knowing how to think in a live contest or reach to a particular solution.
Here is my live Screencast of solving problems [A -> E] (with detailed commentary in Hindi language).

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why are there so many hacks on A? What is the hack?

Also: https://codeforces.net/contest/1881/submission/227851818

This looks kinda sus, to escape plagiarism checker?

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    Hack TC
  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    He's definitely a cheater, I see no point int having an infinite while loop with a break statement.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Is my solution for problem A hackable

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Nice ProblemSet :)

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Maximum possible answer in problem A can be log2(m)+1 . Isn't it?

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

A,B,C,D were tougher than usual div3.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Code for generating a testcase to check TLE for problem A

https://ideone.com/c8Rs0m

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Is using unordered_map in D correct? Shouldn't it give tle? https://codeforces.net/contest/1881/submission/227902139

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's fine. Input constraints guarantee there are at most $$$10^4$$$ values, each less than or equal to $$$10^6$$$, which means up to 20 factors per value ($$$2^{20} > 10^6$$$), so a total of ~200,000 prime factors to add to the map.

»
14 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I think problem F is to find the spanning tree connecting the selected vertices and then get the diameter r->(r+1)/2 as the result but I don't know how to code it. is my idea correct??

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes, the idea is correct. Maybe you can use the fact that on the smallest tree spanning the marked vertices, every leaf node MUST be a marked vertex. So, root the tree on some arbitrary marked vertex, and trim the leaf nodes until all leaf nodes are marked vertices.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I had the idea for the problem F but ran into a bug and ended up wasting my time :3

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

A friendly contest to beginners! Although my B FST... :|

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

everyone seems to be overcomplicating B observation: we can divide a, b, c each into threads of size equal to the greatest common divisor of a, b, c. this will always be optimal therefore, the number of operations would be equal to: ceil((a + b + c) / gcd(a, gcd(b, c)) / 2) (it only takes 1 operations to split into 2 equal threads

»
14 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Hello everyone, I am in bit trouble, I have tried to solve the first question of the contest but I am unable to debug it up. If anyone can help me, I will be very thankful. Thanks My submission

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why this code always work for Problem D?


void solve() { double n; cin >> n; double m = 1; double s = 1.0 / n; f(i, 0, n) { int x; cin >> x; m *= pow(x, s); } // cnl(m); double a = ceil(m), b = floor(m); if (abs(m - a) < 1e-6 || abs(m - b) < 1e-6) cnl("YES"); else cnl("NO"); }
  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's doing the same thing as other's have mentioned above. If the answer is yes, m will be an integer the way it is being calculated

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Question A: What data can be used for hack

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hello, how do I solve 1881G - Anya and the Mysterious String with Segment tree using Lazy propogation? This is what I've done 227967016, I haven't used Lazy propogation and it's TLE.

Thank you in advance.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hackforces again ;)

»
14 months ago, # |
  Vote: I like it +2 Vote: I do not like it

problem A was very bad for div3.

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Can anyone check this i am getting wrong answer in test case 4 for Problem G

here's my submission : 227971449

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

My solution was hacked yesterday, again I submitted the same solution and it got accepted. Do the test cases used in hacking not get added to the main test-case?

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    they will get added after the hacking phase is finished, at the time of system testing.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please explain E. Block Sequence as dp states please and also suggest similar problems

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Let $$$dp[i]$$$ denote the minimum number of deletions for the suffix starting on the $$$i$$$-th element: $$$a[i..n]$$$. Base case will be $$$dp[n + 1] = 0$$$.

    For $$$dp[i]$$$, we can either delete or take it. If we delete it then $$$dp[i] = dp[i + 1] + 1$$$. If we take it, then the problem reduces to the suffix starting on the $$$j = (i + a[i] + 1)$$$-th element: $$$a[j..n]$$$. So $$$dp[i] = dp[i + a[i] + 1]$$$. We take the minimum.

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anybody help me figure out why there is TLE in this solution (Problem D)?

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Ignoring TLE, your solution is wrong. For the test case $$$[7, 13]$$$, it outputs "YES" when it should be "NO".

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes, I figured out the reason for the wrong solution. I am checking up to n(size of the input array), while I should be doing it up to 1e6. However, still, I am getting TLE solution

      • »
        »
        »
        »
        14 months ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        You're going to be doing that for every testcase though. So it'll require at least $$$2e9$$$ operations when $$$t = 2000$$$. You can use map/hashmap to keep count of the primes factors.

        Ignore below, it does work.

        Though even then, I'm not convinced you won't TLE in later testcases.

»
14 months ago, # |
  Vote: I like it +8 Vote: I do not like it

THIS CONTEST REALLY MADE ME TERRIFIED TO CONTINUE COMPETITVE PROGRAMMING

»
14 months ago, # |
  Vote: I like it +3 Vote: I do not like it

It was a nice contest , i have a lot of silly mistakes , but still it was a quality contest

»
14 months ago, # |
  Vote: I like it +2 Vote: I do not like it

What's up with the rating? System testing got completed hours ago?