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

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

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://mirror.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
  • Проголосовать: не нравится

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

Belarusian National Olympiad <3

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

Belarusian National Olympiad <3

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

Please more contests at this time

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

Notice the unusual time

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

The graph is opposite!

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

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

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

One more raid on cheaters?

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

what's that image in the post about?

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

I don't know why but the meme is so relatable to my current situation :)

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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 :)

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

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

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

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

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

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

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

Hope to get CM this time

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

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

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

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

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

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

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

OMG 750 A and unusual time round!

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

Hoping to have a balanced round !

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

College viva or codeforces contest >﹏<

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

The rating graph in the meme is opposite!

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

Hello Wind_Eagle,

I just found a typo in the blog where you say "divided into easy and hard verions." Although it is a minuscule one (of course, we are humans) but it would be nice to be corrected. BTW, I love your rounds and hope that this round would be fun for everyone too <3.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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
»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Score distribution is really interesting.

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

Now it's not a joke

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

Unusual time but hope for a positive delta rating.

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

omg 3 version E round

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

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

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

Expect three versions of E and hopefully increase ratings.

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

Go to Pupil bruhh

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

Wishing everyone the best possible work!

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

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

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

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

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

will E3 >3000 ?

»
3 года назад, скрыть # |
 
Проголосовать: нравится -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 (?).

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

Good luck & Have fun!

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

hope to be Expert:D

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

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

Hardforces :(

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

ahhh

160858923d467feaaa9de5c134246a22

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

What do those Belarusian students eat?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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

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

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

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

How to solve B? Can anyone help.

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

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

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

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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)

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

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

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

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

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

Amazing contest, E problem is really cool!

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

Hardest C I've ever seen :(

I spend more than a hour to solve it.

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

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

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

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

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

Loved problem D! very educational problem

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

Mathforces

»
3 года назад, скрыть # |
 
Проголосовать: нравится 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;
}
  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 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. :)

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

    Maybe my code can help.199651953

»
3 года назад, скрыть # |
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

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

WA on pretest 4 for 4 times on problem 4

OMG

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

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится 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. :)

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

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

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

Wonderful round with interesting problems

»
3 года назад, скрыть # |
 
Проголосовать: нравится 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.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 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.

»
3 года назад, скрыть # |
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.

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

199684592 any idea why it gives Run Time ?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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.

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

When will tutorial be posted?

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

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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.

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

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

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

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

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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 ...

»
3 года назад, скрыть # |
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

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

Nice round.

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

What about the cheater raid this time?

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

![ ](ruban)

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

For C,I code for an hour but Failed at Pretest.
Maybe D cost less time on coding than C.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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 = =

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

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

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +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.

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

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

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

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

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

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

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

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

Spoiler
»
3 года назад, скрыть # |
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://mirror.codeforces.com/submissions/SamyakSinghania

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

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится 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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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 :)

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

Nice balance of round

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

Any predictions of E1,E2,E3 rating?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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

»
3 года назад, скрыть # |
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

»
3 года назад, скрыть # |
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

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

Can anyone help me debug why my Digit DP solution is not working?

My Solution

»
3 года назад, скрыть # |
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://mirror.codeforces.com/contest/1808/submission/199734771

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

Finally reached pupil after 39 contests.

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

How to solve E2/E3?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 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?

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

Editorial when?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +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.

  • »
    »
    3 года назад, скрыть # ^ |
    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://mirror.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.
        }
    }
    
    • »
      »
      »
      3 года назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        3 года назад, скрыть # ^ |
        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
        --+---------------------------------->
          |
        
»
3 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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

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

A good contest!

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

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится -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.

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

Why the picture in E3 uses gaster language?