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

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

1945A - Разбиваем лагерь

Идея: Kirill_Maglysh

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

1945B - Фейерверки

Идея: NToneE, Gadget

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

1945C - Левые и правые дома

Идея: Gadget, NToneE

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

1945D - Филин Серафим

Идея: Kirill_Maglysh

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

1945E - Бинарный поиск

Идея: Kirill_Maglysh

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

1945F - Кирилл и грибы

Идея: Kirill_Maglysh

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

1945G - Повар и каша

Идея: Kirill_Maglysh

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

1945H - НОД больше

Идея: Kirill_Maglysh

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

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

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

E was subtle

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

E was subtle

»
9 месяцев назад, # |
  Проголосовать: нравится 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$$$.

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

    can you explain the first sample test case of D. the answer should be swap with place 2 and pay 3+8 = 11. how is it 14?

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

      If we swap with the 2nd position, you also must pay $$$b_n = 5$$$ because initially you will stand in $$$n+1$$$ place and this give you $$$16$$$. I'll simulate the solution for the first test case

      Consider $$$dp_4 = 9$$$, so we move on to $$$dp_3$$$, we must choose:

      $$$dp_3 = \min\{a_i+dp_{i+1}, a_i+dp_{i+1}-a_{i+1}+b_{i+1}\}$$$
      $$$dp_3 = \min\{6+dp_{4}, 6+dp_{4}-9+5\}$$$
      $$$dp_3 = \min\{15, 11\}$$$

      $ So, $$$dp_3 = 11$$$. The second part of the $$$\min$$$ function represent that we consider took $$$b_{i+1}$$$ instead of $$$a_{i+1}$$$, in this case $$$dp_3$$$ choose $$$b_4$$$ because if we want to reach $$$i=3$$$, it will be optimal to choose $$$a_3+b_4$$$. At this moment we have $$$dp_3=11$$$, so we will calculate $$$dp_2$$$ as follows: $$$dp_2 = \min(3+11, 3+11-6+8) = \min(14, 16)$$$ so $$$dp_2 = 14$$$ and actually this is the minimum value for $$$dp_i, 1 \le i \le 2$$$. This solution says that is optimal to choose $$$a_2+a_3+b_4$$$.

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

    CAN you please explain how did this expression for the dp come? what i mean is that what is the logic behind this expression

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

Problem E Video Editorial Audio : (Hindi)

YOUTUBE VIDEO LINK ---Click Here

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

There's actually quite an elegant implementation for problem F:

https://codeforces.net/contest/1945/submission/252463604

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

Please guys, l'd like to know why I het a WA? Problem F: https://codeforces.net/contest/1945/submission/252370876

Thanks.

»
9 месяцев назад, # |
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.

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

    Let's consider the first launch station.

    When the station has its first launch, you can construct the following interval $$$I=[a, a+m]$$$, where $$$I$$$ represents all the moments in which a firework $$$x$$$ is visible.

    Let's say $$$a=6$$$ and $$$m=4$$$, then $$$I=[6,10]$$$. If we want to count the maximum number of fireworks in this interval, it's clearly $$$\lfloor\frac{10}{6}\rfloor=1$$$, which is when $$$x=6$$$ (the next $$$x$$$ is $$$12\notin I$$$).

    Now you do the same for the second launch station $$$b=7$$$, and the answer becomes $$$\lfloor\frac{10}{6}\rfloor + \lfloor\frac{11}{7}\rfloor= 2$$$.

    Formally, $$$ans=\lfloor\frac{a+m}{a}\rfloor + \lfloor\frac{b+m}{b}\rfloor$$$ , which is $$$2 + \lfloor\frac{m}{a}\rfloor + \lfloor\frac{m}{b}\rfloor$$$

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

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

252626826

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

