By awoo, history, 4 years ago, translation, In English

Hello Codeforces!

On Apr/12/2021 17:35 (Moscow time) Educational Codeforces Round 107 (Rated for Div. 2) will start.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given 6 or 7 problems and 2 hours to solve them.

The problems were invented and prepared by Roman Roms Glazov, Adilbek adedalic Dalabaev, Vladimir vovuh Petrov, Ivan BledDest Androsov, Maksim Neon Mescheryakov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.

Good luck to all the participants!

Our friends at Harbour.Space also have a message for you:

Calling on all Codeforces,

Harbour.Space University is offering a unique opportunity to study in Barcelona for those who are interested in joining our young and dynamic competitive programming team. We accept medalists and top performers of IOI, IMO, ICPC, and participants with Codeforces rank above 2000.

Codeforces and Harbour.Space

Harbour.Space has a single, key requirement: be passionate and motivated to learn and/or work in the field of competitive programming in the long term. Even if you have already exhausted all your ICPC attempts, you are still welcome.

Join us to help build a comprehensive system of preparation for IOI and ICPC for the next generations! We believe that if you have the talent and determination to succeed, you can. We want to help you make it happen.

In addition to courses taught by some of the world's foremost experts in their fields, Harbour.Space offers these benefits upon acceptance for this scholarship:

  • A full tuition fee waiver (Bachelor and Master degrees)
  • Student visa
  • Private health insurance
  • Monthly living allowance*

Codeforces and Harbour.Space

In return, we demand dedication to learning and improving yourselves:

Study three hours per day
Train continuously for ICPC, if you are still eligible for participation
Intern four hours per day

Ready to formally submit your application? Please register on our website, attach your latest CV, and pay a non-refundable €125 application fee. The fee guarantees we can process every single application in a fair and timely manner, and maintain the highest possible standards of assessment.

Register→

Our admission process is a holistic review of each candidate's abilities, achievements, and potential to create something exceptional.

You may choose to study in the following areas of specialization:

  1. Computer Science
  2. Data Science
  3. Cyber Security
  4. Front-End Development

Codeforces and Harbour.Space

All our degrees are taught in English. If you want to learn more about our programs please visit our website or contact our admissions office.

*The exact living allowance level throughout the entire duration of studies depends on the performance during the interview and on the overall performance. As a guidance, it is in the range of 500-1500 EUR.

Harbour.Space University Team

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 risujiroh 7 233
2 Maksim1744 7 243
3 noimi 7 253
4 fastmath 7 278
5 mango_lassi 7 288

145 successful hacks and 1221 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A Maksim1744 0:01
B SSRS_ 0:03
C BrunoFMUFC 0:06
D SSRS_ 0:10
E AmShZ 0:08
F SSRS_ 0:51
G Potassium 0:45

UPD: Editorial is out

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

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

In return, we demand dedication to learning and improving yourselves:

— Study three hours per day

— Train continuously for ICPC, if you are still eligible for participation

— Intern four hours per day

Is this a hard and fast rule or can be slack. As the above three activites consumes around 10 hours of day. Where is life?

»
4 years ago, # |
  Vote: I like it -10 Vote: I do not like it

Three contest in a row in consecutive days. This is really awesome! That's why codeforces is best.

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

    So you're going to say the opposite thing when there is no contest in 3 consecutive days?

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +32 Vote: I do not like it

      No, not at all. I am just talking about frequency as compared to other sites.

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it -18 Vote: I do not like it

    Actually, while this is generous of CodeForces, I think it would be ideal if contests were spread out a little more evenly. I had prior commitments for the weekend and Monday and will miss 3 contests (that would typically be spread over 2-3 weeks instead of 3 days).

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

      So you're saying that there should be less contests so you compete in more contests? I don't get your point.

      5 contests over 2 weeks is worse than 3 contests over 3 weeks?

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

        Nope, that's not what I'm saying. Rather than have 3 back-to-back contests over a single weekend, and then wait for 10+ days for the next one, it may be better to spread them a little (say over a week) so people who are occupied (over a weekend in this case) don't miss all 3 and have a chance to attend at least 1-2 of them.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Yeah ok but the next contests is in 3 days (a 5-day gap, not 10+) and the one after that is in 2 more days.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            It's great that there's some more right around the corner. My suggestion was not to reduce the frequency or number of contests (the more the merrier), but to distribute them in an optimal way.

