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

Автор okwedook, 4 года назад, перевод, По-русски

Привет, Codeforces!

Я рад пригласить вас принять участие в Codeforces Round #870 (Div. 2), который состоится в 05.05.2023 17:35 (Московское время). Раунд будет рейтинговым для участников с рейтингом менее 2100. Участники из первого дивизиона могут принять участие в раунде вне конкурса.

Вам будет предложено 6 задач и 2 часа чтобы их решить. Все задачи раунда придуманы и подготовлены мной. Одна из задач будет интерактивной, пожалуйста ознакомьтесь с гайдом для интерактивных задач перед контестом.

Я также хочу поблагодарить:

Разбалловка: $$$500-1000-1500-2000-2750-3250$$$.

Не забудьте прочитать ВСЕ задачи. Желаю вам удачи и высокого рейтинга!

Я старался сделать хорошие задачи и понятные/короткие условия, так что надеюсь вам понравится раунд и вы найдете задачу под себя :)

UPD: Разбор

UPD: Победители и первое полное решение

Div1 + Div2

Место Участник
1 A_G
2 Rubikun
3 kotatsugame
4 244mhq
5 risujiroh

Div2

Место Участник
1 Perfectt
2 Hovery
3 UmajiHidakata
4 ivatopuria
5 wrihapcod

Первое полное решение

Задача Участник
A arvindf232
B A_G
C ksun48
D kaiboy
E NetSpeed1
F triple__a
  • Проголосовать: нравится
  • +136
  • Проголосовать: не нравится

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

div2 round witih more div1 testers. not good.

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

Contest with short statements. I hope we'll enjoy.

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

Div.2 round with "3250" point's problem, quite interesting.

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

Ha felt like forever since the last contest.

Excited to take part in this contest.

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

No 'As a tester' comment, interesting

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

hoping for easy A this time ;)

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

Good luck for all of us

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

Looking forward to be sad like him

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

Div √2

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

Thanks for the toughest contest I have ever seen.

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

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

Hardest A, A took me longer than B and C combined.

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

Problem E — F ratings are different from the blog post. Neither that it matters to me. xD ... cos I solved none of it.

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

Toughest A or Easiest C?

»
4 года назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится
  • 13 minutes for D
  • 26 minutes for C
  • 10 minutes for B
  • 45 minutes and 5 wrong answers for A.

Weirdest contest for me.

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

how to solve E?

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