Solving B using binary search - The key to solve this problem lies in the concept of binary search on the answer. We aim to find the largest integer value x such that x * a — a <= m.

  • We start by initializing a binary search range with st = 0 and en set to a sufficiently large value, say 10^20 (we can't in c++ so use python). Then, we perform a binary search within this range. At each step, we calculate the midpoint mid and check if mid * a — a <= m. If this condition holds true, it means we can increase our search range. Thus, we update st = mid. Otherwise, we need to decrease our search range, so we update en = mid — 1. We repeat this process until we find the maximum valid value for x. This process has a time complexity of O(log n).

  • We apply the same binary search approach to determine the maximum number of fireworks launched at intervals of b, 2b, 3b, and so forth.

  • Finally, we sum the maximum values obtained from both binary searches to obtain the total maximum number of fireworks launched within the given time frame m. This sum represents our answer. https://codeforces.net/contest/1945/submission/252638271

»
9 месяцев назад, # |
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."

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

Well For the Problem E only one swap is sufficient in every case ? my solution got accepted but don't know how....? can anyone explain

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

nvm, i got it lol good contest btw

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

For C,why n/2, it's a real number didn't mention in the problem statement?

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

Can someone please help me in finding my mistake for submssion 252896905 to problem F?

»
9 месяцев назад, # |
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.

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

    Question does say

    "If several schoolchildren return at the same time, they will return to the queue in ascending order of their si."

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

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

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

    We know this binary search gives a number which is always <=X. (If you are not sure about that, you can try some examples.)

    Assume P is position of X.

    If we change this result and P, we can find X. Because only once we asked to P. And smaller number will give same answer(make l = mid). So we will get same index before don't swapped P and result.

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

https://codeforces.net/contest/1945/submission/253021750

why this solution is giving runtime error on testcase 2 in problem D

»
9 месяцев назад, # |
  Проголосовать: нравится 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

»
9 месяцев назад, # |
  Проголосовать: нравится 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

  • »
    »
    9 месяцев назад, # ^ |
      Проголосовать: нравится +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 $$$> 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

    • »
      »
      »
      9 месяцев назад, # ^ |
      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

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

Understanding problem statement C is 80% and solving it is 20%. Problem statement of [problem:C] is really confusing.

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

for D question is tough to understand

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

Someone please explain what this line means in tutorial for problem H: "We will iterate through each of these numbers as one of the red numbers, and iterate through the second one for n " , where are we iterating for second number and how? Need some explanation .

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

Folks, wanted to validate an alternate brute complex idea for problem E.

The binary search tree of ranges would consist of 2n-1 nodes at max, with depth of log2n.

Each leaf node is the node where the search ends, we can try to find the total number of swaps required for the number to be at this node, were the binary search to happen from root to this leaf node.

Any leaf node that requires <= 2 swaps would be an answer.

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

Problem D editorial contains typo, $$$b_k$$$<$$$a_k$$$ should be there.

»
9 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
$$$\Huge \text{hello!!!}$$$
»
8 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Problem D

before reaching the position m why not simply take the minimum of a[i] and b[i] ?? and then consider the sum of pref and bSum ??

something like this

int n,m; cin >> n >> m;

vector<int> a(n);
vector<int> b(n);


for (int i = 0; i < n; i++)
{
    cin >> a[i];
}
for (int i = 0; i < n; i++)
{
    cin >> b[i];
}

if(m==n){
    cout << a[n-1] << endl;
    return;
}

long long ans = 0;
long long c = 0;
for (int i = n-1; i >=m; i--)
{
    ans+=min(a[i],b[i]);
}
long long ans1=1e18;

for (int i = m-1; i >=0; i--)
{
    ans1 = min(ans+a[i]+c,ans1);
    c+=b[i];
}





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

    i did same during practice for D void solve() { ll n, m; cin >> n >> m;

    vl a(n), b(n);
    
    for (auto& it : a) {
        cin >> it;
    }
    
    for (auto& it : b) {
        cin >> it;
    }
    
    
    ll sum = 0;
    
    ll ans = 1e18;
    
    for (int i = n - 1; i >= 0; --i) {
        sum += min(a[i], b[i]);
        if (i < m) {
           ans = min(ans, sum - min(a[i], b[i]) + a[i]);
        }
    }
    
    cout << ans << '\n';
    

    }

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

Problem B: Please explain this line: At the moment x, there will be fireworks in the sky, released at moments [x, x+a, …, x+a⋅⌊m/a⌋[user:Gadget].

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

Hey anyone can you tell me about what is the wrong with the constraints for the problem C here. I would like to know what is the error in my code here. I can't figure it out

void solve() { ll n; cin >> n; string s; cin >> s;

vector<int> right(n+1);
right[n] = 0;
for(int i=n-1; i>=0; i--){
    right[i] = (s[i] == '1') + right[i + 1];
}

int mini = 0, diff = n;
int cnt = 0;
for(int i=0; i<n; i++){
    cnt = cnt + (s[i] == '1');
    int left0 = i + 1 - cnt;
    int right1 = right[i+1];

    int atlL = (i + 1) / 2 + (i + 1) % 2;
    int atlR = (n - i - 1) / 2 + (n - i - 1) % 2;

    if((left0 >= atlL) && (right1 >= atlR) && abs(n - 2*(i + 1)) < diff){
        mini = i + 1;
        diff = abs(n - 2*(i + 1));
    }
}

cout << mini << endl;

}

Your code here...
»
7 месяцев назад, # |
  Проголосовать: нравится 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

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

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

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

I think there is an error in editorial of problem D

Spoiler
»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
// this is code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i=a; i<=b; i++) 
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
 
typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll>
pll; typedef pair<string, string> pss; typedef vector<int> vi;typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll>
vl; typedef vector<vl> vvl;

 
double EPS = 1e-9;int INF = 1000000005; long long INFF =
1000000000000000005ll; double PI = acos(-1); int dirx[8] = { -1, 0, 0,
1, -1, -1, 1, 1 }; int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };


int main()
{
 ios::sync_with_stdio(false);
  cin.tie(0);

  ll t;cin>>t;
  while(t--){
  	ll n,m;cin>>n>>m;

  	vl a(n+1,0);for(int i=1;i<=n;i++)cin>>a[i];
  	vl b(n+1,0);for(int i=1;i<=n;i++)cin>>b[i];

  	ll sum=0;
  	// ll i=n;
  	while(n>m){
  		sum+=min(a[n],b[n]);
  		n--;

  	}
  	if(m==1){
  		sum+=a[m];

  	}
  	
  	else{
  		sum+=min(b[m]+a[m-1],a[m]);
  	}


  	// sum+=min()
  cout<<sum<<endl;
  }

} 

}

what test case does this miss for D problem cant we just smaller between a[i] and b[i] as we can anyways stop at any index.