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

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

350-20230320195909

Привет, Codeforces!

Я очень рад пригласить вас на Codeforces Round #861 (Div. 2), который пройдет в 29.03.2023 12:05 (Московское время). Этот раунд будет рейтинговым для участников, чей рейтинг ниже, чем 2100.

Моя искренняя благодарность:

У вас будет 2.5 часа на решение 6 задач, одна из которых будет разбита на простую и сложную версии. Раунд основан на задачах заключительного этапа республиканской олимпиады по информатике в Беларуси. Просьба всех белорусских школьников, участвовавших в заключительном этапе, воздержаться от участия в раунде и обсуждения задач публично до конца раунда.

Я надеюсь, вам понравится раунд!

Тестировали раунд: Ormlis, 4qqqq, nnv-nick, olya.masaeva, Makcum888.

Предварительная разбалловка: 750-1000-1500-2000-2500-3250.

UPD: раунд был перебалансирован. Вам предстоит решить 5 задач за 2 часа, одна из задач будет разбита на простую, среднюю и сложную версии.

Новая разбалловка: 750-1000-1500-1750-(1750+1000+750).

Разбор: https://codeforces.com/blog/entry/114523

Победители:

Div. 1 + Div. 2:

1) BurnedChicken

2) maspy

3) happylmb

Div. 2:

1) happylmb

2) Cherished

3) 2021_yes

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

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

Belarusian National Olympiad <3

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

Belarusian National Olympiad <3

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

Please more contests at this time

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

Notice the unusual time

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

The graph is opposite!

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

Почему у вас на картах бубны чёрные?! Почему на карту если с разных сторон посмотреть, то там или шестёрка, или девятка? Вы их в киосках заряжаете, что ли?

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

One more raid on cheaters?

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

what's that image in the post about?

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

    There is a meme in russian community. If you wanna check it, you can google it like "случай в казино".

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

    It's a hint for one of the questions ;)

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

    The rating of people that didn't participate in the Belarusian National Olympiad

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

Rating change in the image seems terrible :dead:

Something SUS!

Anyways!
- Notice the unusual time everyone!
- Hopefully everyone gets +ve delta (make the image state false).
- Hoping for a balanced round :)

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

The length of the contest in the post differs from that shown in the contests tab

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

Last time I managed to upsolve A1-D. I hope I can perform well today too and become specialist again!

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

Is it 2.00 hours contest or 2 hours 30 minutes contest?different contest duration were given in blog and contests section

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

Hope to get CM this time

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

could the timings be shifted to the normal timings, not a conducive time to conduct contests

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

Does the picture imply that this round will be the next big milestone in my downward trend in rating?

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

Эта картинка идеальна...

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

OMG 750 A and unusual time round!

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

Hoping to have a balanced round !

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

College viva or codeforces contest >﹏<

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

The rating graph in the meme is opposite!

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

TT first time finally to participate in a CF round this early hahaha. I stayed up late in the dorm till midnight most of the times. Good luck guys!!

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

Score distribution is really interesting.

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

Now it's not a joke

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

Unusual time but hope for a positive delta rating.

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

omg 3 version E round

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

Am I the only one who noticed that master is above international master on the graph?

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

Expect three versions of E and hopefully increase ratings.

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

Go to Pupil bruhh

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

Wishing everyone the best possible work!

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

