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

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

1945A - Setting up Camp

Идея: Kirill_Maglysh

Разбор
Решение

1945B - Fireworks

Идея: NToneE, Gadget

Разбор
Решение

1945C - Left and Right Houses

Идея: Gadget, NToneE

Разбор
Решение

1945D - Seraphim the Owl

Идея: Kirill_Maglysh

Разбор
Решение

1945E - Binary Search

Идея: Kirill_Maglysh

Разбор
Решение

1945F - Kirill and Mushrooms

Идея: Kirill_Maglysh

Разбор
Решение

1945G - Cook and Porridge

Идея: Kirill_Maglysh

Разбор
Решение

1945H - GCD is Greater

Идея: Kirill_Maglysh

Разбор
Решение
Разбор задач Codeforces Round 935 (Div. 3)
  • Проголосовать: нравится
  • +38
  • Проголосовать: не нравится

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

For problem G the editorial has the swapped inequality it should be suffixMax_p >= k(Q2_front), because that indicates there is a larger k in the suffix of Q1 that highest priority person in Q2 would be waiting behind.

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

For problem D we can consider a dp approach: let $$$dp_i$$$ the minimum ammount of coins for reach the position $$$i$$$, thus:

$$$ dp_i= \begin{cases} a_n & \text{if } i = n \\ \min\{a_i+dp_{i+1}, a_i+dp_{i+1}-a_{i+1}+b_{i+1}\} & \text{otherwise} \end{cases}$$$

We can calculate solutions from $$$dp_1$$$ and choose $$$\min\limits_{1 \le i \le m}{dp_i}$$$. The basic idea is to choose between pay $$$b_i$$$ or $$$a_i$$$ for all $$$i$$$.

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

Problem E Video Editorial Audio : (Hindi)

YOUTUBE VIDEO LINK ---Click Here

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

At problem B,

"At the moment x, there will be fireworks in the sky, released at moments [x, x+a, …, x+a⋅⌊m/a⌋]"

Please explain.

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

Problem F can be simulated with an ordered statistic tree :p

252626826

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

In C sample 1.

3
101
outut:2

"can't we insert at 0 the villagers to right side 2 of 3 are satisfied ?

If there are multiple suitable positions i with the minimum ∣n2−i∣, output the smaller one."

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

nvm, i got it lol good contest btw

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

I think the problem G's statement is still not 100% clear. If 2 students with the same priority, finishing their dishes at the same time, who will go to the queue first?

I tried to solve this solve this by assuming the one who goes out eating first will come back first, but apparently this seems to not be the case. The comparator function in the solution prioritize the student with higher eating time first. This seems very unnatural to me.

Though the problem idea didn't change much if a more strictly description was added. This is still a cool problem. Though this bug me for hours, not know where I was wrong.

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

Can anyone explain E? Not able to get it from the tutorial.

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

H's tutorial is no unclear i'd love if somebody explains what the tutorial wants us to do i only understand why its always beneficial to take 2 numbers as the red and that the AND cant be less than the AND of the entire array , i dont get the rest ( the middle paragraph ) such as

we if a cet certain bit y is equal to zero in more than two numbers

Why more than 2 numbers ? if we have the bit x 0 in a certain number then it'll be 0 in the AND unless we take that number as red ?? so many questions

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

in problem H why if a bit is 0 in more than 2 numbers then its 0 in the AND ? i understand that if we have 3 or more numbers with bit x 0 in them then it'll always be zero in the finally AND but sometimes we can have only 1 number with bit x equal to 0 and still the finally AND will have that bit 0 if we dont consider it in the red numbers ? the middle paragraph is unclear hope somebody rewrites it in a more clear way , thanks

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

    Your understanding is correct. Suppose we are dealing with $$$x^{th}$$$ bit. There are 3 cases:

    1. None of the numbers contain a 0 at this position : The AND would contain 1.
    2. There are $$$ \gt 2$$$ 0 at this position. The AND would contain 0.
    3. There are 1 or 2 zero at this position. Then, we are not sure about the AND. But, let's pick one element with zero at this position, move it to the blue set, and then, let's try to pair it up with all possible elements. If no match could be found, then we know for sure that the element belongs to the red set, hence making the AND zero.

    I've added more details here

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

      Yea thanks I got it , it wasn't clear at the beginning I feel like it would've been more clear if they stated why we try all numbers where the bit is 0 in no more than 2 but now that I get it I feel like it's self explanatory

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

Problem F. Kirill and Mushrooms can actually be solved using Fenwick Tree:

Let us fix the number of mushrooms for a potion. Let this number be $$$k \leq n$$$. Now we have to maximize the minimum value that we choose for this potion. This number is the $$$k-th$$$ maximum, lets call this number $$$mxmin$$$. And we update the answer with $$$ans=min(ans,mxmin*k)$$$.

