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

Автор awoo, история, 6 лет назад, По-русски

1469A - Правильная скобочная последовательность

Идея: BledDest

Разбор
Решение 1 (BledDest)
Решение 2 (BledDest)

1469B - Красные и синие

Идея: BledDest и adedalic

Разбор
Решение 1 (Ne0n25)
Решение 2 (pikmike)

1469C - Построение забора

Идея: adedalic

Разбор
Решение (adedalic)

1469D - Деление с округлением вверх

Идея: adedalic

Разбор
Решение (adedalic)

1469E - Немного похожи

Идея: BledDest

Разбор
Решение (BledDest)

1469F - Розетки

Идея: adedalic

Разбор
Решение (pikmike)
  • Проголосовать: нравится
  • +121
  • Проголосовать: не нравится

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

Here is an attempt to make a unofficial video editorial of Educational Round 101 by COPS IIT BHU (in Hindi-English) (Problem A-E).

Do check it out.

https://codeforces.me/blog/entry/86076

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

Pretty optimal solution of D if you fixed 8 and all other numbers from 3 to n-1 divide by n to obtain 1. These numbers are n-4, and after that will remain 9 operations. So you can obtain 1 from n in no more than 6 operations, and 1 from 8 in 3 operations. Since there is don't need to build binary search, this solution will be realised much faster

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

I'm little bit confused about this test case for problem A

"?))?"

shouldn't it return "NO"?

Or, am i missing something?

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

In problem C, suppose the last fence's ground level is Hn. Why can't Hn be between(inclusive) [mn[n-1]-(k-1),mx[n-1]+k-1]

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

Can someone explain C in simpler words , its tricky for me rightnow

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

    We have got an uneven ground (better if you think of them as unit wide platforms at possibly different heights) with level at point $$$i$$$ being $$$H[i]$$$ (size $$$n$$$).

    We also have n fence_wood_sections (fws) all of whose dimensions are same and more importantly height being $$$k$$$ (width assume unit length) and $$$i th$$$ fws is to be placed above point $$$i$$$ on the ground (whose height is denoted in H[i]).

    For all $$$1 \lt i \lt n$$$ we can keep the distance between ground and bottom of fws at max $$$k - 1$$$ (1st and last ones should have 0 distance from their respective ground levels) and each consecutive fws(es) should have a vertical overlap of at least 1 unit (as we need to glue / nail them together as we respect gravity). Now you are to tell whether this is possible to do or not.

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

    Keep the maximum and minimum y-coordinate of bottom each section from left to right. And then don't forget that last section must be in the land (coordinate h[n-1])

    Let's minimum of the current section is d, and maximum is u. The next section must touch the current one, so difference of its coordinates no more than k-1 by abs. value. Then minimum of the next section is max(h[i], d-k+1) and maximum is min(u+k-1, h[i]+k-1) where h[i] is the height of the next place

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

    Now I think you were asking for explanation of solution. Damn me.

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

    In very simple words, just go from 1 to n just keep track of all allowed bottoms for previous and with that compute the next allowed.It is simple and brute force solution question

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

Ended up doing 1469A — Regular Bracket Sequence using DP. Never read that there are only one '( and')' in the input string. Ended up costing me a lot of time thankfully the constrainst were quite small for a O(1) soln.

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

How to prove in D editorial that number of such segments isn't more than log(log n)?

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

    This SO answer has a pretty good explanation.

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

    We can observe that left boundary of segment can be represented by $$$n^{1/2^x}$$$ where $$$x$$$ is number of the segment , now process will stop when $$$n^{1/2^x} \lt =2$$$ , taking log both sides we get $$$(1/2^x)*logn \lt = C$$$ , where $$$C$$$ is constant depending on base of log (if base is 2 then C=1).

    Now equation can be written as $$$logn \lt =C*2^x$$$ . Take log both sides one more time , $$$log(logn) \lt = log(C)+x*C$$$ i.e $$$(log(logn)-log(C))/C \lt = x$$$ hence $$$x$$$ is $$$ceil((log(logn)-log(C))/C)$$$ , constant factors can be ignored , for log base 2 it will be $$$ceil((log(logn)-1))/2)$$$

    You can read properties of log if you are not able to get some step.

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

I can't understand the tutorial for question no.3 please help.

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