RIP my rating. That first problem was brutal and then I struggled on the second after :(

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

How to optimize in Problem E

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

include <bits/stdc++.h>

using namespace std;

define int long long int

int32_t main() { int t; cin>>t; while(t--) { int n; cin>>n; int a[n]; for(int i=0;i<n;i++)cin>>a[i]; vectorv; for(int i=0;i<((n+1)/2);i++) { int k= abs(a[i]-a[n-i-1]); if(k==0)v.push_back(-1); else v.push_back(k); }

int ans=-1;
    int cnt=0;
    for(auto x:v)if(x!=-1)cnt=1;
    if(cnt==0)
    {
    ans=0;
    cout<<ans<<endl;
    }
    else if(cnt!=0)
     {
         vector<int>v1;
         for(auto x:v)if(x!=-1)v1.push_back(x);
        int ans=v1[0];
        for(int i=1;i<v1.size();i++)ans=__gcd(ans,v[i]); 
        cout<<ans<<endl;
     }

}

}

I am getting WA at 4 testcase please help me asap

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

So apparently every single one of the testers saw A and solved it and though that it's a good idea to put something like that in the contest?

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

Difficulty jump from D to E is too much. Up till task D it feels like div 3

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

Any hints for C and D

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

great contest! thanks

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

Codeforces Round 657 vibes

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

Can someone tell where can I find some similar problem to practice :(

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

F is an absolute joke. Just query y=0, x=0, y=240x

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

Very cool problem

2023-05-05-192456

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

Problem A is very hard for me and i can't even solve A in the contest...

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

can anyone please give hints for problem E.

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

C is easier than A,,,Hardest A ever...

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

Хотелось бы поменьше задач вида А-С и побольше вида Д-Е. Вцелом контест понравился, спасибо за труд)

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

Was D a dp problem ? Hope to become specialist this time.

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

As a newbie, I started doubting myself when I was unable to solve A, but looks like it is really a tough problem. Now waiting for someone to post it's solution.

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

    Enumerate possible answers and verify them one by one.

    Bonus: you can do better than pure brutal-force. Although it's not needed given the data scale.

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

    We can brute force on the number of liars. lets call this number x. We go from x = 0 to n

    So lets check, is 0 liars possible? 1 liar possible? is 2 liars possible? and so on. We run through the array, checking if arr[i] > x, that person is lying for that value of x, because they are saying that there are at least arr[i] liars. We increase the liar count

    Now, if the liar count == our projected value of liars x, we print x. Otherwise, we cannot determine the liars, so we print -1.

    https://codeforces.me/contest/1826/submission/204635985

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

      thanks for such a simple solution. I often do this mistake of over optimizing the first problems of contests instead of trying out bruteforce :(

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

        I kinda made that mistake as well, I kept trying to see a pattern and how to best determine the number of liars and so on.

        This is a good learning point for me as well, because next time if I cannot think of the optimal solution for A I will just bruteforce it if the constraints are good

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

    Yea this A was a complete shitshow. Since it's been solved by less than 5000 people, I think this problem A takes the reward for the hardest A since America was discovered.

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

    after spending more than hour and 3 Wa the solution is very easy , you can just brute force all possible number of liars from i = 0 to i = n and count every one who said that there is a bigger number of liars as a liar(cnt++) if the counter of liars == i then thats your answer

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

Problem B is from past contests.

Problem Link: https://codeforces.me/gym/102035/problem/I

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

Did anyone have the same problem as me in C? I figured it out pretty quickly and tried using a sieve to implement it. Kept on getting TLE on 4. preset tho...

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

    I looked at your submission and you found primes up to $$$10^6$$$ when you only need to find primes up to $$$10^3$$$.

    This is because you only need to find the lowest prime factor, and the lowest prime factor of a number $$$n$$$ is at most $$$\sqrt{n}$$$

    As a result, in the worst case, you need to check every single prime up to $$$10^6$$$ for each test case. And there are roughly $$$8\times 10^4$$$ primes that you need to check in that case. Given that there are $$$10^5$$$ testcases, this is far too slow.

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

Yay, Pupil!!!

For me, A was quite impossible, I think I had a decent idea, but couldn't implement it. Spent at least forty-five minutes attempting it just to get nowhere. Similar to the last contest, A was really difficult to understand resulting in A being difficult for me and I ended up spending >15 minutes re-reading it over and over. Although, both B and C were far easier, all A, B, and C seemed to be fairly tricky.

Anyways, thanks for the contest, the problems were really enjoyable. I need to think about A more!

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

A: Brute force for all possible numbers of liars from 0 to n.

B: To make a[1]%x==a[n]%x we must have x is a divisor of abs(a[1]-a[n]). So the answer is the gcd of abs(a[i]-a[n+1-i]) for 1<=i<=n/2.

C: If m is a divisor of n, m can remain the same after voting, otherwise m must be decreased. So if m < the minimal prime factor of n, m will be decreased to 1.

D: Let the indexes of sights we pick are i, j, k from left to right, then definately we will let L=i, R=k. So we just need to find the minimum of b[i]+b[j]+b[k]-(k-i)=(b[i]+i) + (b[k]-k) + b[j], where i<j<k. We can do this by pre-calculating the prefix-maximum of (b[i]+i) and the suffix-maximum of (b[k]-k).

E: If model u can be ordered before model v, for all i we have r[i][u]<r[i][v]. So we can build a DAG (directed acyclic graph) in O(m*n^2), and we can solve the problem by toposort and dp. Naive approach will get TLE and we can optimize this solution to O(m*n^2/w) by bitset, which could pass the pretest (and hopefully system test).

PS: Is there any O(m*n) solution of E? I think there must be something faster than O(m*n^2) but I can't come up with it.

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

    What I tried was, first sort all people by the first city. Now we have permutation [0,1,...N]. I sort this permutation by every city, while ensuring that inversions are always created and never destroyed. This is because for some person X > person Y, this should hold in every city. So inversion created in any one city always stays. After sorting by every city we can simply take LIS. But I didn't get AC

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

    I mis-implement the biset so it OOM for me... rather than solve the OOM issue, I chose to sqrt-decomp it but failed to finish before deadline. With sqrt-decomp it should get O(mnlogn, n^2, m*n*sqrt(n))~=O(m*n*sqrt(n)).

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

    It may seem obvious, but in problem A you can get non-brut force solution if you sort all numbers in non-ascending order and without loss of generality assume that liars told the first k numbers, and try to find maximum possible k.

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

Problem B was exanctly this problem

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

Is there any solution for problem E that is faster than O(n^2*m/w), like O(mn+n^2) ? I tried to find a O(m*n) solution to compute all pairs of i,j that j can go after i, but failed.

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

B was google-able, solved it after finding this which is the first link when you google "largest number that gives same modulo for 2 numbers"

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

I hate E

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

You can solve problem 1826E - Walk the Runway in $$$O\left(n^2 \times m\right)$$$ in C++ without bitsets. Based on naive $$$O\left(n^2 \times m\right)$$$ approach, you need to apply next optimizations one-by-one for getting 1872 ms.

Optimization 1
Optimization 2
Optimization 3
Optimization 4

Accepted 1872 ms submission

Optimization 5 for getting 1200 ms

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

The problem C is copied from https://codeforces.me/gym/433264/problem/F

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

I'm stupid and had to do a bunch of random tests for B to find out the set of possible answers for a mod x = b mod x are the factors of abs(a-b). From there, I didn't realize that it's literally just equivalent to GCD XD

Got TLE 8 on that sadge

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

For E), I had the following DP recurrence:

$$$\text{dp}[i] = \text{p}[i] + \max(\text{dp}[j] \; \forall j \gt i \land r[t][i] \lt r[t][j] \; \forall t \lt m)$$$

and I think it runs in

$$$O(mn^2)$$$

Never would have thought to use bitsets though, I was trying to optimize it to either

$$$O(n^2) \text{ or } O(mn \log n)$$$

because it looked suspiciously similar to longest increasing sequence.

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

10134 — 6367 = 3767 participants (37.2%) can't solve a single problem!

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

In problem D, I made this 204647760 during the contest and after about 20 minutes I realized that it can be hacked with a test case like this:

1

100000

1 1 2 3 4 5 6 7 .....

The reason is that I use -1 to check if I visited a state in dp or not and the above test produces -1 a lot which mean the dp will recompute states which was computed before, so I made another submission to avoid this mistake.

But after the contest, I submitted the first solution again and it passed the tests of the problem with about 46 ms , I think that this test should be added to main tests!

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

I liked the contest, it was nice. But E is so bad

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

My E solution with bitset took 2800 ms :(

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

I found a tricky way to exclude those pairs without ordering fast: if a[i]<b[i] for evety i, then sum(a)<sum(b), min(a)<min(b), max(a)<max(b). Problem E, a 592 ms solution without using bitsets.

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

Problem B was written in GYM before:

B- https://codeforces.me/problemset/gymProblem/102035/I

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

Ratings updated preliminary, it will be recalculated after removing the cheaters.

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

good contest, problems were quite interesting, i am able to prove my solutions of a b and c!

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

Problem A.. Uff..

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

Has anyone come up with a dp solution for problem d?

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

My code can pass the example on my computer but failed when testing. Can somebody help me ? My code