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

Автор Kirill_Maglysh, история, 5 недель назад, По-русски

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

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

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

E was subtle

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

E was subtle

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

    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?

    • »
      »
      »
      3 недели назад, # ^ |
      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$$$.

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

Problem E Video Editorial Audio : (Hindi)

YOUTUBE VIDEO LINK ---Click Here

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

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

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

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

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

Thanks.

»
5 недель назад, # |
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.

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

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

252626826

»
5 недель назад, # |
  Проголосовать: нравится 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.com/contest/1945/submission/252638271

»
5 недель назад, # |
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."

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

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

nvm, i got it lol good contest btw

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

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

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

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

»
5 недель назад, # |
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.

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

    Question does say

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

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

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

  • »
    »
    5 недель назад, # ^ |
    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.

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

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

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

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

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

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

    • »
      »
      »
      5 недель назад, # ^ |
      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

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

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

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

for D question is tough to understand

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

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

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

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

»
3 недели назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
$$$\Huge \text{hello!!!}$$$
»
2 недели назад, # |
  Проголосовать: нравится 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';
    

    }

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