This is my first contest on codeforces, can someone give some tips to do good on codeforces.

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

    Just do your best. Don't give up during the contest (This is what I used to do). No problem is hard and if others can do it then you can do it too.

    Best of luck =)

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

      Thank You :)

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

      well!! , i suck :(

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

        Hey! don't be sad, this was a tough contest indeed for everyone. I and every other cper started like this. This is the time when you should learn from your mistakes to avoid them in future, not to be sad. We are with you. Just practice as much as you can.

        (BTW, I would recommend you to solve easier problems first then move on to the harder ones. As I stated before, you should not skip problems until you have given it your best.)

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

The rating graph seems like a warning to me. Anyway, I'm still gonna appear for it.

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

will E3 >3000 ?

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

He said: The round is based on the problems from the Belarusian National Olympiad. We can ask the Belarusian students who participated in this Olympiad or find the solution in anywhere. So, I think this contest should be unrated because everyone can search the problem in Google (?).

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

Good luck & Have fun!

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

hope to be Expert:D

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

The Hardest problems in Div. 2 I've ever seen.

Hardforces :(

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

    Belarusian students had no problems with solving C. Half of the students successfully solved this task.

    I couldn't imagine this task will be so hard.

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

      I think it is not hard in general, it is just hard to come up with a solution fast in my opinion.

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

      Which problems did belarusian students get on a contest from the Round?

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

ahhh

160858923d467feaaa9de5c134246a22

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

What do those Belarusian students eat?

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

This contest was held at 4 am for my timezone, I tried using segment tree for A and fenwick tree for B before I came to my senses xD

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

Test case 4 of Problem C irritated me in the whole contest

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

How to solve B? Can anyone help.

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

    Hint: I solved it by sorting each column and using prefix sums

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

      Ohh ok just now i just sorted it and got the ans. But why won't it work if i don't sort it?

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

        Think about the case like:

        4

        6

        2

        We can't discern between the 6 and 2 because they give the expected value of 8. So we need to take the sum of all numbers higher than the value ahead of it and also the sum of all numbers lower than the value ahead of it. We can solve this problem by sorting so that there are no lower numbers in front of it.

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

How to solve c? I can only think of digit dp Here is the wrong submission

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

    There are two cases depending on the lengths of the numbers: 1. if the lengths aren't equal, you can spam 9s. 2. if the lengths are equal, find the common prefix(you can't change that part no matter what) and brute force the next two digits. You're answer will be something like common_part + x + spamming y's until you fill the length of the number. There won't be much candidates for the answer so you can check all of them.

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

      Can you tell me why you have considered 2 digits, not 3 or 4?

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

        Dunno, just observed it. If I have to give a concrete reason, probably because two digits are enough to set a min/max digit for a number. Even if we choose three digits — x < y < z — that would be useless, because we can just choose x = y.

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

          I understand that we only need two digits for min/max. But do you have any reason why we don't need more than 2 digits for the purpose of the number being in between l and r?

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

      I combined not equal length part of your solution and for euqal i applied digit dp. It Worked now, but still dont know why dp didnt worked for non equal length.

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

      Thanks

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

    You can break the problem col wise. Observe the pattern.

    Hint1: Try to find contributions of each element to the ans.

    Hint2: the solution involves sorting.

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

    You can use a greedy approach. You first try to create number with luckiness = 0, then 1, 2... To find number with luckiness = k, you can try out all intervals [i, i + k] where 0 <= i <= 9 — k You stop as soon as you find one

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

    if l and r have different length, the answer is '9' * len(l). Else let i be the first position where l[i] != r[i] (I'm thinking of l and r as strings). We can bruteforce the digit on i-th position (l[i] <= d1 <= r[i]), and then fill the suffix with a single digit d. Then we just compare the numbers. Let our number be m. If l <= m && r <= m, we update the answer

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

    Although all the greedy solutions explained here are probably correct, I will explain how to solve it using digit dp.

    dp[n][mx][mn][t] -> largest number consisting of max n digits, having max digit mx, min digit mn, and tight t. After you compute the dp till r, you look for the number with minimum difference mx — mn, that also is bigger than l. The implementation is pretty tedious though.

    Code

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

      Hey , i also coded digit dp, my states were [idx][small][big][put][max][min], can u tell if i did something wrong there?

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

Maybe we can consider this round as Div1.5...2 hard 4 me.

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

was b is a copy from this:

https://www.geeksforgeeks.org/sum-absolute-differences-pairs-given-array/ i know here we compute the abs on a matrix but isn't it just a little different? ( since we can consider every column just an array)

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

My $$$O(4 \cdot k^2 \log n)$$$ solution is giving me TLE on E3 :((

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

Would be nice if this round lasted for 3 hours instead of just 2

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

Amazing contest, E problem is really cool!

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

Hardest C I've ever seen :(

I spend more than a hour to solve it.

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

This round motivated me to solve more problems ;)
How to do A? i tried and i'm getting tle.

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

Got 10 wrong answers on D,really keen to know what went wrong.

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

Loved problem D! very educational problem

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

Mathforces

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

Here is my code of problem B, but it got wrong in the pretest3. How can I modify it? Thanks:)

#include <bits/stdc++.h>
using namespace std;
vector<int> vec[(int)3e5+5];
#define ll long long
int main(){
    int _;
    cin>>_;
    while(_--){
        int n, m;
        cin>>n>>m;
        ll ans=0;
        for(int i=0;i<n;i++){
            vec[i].clear();
            for(int j=0, tmp;j<m;j++) cin>>tmp, vec[i].push_back(tmp);
        }
        if(n==1) {cout<<"0\n";continue;}
        if(n==2) {
            for(int i=0;i<n;i++) ans+=abs(vec[i][0]-vec[i][1]);
            cout<<ans<<'\n';
            continue;
        }
        for(int i=0;i<m;i++){
            vector<int> tmp;
            for(int j=0;j<n;j++) tmp.push_back(vec[j][i]);
            stable_sort(tmp.begin(), tmp.end());
            if(n==3) ans+=tmp[0]*(-2)+tmp[2]*2;
            else {
                ll X = -(n-1);
                for(int j=0;j<n;j++) ans+=tmp[j]*X, X+=2;
                //ans+=tmp[0]*(-(n-1))+tmp[1]*(-(n-3))+tmp[n-2]*(n-3)+tmp[n-1]*(n-1);
            }
        }
        cout<<ans<<'\n';

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

    First, there is something wrong in your if (n == 2). Then, maybe your solution ans+=tmp[j]*X, X+=2; is wrong.

    You can remove the unnecessary special judgement, and reverse the vector dimension for convenience. As you did, you can sort and then let sum be the prefix sum and when get the answer for $$$j^{th}$$$ person, just ans += v[i][j] * j - sum.

    Sorry for my poor English. :)

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

    Maybe my code can help.199651953

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

Problem 1808D - Petya, Petya, Petr, and Palindromes can be solved in $$$O\left(n \cdot k\right)$$$ on GCC with auto-vectorization in $$$795$$$ ms. You can compare left half of segment with reversed right half of segment. AC submission from contest

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

    How did this got AC? This should TLE!

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

      Deleted

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

        Damn bro, from where can I learn all of this. By this way, we can solve many problems with larger time complexities too right.

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

WA on pretest 4 for 4 times on problem 4

OMG

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

Problem C , 123 lines get WA on test#2 ^_^

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

Debug long time for C. In the end, I found that there may be overflow in my solution, but I have no time to change. :)

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

Nice registration count. Haven't seen anything like this before.

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

Wonderful round with interesting problems

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

In A, why is the correct answer for the test case l=r=6 equal to 6? The largest digit of 6 and the smallest digit of 6 is equal to 6, so the answer should be 6-6 =0. Same goes for all numbers m such that 1<=m <= 9.

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

    because you asked to output the luckiest number, not the amount of luck

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

      Thanks!

      My brain completely bricked. I had if r<=9: return 0 in my code the entire time and I didnt even consider that to be an issue.

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

    Output the number,not its luckiness.

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

Could someone shed some light on how rating delta is calculated when the first problem is harder than usual? For participants who couldn't solve first problem, they are not considered to be in the contest, and this reduces the total number of effective participants.

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

Solved A-D. Unusual time and unusual difficulty.

A: For any 100 consecutive numbers, there must be a number end with "09" and it will reach the maximum luckiness (9). So we can let r=min(r,l+99) and solve by brute force.

B: For 1<=j<=m, consider the contribution of the j-th number on each card. We can sort all n j-th numbers, and the contribution of i-th number is ((i-1)-(n-i))*c[i].

C: Let t be the number we find, and assume L<t<R (we can do this by let L=L-1, R=R+1), then there must be a number d that d satisfies floor(L/10^d)<floor(t/10^d)<floor(R/10^d), but d+1 doesn't. Then we know that floor(L/10^(d+1))==floor(t/10^(d+1)) or floor(t/10^(d+1))==floor(R/10^(d+1)). First assume floor(L/10^(d+1))==floor(t/10^(d+1)), then if we know d, we can know (d+1)-th, (d+2)-th, ... 19th digits of t, and we can try for every possible d-th digits and check if floor(t/10^d)<floor(R/10^d). If so, we can assign (0~d-1)-th digits of t to the d-th digit (which means, the (0-d)-th digits of t are the same), and let it be a candidate answer. Similar for assuming floor(t/10^(d+1))==floor(R/10^(d+1)). Therefore, by considering all possible value of d and d-th digit of t, we can get at most 2*19*10 candidate answers, and we just need to check them to get the final answer.

D: Denote r=(k-1)/2. We need to count pairs of (i, j) such that:

  • i<j and j<=i+2*r and (j-i)%2==0.

  • a[i]!=a[j].

  • let mid=(i+j)/2, then 1<=mid-r<=mid+r<=n.

We can change the 2nd condition to a[i]==a[j] and subtract it from (n-k+1)*r. We store the positions of occurences of each number into different buckets (we need to store odd and even positions separately), and for each j we find the number of valid i by binary search.

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

199684592 any idea why it gives Run Time ?

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

In problem C, many solutions are giving wrong output on the test case 1 1000000000000000000 1000000000000000000 such corner test cases should have been there.

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

A=B<<<<<<<<C=D

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

what is intended complexity of E2?

I assume it is k^3 * logn, because limits seems to dictate that, yet my solution of k^3 logn had to be optimized several times before fitting in TL with a pragma, and finally getting uphacked :(

If intended was k^3 logn, you could have relaxed the limits quite a bit, i think.

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

Can someone help debug this solution of D- 199696312 ,there is something wrong with implementation and i can't figure it out.

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

How to solve D ? Can anyone please explain in simpler way ?

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

    Consider all the possible pairs of (i, j) that may be different which would result in a +1 in the answer, minus the pairs such that a[i] = a[j] and you will get the pairs that a[i] != a[j], you can calculate the a[i] = a[j] part using a vector and binary search, and the total number is the same as (n — k + 1) * (k / 2)

    Here is my code, maybe looking at it is a lot more simple R199691512

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

Nice round! though D is a bit too similar to ABC290E

But I wrote a useless line of code but it resulted in an RE in final tests in D :( droped from ~100 too ~200 in rank, so sad ...

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

Another C solution, in $$$O(t \cdot 2^{10} \cdot 18)$$$

Let's implement function next_mask(x, mask) ($$$mask$$$ is the mask of the digits from $$$0$$$ to $$$9$$$) which return smallest integer $$$y$$$ such that $$$y \geq x$$$ and all digits of $$$y$$$ are in $$$mask$$$

It can be implemented by bruteforcing prefix of $$$x$$$ that will be same in $$$y$$$ and then putting smallest digits from $$$mask$$$ in the remaining suffix but you need to be careful with corner cases.

So for actual solution we just bruteforce all $$$masks$$$ and check whether next_mask(l, mask) is not bigger than $$$r$$$ and relaxing answer. Code: 199692880

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

    Instead of iterating through all of the masks you can just iterate through the pairs of minimum and maximum set bits in the mask and then build the answer.

    I did something similar, but instead of constructing the answer I did digit dp. Code: 199704153.

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

Nice round.

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

What about the cheater raid this time?

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

![ ](ruban)

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

First I appreciate all the time and efforts for all the contributors to this round for the interesting problems.

There was just a little bit of confusion to me since E1/2/3 was nothing more than an inclusion-exclusion + binomial theorem. To me it just didn't fit 3s of TL and only range <= 2000 for parameter k, which made me thinking of some other complicated algo till near the end of contest.

I'm just curious that were the constraints set so by design or by carelessness?

(I meant no offence to anyone that made this round possible, I'll apologize if I did so unknowingly = =

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

    For E2 we have two solutions for $$$O(k^2 + \log(n))$$$ and it is easy to optimize this solution to $$$O(k + \log(n))$$$. It make no sense if we setted constrains for $$$O(k + \log(n))$$$. That's why we set $$$k \leq 2000$$$

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

      please see this 199700596

      it is based on similar technique to derive the closed form of answer, and it runs in $$$O(\log k + \log n)$$$, I guess

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

      So what's the solution can pass for k<=100 but can't pass for k<=2000? I can only come up with O(k+log(n)) solution.

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

        Well, there's $$$O(k^3 \log n)$$$ (or $$$O(k^2 \log k \log n)$$$ with fft). For each total sum (k options) find the number of sequences with this particular sum that are bad. And subtract it from $$$k ^ {(n-1)} $$$ (amount of sequences with any fixed sum).

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

[deleted because of mistaking a powerful person for someone else]

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

    I am glad to be mentioned.

    I am struggling for this problem for a very long time. Then I realized that, an integer with the suffix that all number are same will never make the answer worse.

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

Maybe change the allowed runtime in problem D to 1 second? a lot of wrong solutions are passing: https://codeforces.com/contest/1808/submission/199698146

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

    It's really hard to hack.

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

    Better to increase limitation for $$$N$$$ and $$$K$$$ to $$$300000$$$, because changing TL is linear function, but changing of limitations is quadratic function.

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

Thanks to this round which make me be CM finally :)

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

seems that there exists $$$O(k)$$$ and $$$O(\log n)$$$ solutions for E......

$$$O(k)$$$ solution: https://codeforces.com/contest/1808/submission/199658264

$$$O(\log n)$$$ solution: https://codeforces.com/contest/1808/submission/199673882

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

In problem D, I was trying an approach similar to https://atcoder.jp/contests/abc290/tasks/abc290_e with some modifications but I cannot understand what's going wrong. Can someone explain? https://codeforces.com/submissions/SamyakSinghania

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

Thank you for Problem C. Refreshed my digit dp practice.

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

Nice Round! I think the problems were great, if you find yourself stuck on A,B and C then maybe these tutorial videos could help you out — Problem A, Problem B, Problem C video tutorial

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

Really nice contest. I personally liked the problems a lot. A little different than the normal div2 rounds. I loved it. Duration could have been more.

It's good to know that I am not the only one who used segment tree for problem A :)

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

Nice balance of round

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

Any predictions of E1,E2,E3 rating?

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

weird E xd

if (n == 1) { cout << '1'; return; } if (k % 2) cout << (poww(k, n) — poww(k — 1, n) — poww(-1, n) * (gcdd(n — 2, k) — 1) + m) % m; else k /= 2,cout << 1ll * poww(2, n — 1) * ((poww(k, n) — poww(k — 1, n) — poww(-1, n) * (gcdd((n — 2) % k, k) — 1) + m) % m) % m;

(poww means pow and gcdd means gcd) luckily didn't participate today or collapsed maybe lol

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

Why are the constraints on E3 so low? IMO, anyone who can get a solution that's $$$O(k^2\log n)$$$ should also be able to get the $$$O(\log n + \log k)$$$ one...

(not to say that E3 isn't difficult as is, it took me at least an hour of work after contest to solve it, haha)

Fast: 199736258 Slow: 199729972

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

Problem C:

if l and r not same number of digits, fill l with 9 and return.

if same number of digits, first find max common prefix. After that, brute force the next digit d, which is the first digit that l and r differs.

  1. if we choose digits_l[d] < digits[d] < digits_r[d], then obviously just greedily fill the rest with digits[d].

  2. if digits_l[d] == digits[d], then if we know the max_digit, we greedily fill everything after d with max_digit.

  3. if digits_r[d] == digits[d], similarly, fill everything after d with min_digit.

Thus, just brute forcing the next two digits is enough.

Edit: Formatting

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

Here's how to solve problem E in $$$O(\log n+\log k)$$$:

First, handle the special cases with $$$\min(n,k)\le 2$$$. Now assume this is not the case.

In a lucky number, call a digit "special" if it is equal to the remainder when the sum of all other digits is divided by $$$k$$$. Then, we will enumerate all lucky numbers by the location of their first special digit.

Suppose $$$k$$$ is odd. If the first special digit is not the last digit, say it is $$$a_i$$$ in the number $$$\overline{a_1 a_2\ldots a_n}$$$ then there are $$$k-1$$$ ways to choose each of $$$a_1$$$ through $$$a_{i-1}$$$, $$$k$$$ ways to choose each of $$$a_i$$$ through $$$a_{n-1}$$$, and then the value of $$$a_n$$$ is uniquely determined to force $$$a_i$$$ to be special. The sum of the number of lucky numbers with first special digit at index $$$i$$$ over all $$$i$$$ between $$$1$$$ and $$$n-1$$$ is $$$k^{n-1}+k^{n-2}(k-1)+k^{n-3}(k-1)^2+\ldots+k(k-1)^{n-2}=\frac{k^n-(k-1)^n}{k-(k-1)}-(k-1)^{n-1}$$$.

To count the number of lucky numbers whose first special digit is $$$a_n$$$, notice that if the first $$$n-1$$$ digits do not contain $$$a_n$$$, we can decrease each of the first $$$n-1$$$ digits by $$$a_n$$$, so that the first $$$n-1$$$ digits don't contain 0 and sum to $$$(2-n)a_n$$$ (all operations are mod $$$k$$$, of course). Using the roots of unity filter on the polynomial $$$(x+x^2+\ldots +x^{k-1})^{n-1}$$$ (or alternatively just using small cases to guess a pattern), we can compute that for each possible value of $$$a_n$$$, if $$$(2-n)a_n$$$ is a multiple of $$$k$$$, then there are $$$\frac{(k-1)^{n-1}+(k-1)(-1)^{n-1}}{k}$$$ lucky numbers whose first special digit is $$$a_n$$$, and otherwise $$$\frac{(k-1)^{n-1}-(-1)^{n-1}}{k}$$$ lucky numbers whose first special digit is $$$a_n$$$. There are $$$\gcd(n-2,k)$$$ possible values of $$$a_n$$$ that fall into the first case, and others fall into the second case, so we can add them to $$$\frac{k^n-(k-1)^n}{k-(k-1)}-(k-1)^{n-1}$$$ to get the answer.

The k even case is similar, only that now if $$$a_i$$$ is the first special digit, then $$$a_i+\frac{k}{2}$$$ also cannot appear before $$$a_i$$$. We get that there are $$$\frac{k^n-(k-2)^n}{k-(k-2)}-(k-2)^{n-1}$$$ lucky numbers whose first special digit is not $$$a_n$$$. Using the roots of unity filter again on $$$(x+x^2+\ldots+x^{\frac{k}{2}-1}+x^{\frac{k}{2}+1}+\ldots+x^k)^{n-1}$$$, we know that if $$$(2-n)a_n$$$ is equal to $$$0$$$ or $$$\frac{k}{2}$$$, then there are $$$\frac{(\frac{k}{2}-1)(-2)^{n-1}+(k-2)^{n-1}}{k}$$$ lucky numbers whose first special digit is $$$a_n$$$, otherwise there are $$$\frac{(k-2)^{n-1}-(-2)^{n-1}}{k}$$$ lucky numbers whose first special digit is $$$a_n$$$, and the first case covers $$$2\gcd(n-2,\frac{k}{2})$$$ values of $$$a_n$$$.

My submission which actually runs in $$$O(\log m+\log k)$$$ using Fermat's Little Theorem: https://codeforces.com/contest/1808/submission/199734771

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

    Is this solution worth rating 2800? I think that the problem is overrated..

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

Finally reached pupil after 39 contests.

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

How to solve E2/E3?

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

Why is this solution accepted in problem C?

I'm not sure about the time complexity of the solution, but it was not hacked. Could anyone hack it or explain why it's correct?

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

Editorial when?

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

Can anyone explain the idea to solve C, I did see a lot of solutions but none of them really helped to get to the intuition.

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

    The task C can be solved without DP. The key idea is constructing an answer number, trying to use the same value as at the previous index.

    Submission: https://codeforces.com/contest/1808/submission/200894232

    Let's cover edge cases first.

    1) if l == r, return l.
    2) if l.ToString().Length < r.ToString.Length, return 999..999 of size of l.
        l =  123456
      ans =  999999
        r = 1234567
    

    Considering l and r, as arrays of integers in range [0..9]: we have l and r of the same size and at some index i, where r[i] > l[i].

    The value in the answer (array ans) at index i should be in range [l[i]..r[i]].

    So let's go over all possible values for ans[i] and for each of them check all the possible endings, constructed using a single digit.

           v
    l = 1236**
         ...
        123699
        123700
         ...
    r = 1237**
           ^
           i
    

    Can be implemented like that:

    for (var ansI = l[i]; ansI <= r[i]; ansI++)
    {
        for (var end = 0; end <= 9; end++)
        {
            ans[i] = ansI;
            for (var idx = i + 1; idx < ans.Length; idx++) ans[idx] = end;
            // check that ans has lower luckiness, save it if it is the case.
        }
    }
    
    • »
      »
      »
      13 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      How do you prove the part where size of L == R?

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

        When I thought about proving the solution, I found an even simpler solution. I will update my previous post. If you visually imagine all possible answers and L and R as lines on the same graph you can find it obvious.

          ^
          |-------------- a4: 123577 - X
          |============== R : 123574 ========
          |-------------- a3: 123566 - ?
          |                    ...
          |-------------- a3: 123500 - ?
          |-------------- a2: 123499 - ?
          |                    ...
          |-------------- a1: 123477 - ?
          |============== L : 123469 ========
          |-------------- a0: 123466 - X
        --+---------------------------------->
          |
        
»
13 месяцев назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Wait somehow C is 1900 and D is 2100. Feels like D is actually much easier.

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

A good contest!

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

Wind_Eagle Why not make $$$N$$$ $$$K$$$ larger, like $$$300 000$$$ in $$$D$$$?

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

    Wanted to allow n * sqrt(n) pass. Didn't notice that nk with avx can get AC.

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

      Can you kindly tell how can we do this avx thing. (By the comment it seems like some runtime optimization trick but I am not sure)

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

        This line allows compiler to use avx assembly instructions. These instructions use vectorization and can do monotonous tasks faster, for example, do this code four times faster:

        for (int i = 0; i < n; i++) {
          b[i] += a[i];
        }
        
»
13 месяцев назад, # |
  Проголосовать: нравится -23 Проголосовать: не нравится

I was just warned by the Codeforces system because my Problem C code is the same as someone else's. It's obvious that the reason is that I live-streamed the contest and some viewers copied my code. I want to ask if there is any way to avoid being plagiarized if I have to live-stream, or is live-streaming on Codeforces completely prohibited? But I always see some Grandmasters live-streaming on Codeforces.

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

    Live streaming is a flagrant violation of the rules. You can publish a screencast AFTER the end of a round.

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

.