How to do A when the condition of only one ( and ) is removed?

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

    The first observation to make is that the length of the final string (when we replaced all the '?') should always be even and the count of '(' should be the same than the count of ')' (because '(' and ')' must balance themselves).

    Now, what we wanna do is find the most optimal way to place '(' and ')'.

    Let's imagine we placed some ')' before a '('. This is not optimal because maybe we will need the ')' later to close a '('. So placing all the '(' and then all the ')' will always be optimal.

    The algorithm is the following:

    • Place '(' till count('(') < len(s)/2

    • Then fill the remaining '?' with ')'

    • Check if the string is a valid RBS

    To check if the string is a valid RBS you need to maintain the balance of the parenthesis.

    Let's assume that '(' is +1 and '(' is -1.

    1. The total balance should be 0 (because we need to have the same ammount of '(' and ')' )
    2. At each index of the string, the current balance must be >= 0. In fact, if the balance is negative at index i, then we have more ')' than '(' in prefix [0, i] of the string.

    PS: what I mean by balance of prefix [0, i] is just the sum of the value of the parenthesis from index 0 to index i

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

Anyone help me where my code is getting wrong for problem E ?

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

Wow, Eduactional Round 101 getting exactly 101 contribution

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

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int m,n;
        cin>>m;
        vector<int>v(m),v1(n);
        for(int i=0;i<m;i++)
            cin>>v[i];
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>v1[i];
        int maxi=0,run_max=0;
        for(int i=0;i<(min(m,n));i++)
        {
            run_max+=v[i];
            if(run_max>maxi)
                maxi=run_max;
            run_max+=v1[i];
            if(run_max>maxi)
                maxi=run_max;
        }
        int i=min(m,n);
        for(int j=i;j<max(m,n);j++)
        {
            if(m>n){
                run_max+=v[j];
                if(run_max>maxi)
                    maxi=run_max;
            }
            else if(m<n){
                run_max+=v1[j];
                if(run_max>maxi)
                    maxi=run_max;
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}

What is wrong with this code for B it shows runtime error on test 2

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

D problem has cheat-solution.

We can for one operation remove number $$$a_x$$$ from array if $$$\exists y, a_x \lt a_y$$$. So let's delete all numbers except $$$n$$$(we can't remove it). Also we won't delete $$$2^k, 2, \lfloor{\sqrt{n}} \rfloor$$$. Using two operations we can divide $$$n$$$ to $$$\dfrac{n}{\lfloor\sqrt{n}\rfloor} = n^\prime$$$ and $$$\lfloor{\sqrt{n}} \rfloor$$$ to $$$1$$$. Then let's divide $$$n^\prime$$$ by $$$2^k$$$ until it is $$$1$$$. So if $$$d(n , k)$$$ is number of operations needed to divide number $$$n$$$ by $$$2^k$$$, we need $$$d(n^\prime, k)$$$ operations to do it. Also we need to divide $$$2^k$$$, it will take $$$k$$$ operations. We will use $$$(n - 5) + d(n^\prime, k) + k + 2$$$ operations, so we need $$$d(n^\prime, k) + k + 2 \leqslant 10$$$, which can be easily secured. In my case $$$k = 2$$$ worked. (for all numbers less than $$$1000$$$, $$$d(x, 2)$$$ will be less than $$$5$$$)

Maybe we can find such $$$k$$$, that we don't need to reduce $$$n$$$ to $$$n^\prime$$$. It is much easier than author's solution, and also can be easily implemented, and it doesn't need observations like "number of iterations needed sqrt to become 1 is $$$\log \log n$$$"

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

It's possible to solve F in $$$O(n)$$$.

The bound on the $$$l$$$ values means these can be sorted in linear time. Moreover, instead of doing range updates, we can simply save where the two ends of the chain currently being used will end. This allows us to just iterate through the $$$cnt$$$ array. Solution: 103280970 (unfortunately probably unreadable) and some C++ nerds could probably speed up this idea to get the lowest execution time here too.

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

In the explanation of problem C, can anyone explain why does a solution exist if the condition given in the tutorial is satisfied

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

...

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

Can anyone please help me determine why this submission is passing the tests even though it's O(n^2)? Submission for example, consider this testcase:100000 1 100000 99999 99998 99997....

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

literally the most naive solution in history I just do what the statement allows https://codeforces.me/contest/1469/submission/306660265

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

Can anyone explain about the test case (?)? in problem A? According to me the answer should be NO but they have given it as YES. why??

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

Another prefix sum ans for problem B: 353741055

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

hardest A ever (took 5 minutes instead of 2)