»
4 years ago, # |
  Vote: I like it +54 Vote: I do not like it

Codeforces rank above 2000.

I think you mean rating, not rank

»
4 years ago, # |
  Vote: I like it -6 Vote: I do not like it

Do you do dynamic programming in the dynamic competitive programming team?

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

hope I remain expert after the contest :(

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

A humble request, just try to recheck the problem statement before uploading the question, for example, the last line of the first problem ( which was rectified later ) was incorrect and made the whole problem statement wrong. I was planning to give the contest but was confused reading the last line and by the time it was rectified over 6000 people had already solved it.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +23 Vote: I do not like it

    Yes, it was a typo in the notes, but it was fixed just about 5 minutes into the contest. We are sorry for that issue, but sometimes typos happen, and we almost always fix them quickly.

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Any idea how to fix WA on test-10 for problem D?

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

How to solve D ?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +31 Vote: I do not like it

    Eulerean tour of the letters

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +43 Vote: I do not like it

    a + ab + ac + ad .. + az + b + bc + bd + be + ...

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    if k = 7, we can concan strings below aabacadaeafag bbcbdbebfbg ccdcecfcg ddedfdg eefeg ffg g and then append strings repeat.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    you want to minimize occurrence of each distinct pair of letters (adjacent letters) that appears in the string , add an edge between each pair of usable letters .Then our answer is minimized if we take euler cycle of this graph ,euler cycle always exists since its a directed complete graph, each letter has equal indegree and outdegree.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    I did brute force over all pairs ,$$$"aa","ab","ac"\cdots\ "zz"$$$ and greedily selected the best pair with minimum occurence.

    Compleixty; $$$O(n*26)$$$

    https://mirror.codeforces.com/contest/1511/submission/112864604

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it -6 Vote: I do not like it

      ya, that's what I thought of. But couldn't get to the solution.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I did the same thing but for some reason i was convinced that placing the first k characters first like (abc...k) is optimal submession

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

    Problem D: There can be $$$k*k$$$ possible pairs of characters. Now consider each of these pairs as a vertex of a graph. Then add a directed edge from $$$c_1c_2$$$ to $$$c_2c_3$$$ for all possible $$$c_1$$$, $$$c_2$$$ and $$$c_3$$$. Now do topological sorting to find a sequence of pairs. This sequence has each of the pairs exactly once, so the cost is $$$0$$$. So, you get the maximum lengthed string which has $$$0$$$ cost ($$$c_1c_2 \rightarrow c_2c_3$$$ will become $$$c_1c_2c_3$$$). Now just keep concatanating this string until its size becomes n.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Pay attention to the Example 1's output.

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

Solved problem G in $$$O(nq)$$$ with auto-vectorization. My worst test works in 4305 ms. Solution 112850106. Hope that it will stay strong during next 12 hours and later.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone suggest approach for B and D?

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +2 Vote: I do not like it

    I have not given the contest. But just saw B. I think you can have many possible answers . One possible answer can be like this :

    X = 100...000(a-1 zeroes) Y = 77...7000...00( (b-c+1) 7s & c-1 zeroes).

    This will always give you gcd as 10..00(c-1 zeroes)

  • »
    »
    4 years ago, # ^ |
    Rev. 3   Vote: I like it +1 Vote: I do not like it

    For B, I decided to assign a unique prime factor to each of a (2), b (3) and c (7).
    As all the numbers (2, 3, 4) are lesser than 10, there will always be a power of {2, 3 and 7} whose decimal representation is of any given number of decimal digits.
    First of all, I find c by multiplying it with 7 till I get the required number of digits.
    Then, I multiply both a and b by c so that their GCD becomes c.
    Finally, I multiply a and b with their respective prime factors till their representations reach the required number of digits.
    Eg: 2, 2, 1
    Output: 14 (2 * 7), 21 (3 * 7), 7

    My Submission

»
4 years ago, # |
  Vote: I like it +16 Vote: I do not like it

how to solve E?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +33 Vote: I do not like it

    OEIS

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it -10 Vote: I do not like it

      can u plz tell what is OEIS?? i have heard it a lot(at cf itself) in pattern related questions.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +4 Vote: I do not like it

      Which sequence? How did you get there? I think I'm just really bad at looking on OEIS.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        What is OEIS?

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

        I generated the results for 1D patterns like "o", "oo", "ooo" and so on, got an oeis sequence with these numbers, then for each vertical / horizontal contiguous pattern, I added "formula(lengthContiguous)*2^(nbWhites-lengthContiguous)"

        Formula was weird, couldnt understand (I suck at combinatorics), something like "((3*n+1)*2^n-(-1)^n))/9"

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      logic.?

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 3   Vote: I like it +25 Vote: I do not like it

      Whenever there is a combinatorics problem in one dimension, it is often the case it's formula or some related information will be available on OEIS. So find the answer for small terms and search these terms in oeis.org and you will get the formula for it.

      To solve E ,

      Step 1 : Try to reduce a problem to find the answer for only 1 row having N white color cells.

      Step 2 : Write bruteforce and search OEIS.

      • »
        »
        »
        »
        4 years ago, # ^ |
        Rev. 2   Vote: I like it +3 Vote: I do not like it

        Actually we can do it without OEIS using contribution technique,but yea for that too we need to come up with the observation on small single rows.... If l is the length of row,c is total white places,so the answer is sum of

        2^(c-2)+2^(c-2)........l-1 times...

        -2^(c-3)-2^(c-3)........l-2 times...

        2^(c-4)+2^(c-4)........l-3 times...

        .........till this converges.
      • »
        »
        »
        »
        4 years ago, # ^ |
        Rev. 3   Vote: I like it +36 Vote: I do not like it

        Step 2 (alternative) by Combinatorics: Problem E 1511E - Colorings and Dominoes

        Let's denote the answer for N contiguous white color cells by f(n) and try to compute for f(n+1).
        
        If (n+1)th character is 'b' then we simply have 'value' as f(n).
        
        If (n+1)th character is 'w' then:
              If nth character is 'b' (.......bw) 
                    Then we have f(n-1)
              If nth character is 'w' (.......ww)
                    Then we can put a domino on these ww. 
                    The number of such cases is 2^(n-1).
                    Also, we need to add f(n-1) for the 'value' of the n-1 elements.
        
        so f(n+1) = f(n) + f(n-1) + 2^(n-1) + f(n-1)
        

        Solution: 112869725

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

          thank you so much, this is the best explanation I have found for this problem.

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

    I just used dynamic programming (didn't even know there is such thing as OEIS) to find the sequence of the 1D o's and the equation I found was f(k) = f(k-1) + 2f(k-2)+ 2^(k-2) where f(k) denotes the total sum of the maximum tiling for a length k vertical or horizontal row of o's, and then multiplied that by 2^(nbtotal_white-k)

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      can you explain this "then multiplied that by 2^(nbtotal_white-k)"?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    another way to solve for some n is to iterate on len of the consecutive blocks which have same color this solves for some n in O(N). my submission

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can you please explain your solution?

      • »
        »
        »
        »
        4 years ago, # ^ |
        Rev. 2   Vote: I like it +4 Vote: I do not like it

        Ok Ill try to explain in detail, I hope you get the fact that we want to calculate answer for only a string of length N consisting of 'o' only. where 'o' can be red or blue ,so for some arbitrary painting we consider all consecutive segments of red . Now we iterate on length of this segment (you can see solve function in my code). this contributes to floor of (len/2) and we simply count how many times it occurs and add it to the answer. You can see some article on contribution technique which is what I used here.

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Can someone please help in suggesting an approach for another version of problem C wherein the colours of cards and query colours can be up to 3e5?

Thank you in advance!

»
4 years ago, # |
  Vote: I like it -9 Vote: I do not like it

D is so much harder than E for me. How to solve it?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    D could be solved by the pattern like a+ab+ac+b+bc+c for k=3 , and then just repeat it until you reach n . Can you tell how to solve E

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can u please help me as to how u were able to come up with this pattern.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +2 Vote: I do not like it

        I came up with this pattern after looking at sample test case 1 .

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    first of all given condition is nothing but checking substrings of length two which are repeated how many times.If you are able to observe it then your task is simply to minimize the Cost which can be minimized if two length substrings are repeated minimum times hence try to make all distinct possible two length substrings which wont be repeated if you add it to end your resulting string continue this and make your resulting string

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This Video might help you. Video Explanation

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

How to solve E?

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

$$$O(nq)$$$ solution for problem G, using vectorization: 112850202.

A completely straightforward $$$O(nq)$$$: 112827572.

I understand that the my submission might be impossible to fail, but how in the world did the setters allow the second submission to pass?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +21 Vote: I do not like it

    Second solution is not straightforward $$$O(nq)$$$. It is auto-vectorized with GCC and has same logic as your. See assembly here. Click on cycle for and click on "reveal linked code".

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yeah, sorry. When I was writing my code GCC didn't optimize it for some reason.

      Also they have similar worst case performance, it's just that pretests are weak.

  • »
    »
    4 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    I tried several variations of your code and only a few of them passed, you can check my submission history. I guess it's easy to miss that gcc might optimize this particular problem.

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

Worked like half an hour on C with fancy algos, segment tree and things...before noticing that super simple simulation works fine :/

Edit: And needed some time in B to realize that the order of the two output values matters. That felt fairly uncommon for that problem.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    How can we do C problem if color of cards is of order 10^5(instead of 50)?

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it -14 Vote: I do not like it

      There are max 50 colors, so max 50 positions to maintain.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it -13 Vote: I do not like it

    Fairly SImple way to do C.

    cin>>n>>k;
        vector<ll> mp(51,-1),m1(51);
        for(ll i=0;i<n;i++) {
            cin>> a[i];
            if(mp[a[i]]==-1)
                mp[a[i]]=i;
        }
        ll tot=0;
        for(ll i=0;i<k;i++) {
            ll j;
            cin>>j;
            cout<<mp[j]+1<<" ";
            for(ll i=1;i<=50;i++) {
                if(mp[i]!=-1 && mp[i]<mp[j]) {
                    mp[i]++;
                }
            }
            mp[j]=0;
        }
        cout<<endl;
    
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I resubmitted my problem E but the initial time of submission is shown in the standings. Which will be considered, if both of them pass?

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Why is my rate in offical the same in unoffical?

»
4 years ago, # |
  Vote: I like it +18 Vote: I do not like it

G O(NQ)

»
4 years ago, # |
  Vote: I like it -26 Vote: I do not like it

Well, Contest was really a good one B and D were really good problems but one thing which I observed is that in previous three contests there were overall three problems which were googleable which is a bit weird on platform like codeforces which is known for its originality.A lot of People copied code of linked list in C problem today which makes it somewhat unfair.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +43 Vote: I do not like it

    Linked lists :)...Lol, these people are dumb!

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

I think my D is different from all Please hack it. 112846805

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

in question B the order of output matters , that's wrong , it costed too much

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    yeah , i got the idea and implemented it. It shows wrong answer i spend approx 10 min to find that order matters.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can anyone tell me how to approach A in today's contest?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Just put all the 1st and 3rd type no. in one server and 2nd type no.s in another server

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

14th test for D TLEd me, although on the PC it takes 0.4 sec. How is it even possible?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Most likely undefined behaviour, like an array out of bound access or the like.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

awoo why this 112845193 code is giving TLE in python3.

»
4 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

(Problem-B), Can anyone tell me why my code is giving Wrong answer? Thanks. Here's the link to my code https://mirror.codeforces.com/contest/1511/submission/112825682 (Test case 228)

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve problem C ?

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

    You just care about the minimum index for each number from 1 to 50

    Create an array of size 51 (i call it idx), idx[i] = minimum index for i in the input

    when he ask for t, you put idx[t] = 1 but before changing it shift all other elements in array "idx" by 1 in case they were less than idx[t].

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

    if you know stl it will be easy for you

    • at first you need to store your value in deque
    • then for each query find the expected value
    • print it's position
    • erase that that position's value from deque
    • push expected value in the front of the deque

    you are all done ^_^

    you can see my submission here

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This Video Explanation Might Help you. Video Explanation

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem C:
Python3 gets accepted, the same code on PyPy3 gets TLE :D
I listened to your advice and submitted PyPy and ended up with egg on my face
https://mirror.codeforces.com/contest/1511/submission/112854945
https://mirror.codeforces.com/contest/1511/submission/112860623

»
4 years ago, # |
  Vote: I like it +14 Vote: I do not like it

Masters and above are in the official standings for some weird reason.

»
4 years ago, # |
Rev. 4   Vote: I like it +31 Vote: I do not like it

Today's contest https://mirror.codeforces.com/contest/1511/submission/112852064 https://mirror.codeforces.com/contest/1511/submission/112830325 https://mirror.codeforces.com/contest/1511/submission/112812516

Yesterday's contest https://mirror.codeforces.com/contest/1513/submission/112706259

This is how k_Rishav bypasses Plagiarism testing. He has done this today and yesterday both, and I am sure he must have done it multiple times before as well. People like k_Rishav are spoiling the sport. I don't understand where would cheating take them in life. They will never get anywhere in life but always remain what they are i.e cheater. He should be banned from the platform as soon as possible.

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

How to solve $$$C$$$ if distinct no of color of cards may be of order $$$O(n)$$$ ?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

112861635 TLE

112862682 AC

can anybody explain this !! why using LL gives tle in B??

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It might be that a>b, then the 32 bit integers somewhere overflow and the loop terminates, but the ll do not overflow.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Someone hack my solution for C, it should give RTE verdict

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

i forgot to use fast i/o in problem C. now i'm wondering if i'm gonna get tle

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to prove correctness for the approach used in D?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    So the cost of the string is the sum over $$${occ[ij] \choose 2}$$$ where $$$i$$$ and $$$j$$$ are characters from $$$a$$$ to $$$z$$$ and $$$occ[t]$$$ is the number of substring $$$t$$$ in the given string $$$s$$$.

    You can prove that if $$$x \geq y+2 $$$ then $$${x \choose 2} + {y \choose 2}$$$ is greater than $$${x -1 \choose 2}+{y+1 \choose 2}$$$. Then consider an optimal string. The difference in the occurrence of the maximum and minimum should not exceed $$$1$$$. With this information and the value of $$$n$$$, we can uniquely determine the maximum and the minimum number of occurrence over all substrings. This paves way for a simple cyclic construction.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I understand that we want to spread occurrences of each of the k * k substrings as evenly as possible, in that case, the string of maximum and minimum occurence will differ at max by 1. But how to construct it? Some answers said that we can take an Euler tour over the complete graph, but I don't see why it works? Can you explain that?

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

        oh the construction is pretty simple. No need for euler tour. Let's say consider first f letters. You can consider this pattern:

        faabacadaeafbbcbdbebfccdcecfddefeef

        you can cyclically iterate through this string, as you know that the difference between the max and min will be not more than 1 at any time, when you cycle through this pattern.

»
4 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Can C be optimised brute forced? I don't see the complexity going beyond O(50*q)

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I tried to hack my solution on problem D using the test case "2000005 26" and it got hacked but same test case was there in pretest as well test case number 36

https://mirror.codeforces.com/contest/1511/submission/112856095 (Hacked) https://mirror.codeforces.com/contest/1511/submission/112870279 (Accepted)

I resubmitted my solution it got accepted can anyone explain to me why? thanks in advance

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    MikeMirzayanov please look into this .. My code is hacked by a test case that was already there in pre-tests as well and same code if I submit now is giving AC verdict :(

»
4 years ago, # |
Rev. 7   Vote: I like it 0 Vote: I do not like it

Problem D, you can search the zero-cost string by testing if the current chosen letter will make an existing pair using set(notice that you also do not want to make the next position no choice, so check if the next pair is possible). 112873007

This string is $$$k*k+1$$$ long and costs 0. If $$$n>(k*k+1)$$$, we make it repeat. The reason is that every two repeated zero-cost string has exactly $$$k*k$$$ cost(every adjoint two letters have a collision). Also, observe that the zero-cost string starts with $$$aa$$$ ends with $$$a$$$, we do not want $$$aaa$$$ since it results in more appearances of pair $$$aa$$$, so we delete the last $$$a$$$ of the zero-cost string.

However, I forgot the deletion during the contest. Not clever :<

»
4 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Why people are getting tle in problem C?

is it because we use map?

»
4 years ago, # |
Rev. 2   Vote: I like it -6 Vote: I do not like it

submission (Hacked)

submission (Accepted)

I resubmitted my hacked solution and it got accepted! Please have a look!

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

    Your Accepted solution can be hacked again. All submissions will be rejudged after the open hacking phase is finished.

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

    Now it's hacked :)

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      see my submission it got hacked by a test case that was there in pretests

      200000 26

      https://mirror.codeforces.com/contest/1511/submission/112856095

      do you know whats the reason for this? and now when I again doing it is giving unsuccessful hack

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

        Sometimes you notice that if you resubmit your code it runs in different speed, This thing from CodeForces itself sometimes it differ in a little milliseconds

        So always try to keep at least 100ms (depends on the problem) between your code run time and the time limit

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          But i am again trying to hack my solution with samr test case it is giving unsuccessful hack. I want to know are hacked submission also rejudged during final system testing. Is there any chance that verdict will change to accepted from hacked because its running within time limits specified

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

            I'm sorry, Hacked solutions can't return Accepted

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

I couldn't prove/hack my solution for D, tried to make distribution uniform, maintained a $$$next[$$$ $$$]$$$ char array of size $$$k$$$ where $$$next[c] = c$$$ initially, started with $$$'a'$$$ and appended $$$next[prev$$$_$$$char]$$$ char and incremented it cyclically. For $$$n = 10, k = 3$$$ the resulting string is $$$'aabbccacba'$$$. Did anyone try this approach and proved it?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

https://mirror.codeforces.com/contest/1511/submission/112834165 failed on 7 https://mirror.codeforces.com/contest/1511/submission/112843558 failed on 13

Could someone help me to explain what's wrong with these approaches for question D?

Just using greedy to get the next digits that have the lowest frequency.

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Why the brute force can pass G?

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

My $$$O(1)$$$ solution for B. Felt weird but works.

First i take $$$z$$$ as $$$10^{c-1}$$$ . Now $$$z$$$ has $$$c$$$ digits. I want add $$$a-c$$$ digits for $$$x$$$ and $$$b-c$$$ digits for $$$y$$$. To keep $$$z$$$ as a factor i have to achieve this by a multiplication of sum number (with $$$a-c+1$$$ digits and $$$b-c+1$$$ digits). But to keep $$$z$$$ as the GCD, two numbers used to multiply for $$$x$$$ and $$$y$$$ must not have common factors. aka coprime. But all prime numbers are coprime. Therefore i just have to find two prime numbers with required lengths. For that i precalculated these two arrays. Having two numbers for each length is sufficient.

int p1[] = {3,11,101,1009,10007,100003,1000003,10000019,100000007,1000000009};
int p2[] = {5,13,103,1013,10009,100019,1000033,10000079,100000037,1000000007};

Now answer can be calculated as,

$$$x=10^{c-1}*p1_{a-c}$$$

$$$y=10^{c-1}*p2_{b-c}$$$

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Or you could notice that $$$10^n$$$ and $$$10^m+1$$$ are coprime for all $$$n$$$ and $$$m$$$. So you could do:

    $$$x = 10^{a-1}$$$

    $$$y = (10^{b-c} + 1) \cdot 10^{c-1}$$$

    And the expression for $$$y$$$ simplifies to:

    $$$y = 10^{b-1} + 10^{c-1}$$$

    Which I think is a pretty neat answer!

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anybody tell at which test case my C is hacked? thanks

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

    Your code is slow

    some cases with high constraints and a specific way to arrange the elements will hack it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

why does this solution pass and no one can hack it? 112850106

»
4 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Where is the Tutorial? : )

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

The system is accusing me of cheating when I didn't cheat. It says that my problem D coincides with some other person's problem D, I think because both of us had the same idea and the implementation code is really short.

My Solution

Other guy's solution

MikeMirzayanov Can you please look into this?

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

For problem C:

Can anybody tell me why these Python3/Pypy3 solutions giving TLE.

But Exact same implementation with C++ giving AC?

Is my implementation is wrong somewhere, or is it a Judge (Or Language) issue?

TIA.

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

    Quit using python if there is no bignum related problem. It is just a slow language.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +9 Vote: I do not like it
    1. Both solutions are bad.
    2. C++ solution works because C++ is faster.
    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks. I realize this now, it is a bad solution indeed. I should have thought more optimized approach than this.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there a way to get full testcase 7 of problem C
There is a performance regression in PyPy project and they need it to investigate, here is the link to the issue https://foss.heptapod.net/pypy/pypy/-/issues/3437#note_157645

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

    You should contact the problem setter for that

»
4 years ago, # |
  Vote: I like it +27 Vote: I do not like it

When ratings will get updated??

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem D. Instead of thinking so much complex i have a simple logic...and by using this i got ac.

I though there are limited pairs of two alphabet so after some length whatever we choose this much have occurred previously. and lets say the count of any pair is X. so if any new occurence of that pair will cost x+1; So i have to minimize this X. it is inly possible if we distribute the occurence of pair symmetrically. Means first form all the pair by A then same with B,C,D...Z. until its length becomes N.

»
4 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Why ratings are not updated yet ??

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

It seems that many O(n^2) solutions pass problem G . Maybe 4e10 "xor" operations is very fast QwQ.

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

Why the title of this contest in the rating graph says the contest is unrated?

Rating Graph

»
4 years ago, # |
  Vote: I like it +31 Vote: I do not like it

waiting for rating change

»
4 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Why the ratings don't change ?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

why the ratings haven't changed?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Where's the beef? Why hasn't my rating changed? I stayed up late to participate in the contest!

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

    It's normal for educational rounds, rating changes usually appear around 24 hours after the contest.

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

    beef is banned in India

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

During contest I misread Problem A Review Site. I thought type 3 person will downvote if there are more upvotes than downvotes, otherwise they will upvote.

Can anyone guide me how I can solve this version of the problem.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think it would be optimal to send type 1 guy to the first server and types 2 and 3 to second server, and then just loop through the types.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I thought the same but it actually fails for this test case -

      2
      3 3
      

      Your answer would be 1 but correct answer is 2.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        As the statement mentioned : "type 3: a reviewer hasn't watched the movie — they look at the current number of upvotes and downvotes of the movie on the server they are in and decide what button to press. If there are more downvotes than upvotes, then a reviewer downvotes the movie. Otherwise, they upvote the movie.", you can easily put all of the people from type 1 and type 3 in server 1 and the rest of them in the second server, So the answer is the number of '1's and '3's in the input array.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Please read the original comment one more time.

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

            In your version of problem you should send the Type 1 person to the first server and Type 2 and Type 3 person to the second person and just keep a track of number of downvotes the second server has and accordingly add on to the upvotes (if number of upvotes<=downvotes and current type is 3, then the upvotes increase, if type is 3 then downvotes increase, else if upvotes > downvotes, then for each type downvotes will increase), I guess this should do it

»
4 years ago, # |
  Vote: I like it +6 Vote: I do not like it

finally after 2000 years rating changed

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Hopefully Editorials will out in another few yrs XD

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it +53 Vote: I do not like it

As a first AC, you are late AC.