Fenwick Tree allow us to find the $$$k-th$$$ maximum, wich is equivalent to findind the $$$(rem - k + 1)-minimum$$$ with BinaryLifting. Where $$$rem$$$ is the remaining number of mushrooms. You can find how to do this in this blog

When we go from $$$k$$$ mushrooms to $$$k+1$$$ mushrooms we have to update the FenwickTree by subracting the value of the $$$p[k]$$$ mushroom.

See the code for any other detail: My submission

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

For problem F you can just use order statistic tree and use find_by_order to solve in nlogn time.

»
20 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
#include <bits/stdc++.h>
using namespace std ;
#define ld long double
#define ll long long
int fact[400001] = {0};
vector<vector<int>> num(400001);
vector fst(400001,vector<int>(20,0));
unordered_set<int> s;
int mul = 1;
void gen( vector<int> &num, int in = 0 ) {
    if( in == num.size() ) s.insert(mul);
    else {
        mul *= num[in];
        gen(num,in+1);
        mul /= num[in];
        gen(num,in+1);
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    fact[1] = 1; 
    for( int i = 2; i <= 4e5; ++i )
    if( fact[i] == 0 )
    for( int j = i; j <= 4e5; j += i )
    if( fact[j] == 0 ) fact[j] = i; 
    int tt = 1;
    cin >> tt;
    while( tt-- ) {
        int n, k, flag = 0, x; 
        cin >> n >> x;
        int miny = (1<<20), inx, iny;
        vector<int> a(n);
        int bit[20] = {0};
        for( auto &i: a ) cin >> i;
        sort( a.begin(), a.end() );
        for( int i = 1; i < n; ++i ) {
            if( (a[i-1] & a[i]) < miny ) {
                miny = a[i-1]&a[i];
                inx = i-1;
                iny = i;
            }
        }
        set<int> o;
        for( auto &i: a ) {
            int j = i;
            vector<int> pf;
            while( j != 1 ) {
                pf.push_back(fact[j]);
                j /= fact[j];
            }
            vector<int> stbit;
            for( int u = 0; u < 20; ++u ) 
            if( ((i>>u)&1) )
            ++bit[u], stbit.push_back(u);
            gen(pf);
            for( auto &u: s ) {
                o.insert(u);
                num[u].push_back(i);
                for( auto &h: stbit )
                fst[u][h]++;
            }
            mul = 1;
            s.clear();
        }
        for( auto k = o.rbegin(); k != o.rend() && flag == 0 ; ++k ) {
            int g = *k;
            if( num[g].size() < 2 ) continue;
            int sz2 = n - num[g].size();
            int y = 0;
            for( int i = 0; i < 20; ++i )
            if ( bit[i] - fst[g][i] == sz2 )
            y += (1<<i);
            if( y + x < g && sz2 >= 2 && sz2 <= n-2 ) {
                flag = g;
                break;
            } 
            for( int u = 19; u >= 0 && flag == 0 ; --u ) 
            if( (y>>u)&1 ) {
                int d = -1;
                for( int i = 0; i < num[g].size(); ++i ) 
                if( num[g][i] != -1 ) {
                    if( d == -1 && ((num[g][i]>>u)&1) == 0 ) d = i;
                    if( d != -1 && (y&num[g][i]) < (y&num[g][d]) ) d = i;
                }
                if( d != -1 ) {
                    sz2++;
                    y = y&num[g][d];
                    num[g][d] = -1;
                }
                if( y + x < g && sz2 >= 2 && sz2 <= n-2 ) {
                    flag = g;
                    break;
                } 
            }
            if( sz2 == 0 ) {
                sz2 = 2;
                y = miny;
                num[g][inx] = num[g][iny] = -1;
            } else if( sz2 == 1 ) {
                sz2 = 2;
                int d = -1;
                for( int i = 0; i < num[g].size(); ++i ) {
                    if( d == -1 ) d = i;
                    if( d != -1 && (y&num[g][i]) < (y&num[g][d]) ) d = i;
                }
                y = y&num[g][d];
                num[g][d] = -1;
            }
            if( y + x < g && sz2 >= 2 && sz2 <= n-2 ) {
                flag = g;
                break;
            } 
        }
        if( flag != 0 ) {
            cout << "YES\n";
            vector<int> v1, v2;
            for( auto &i: num[flag] )
            if( i != -1 )
            v1.push_back(i);
            int i = 0;
            for( auto &j: a )
            if( i >= v1.size() || v1[i] != j ) v2.push_back(j);
            else ++i;
            cout << v1.size() << ' ';
            for( auto &i: v1 ) cout << i << ' ';
            cout << '\n' << v2.size() << ' ';
            for( auto &i: v2 ) cout << i << ' ';
            cout << '\n';
        }
        else cout << "NO\n";
        for( auto &i: o ) {
            num[i].clear();
            fst[i] = vector<int>(20,0);
        }
    }
}

this code for h but get wrong answer at testcase 3.Had tried stress test but not found any

kindly help me to debug this

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

E is interesting , I see