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

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

1886A - Сумма трех

Идея: fcspartakm

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

1886B - Fear of the Dark

Идея: BledDest

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

1886C - Уменьшающаяся строка

Идея: Roms

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

1886D - Монокарп и множество

Идея: Roms

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

1886E - I Wanna be the Team Leader

Идея: BledDest

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

1886F - Кража бриллиантов

Идея: BledDest

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

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

amazing round loved it

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

amazing round loved it

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

Just become expert again Amazing contest

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

Just become expert again Amazing contest

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

What will be the expected difficulty for problem B it seems bit tough compared to other div 2 B Questions

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

    No it is pretty balanced. You need to know basic geometry and/or binary search

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

      I thought of using binary search at first, on w but w is floating point number. so how can we apply binary search on it can you please elaborate.

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

Thanks for slow editorial!

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

Div2 D Alternate explanation:

Consider ?<??>?>??

Observation : Last > will be n and last < be 1

This is always true. If 1 and n are always in the permutation could there be a > after n and < after 1? No. If there aren't any such symbols for either > or < they will be in 1st position .

However will the subsequent >s after last > also be n-1,n-2,n-3? And will the subsequent <s after last < also be 2,3,4.....?

The answer is No.

This is because we have ?s after last > and last < respectively. There we could put values So that we could form a decreasing sequence from n ( > > >) and an increasing sequence from 1 (< < <). There could be many such sequences clearly.

Now let's propose an algorithm,

?<??>?>??

Starting from the back we have n-2 choices where n is number of els in the set. This is because only the minimum(1) and maximum(N) is fixed. Now remove last element.

?<??>?>? again n-2 choices where n is number of els in the set.

?>??>?>

1 choice last > is fixed. Similarly last < is fixed.

?>??>? now last > is the max el in the set. We remove 2 els and N so far. Irrespective of our choices for the 2 els, there will be 1 unique maximum in the set which will take place of last >. So for ? we have n-2 choices again where n is number of els in the set.

Hope you get the solution.

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

    "However will the subsequent >s after last > also be n-1,n-2,n-3? And will the subsequent <s after last < also be 2,3,4.....?

    The answer is No."

    I made this wrong assumption and was wondering why my solution is wrong! Thanks for this. I never would have realised why my solution is wrong( This happens a lot to me, I make wrong assumptions and get to a wrong solution but I never find that wrong assumption on my own, and usually some other person points it out for me. I need to work on this by embracing the Sherlock's quote : "When you have eliminated the impossible, whatever remains, however improbable, must be the truth"

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

I don't understand why my solution for C didn't work. It passed the first test case fine, and was very similar to the expected output for the second testcase, so I was wondering where I went wrong.

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

Я балдею! Угробить на разбор случаев в А полтора часа, и за 15 мин. сдать В и С!

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

Problem C. Decreasing String ***** In this problem test number 2 in test case 5. The string is given "pbdtm" and the POS=8 If I select s1=pbdtm s2=pbdm s3=bdm s4=bd s5=b The condition is still right. Because s1>s2>s3>s4>s5 And the POS value of 8 is 'd'.. But why this is wrong answer?

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

    $$$s_2 = \tt{bdtm}$$$, not $$$\tt{pbdm}$$$

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

      i'm having same problem just wondering why ( s1= pbdtm -> s2 = pbdm )is not valid ???

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

        The problem statement says that we always need to make the next string lexicographically minimal.

        From $$$\tt{pbdtm}$$$ we could go to $$$\tt{pbdt}$$$, $$$\tt{pbdm}$$$, $$$\tt{pbtm}$$$, $$$\tt{pdtm}$$$ or $$$\tt{bdtm}$$$. The lexicographically smallest one of these is $$$\tt{bdtm}$$$.

        We cannot go to $$$\tt{pbdm}$$$, since $$$\tt{bdtm}$$$ is lexicographically smaller.

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

Great idea for E, thanks a lot for the wonderful contest :)

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

You can also solve problem B by binary search. By the way, problem c editorial is great,thanks:).

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

    I tried to solve it using binary search 247760061, but getting a TLE though. can someone please help me figure out why?

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

      Change while to for(int i=1;i<=200;i++) and set high to 1e9 and you'll pass this question!

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

        Thanks. It worked 248056414.

        So, was that because there will be so many real values between the extremes?

        And we are can get to an approximate value in < 200 iterations?

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

          I think it's possible that the way your code is written could have some precision issues causing it to get stuck in a dead loop. In fact, we would halve the search each time, and even 100 searches would be enough to achieve the precision needed for the question.

          (I'm sorry my English is not good, the above is the result of using a translator, I hope you can read it:)

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

Nice editorial

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

Awesome Editorial and Problem set.

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

Can someone help me with understanding my solution to B more clearly? I tried using binary search by answer here. I felt it was a plausible solution since if a radius (say r) is an answer then all radiis > r are also the answer. I tried implementing some solution, didnt work, maybe my impl on binary searching for real answers suck. Help/Correction appreciated!

// checks if point is inside circle
bool check(pair<float, float> circle, pair<float, float> point, float w){
    return ((circle.first - point.first) * (circle.first - point.first) + 
    (circle.second - point.second) * (circle.second - point.second)) <= w * w;
}

//checks if circles A and B are touching
bool istouch(pair<double, double> a, pair<double, double> b, double w){
    return w + w >= ((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}


//checks if the radius is a valid answer
bool isok(pair<float, float> b, pair<float, float> p, pair<float, float> o, pair<float, float> a, float w){
    return (check(b,o,w) & check(b,p,w) | (check(a,o,w) & check(a,p,w))) | 
    (check(b,p,w) | check(a,p,w)) & (check(b,o,w) | check(a,o,w) & istouch(a,b,w));
}

double WORST = 3e3f;
double EPS = 1e-6f;

void solve(){
    pair<float, float> p, a, b, o;
    cin >> p.first >> p.second;
    cin >> a.first >> a.second;
    cin >> b.first >> b.second;

    o = make_pair(0.0f, 0.0f);

    double l = 0.0f, r = WORST;
    double w = r;

    //binary searching the answer starts from here
    while(r - l > EPS){
        double mid = (l + r)/2;
        if(isok(b,p,o,a,w)){
            w = mid;
            r = mid;
        } else {
            l = mid;
        }
        // cout << l << " " << r << "\n";
    }

    cout << w << "\n";

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

    In theory binary search should be possible here, even if I don't think it makes the problem easier to solve than the direct solution.

    Problem 1: istouch() is wrong. You need to square the distance at the left-hand side (as you do in check()), or take the square root of the righthand side (hypot() is useful here).

    Problem 2: isok() is wrong. You need to check four possible paths: O->A->P, O->B->P, O->A->B->P, and O->B->A->P. The first two subexpressions (check(a,o,w) & check(a,p,w) and check(b,o,w) & check(b,p,w)) cover the first two possibilities. The third expression doesn't really work. instead of check(b,p,w) | check(a,p,w)) & (check(b,o,w) | check(a,o,w) & istouch(a,b,w) you need something like (check(b,p,w) | check(a,p,w)) & (check(b,o,w) | check(a,o,w)) & istouch(a,b,w) (note the different places of the parentheses!)

    (Also, generally don't use & and | for Boolean logic. Use the proper Boolean operators && and || instead. But that's not causing any bugs in this case.)

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

For problem E, I was able to squeeze in what I think is an $$$O(m \times 2^m \times \sqrt{n})$$$ solution that doesn't precompute the number of programmers needed to satisfy a project: 227729256

Not sure if this was intended to pass or not!

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

For Problem F, the editorial states that when "when you move a camera of type 2 to the first block, it can force multiple cameras of type 3 into the second block". I'm unable to see why this is true.

It seems to me that from the way we pick the camera of type 3, after a single move, it will fix all the $$$x$$$ which have $$$d_x - x > 0$$$. Because after moving the camera of type 2 from block2 to block1, we might cause several indices to have $$$d_x - x = 1$$$ (and not any value higher than $$$1$$$), which can be fixed by a single camera move.

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

    Good question, it was one of our main points of concern while designing the solution (we weren't sure if it is necessarily to change the positions of multiple cameras of type $$$3$$$). This is because, when you move a camera of type $$$2$$$, it increases $$$d_x$$$ by $$$1$$$ on some suffix of values. But when you "move" a camera of type $$$3$$$, it actually stays in the first block (we still have to hack it before stealing the first diamond). It just has a bigger range of possible positions. So, it decreases $$$d_x$$$ on some suffix, but increases $$$d_x$$$ back on some shorter suffix (i. e. it just decreases $$$d_x$$$ by $$$1$$$ on one subsegment, not on the whole suffix). If there are multiple points where $$$d_x - x$$$ became positive after we moved a camera of type $$$2$$$, some of them might be outside that affected segment.

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

In F why "if we skipped some camera which could be inserted into the first block, and chose some other camera for the same slot, they can be "swapped". " is right?

I think if we first insert the camera which $$$s_i$$$ is small and then insert the camera which $$$s_i$$$ is big,for the second block it is greater,but for the first block it is not greater than we first insert the bigger one.

BledDest

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

    Suppose we already placed cameras of type $$$1$$$ and $$$2$$$, and try to place cameras of type $$$3$$$. Why is it always optimal to do it in non-descending order of $$$s_i$$$, and place a camera only in the first block (instead of placing it in both) whenever possible?

    Suppose we fixed an optimal placement of cameras, and it differs from the one produced by that greedy algorithm. Let's fix the first (in sorted order) camera $$$i$$$ that would be placed in the first block by the greedy algorithm, but is not placed there by the optimal solution.

    There should be a moment of time (some $$$x$$$ seconds before stealing the first diamond) where we would place that camera $$$i$$$ in the first block in the greedy solution. So, the condition $$$s_i \ge x + len$$$ must hold. If there's no camera of type $$$3$$$ occupying that moment, then we just place that camera $$$i$$$ there and remove it from the second block.

    If there is such a camera, suppose its index is $$$j$$$. We can show that if we place the camera $$$j$$$ in both blocks, and the camera $$$i$$$ in the first block only, nothing will break: we can place the $$$j$$$-th camera in both moments of time occupied by the $$$i$$$-th camera, and the $$$i$$$-th camera in the slot of the $$$j$$$-th camera:

    • since $$$s_j \ge s_i$$$, the position for the $$$i$$$-th camera in the first block is suitable for the $$$j$$$-th camera;
    • since $$$s_j \ge s_i$$$, the position for the $$$i$$$-th camera in the second block is suitable for the $$$j$$$-th camera;
    • $$$s_i \ge s_j$$$ does not necessarily hold, so it might be possible that the slot occupied by the $$$j$$$-th camera is unsuitable for the $$$i$$$-th camera. But remember that the greedy algorithm would place the $$$i$$$-th camera in the time slot occupied by the $$$j$$$-th camera, so the condition $$$s_i \ge len + x$$$ holds. So, that slot is suitable for the $$$i$$$-th camera.

    By repeating this process enough times, we can transform the optimal solution to the solution produced by the greedy approach, and nothing breaks.

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

Can anyone help me to find why is it wrong in th case 16 of the problem E: https://mirror.codeforces.com/contest/1886/submission/228496275

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

    Obviously, the programmers that you finally choose are the biggest ones, so you should sort them decreasingly instead of increasingly before DP. Otherwise it means that you assumed choosing the smallest one, making it not optimal sometimes.

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

    e.g.

    2 1

    1 3

    3

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

Hi, can anyone explain for D, (TestCase 1, before all queries.)why the permutation 2, 1, 3, 5, 4, 6 is not possible ?

Maybe I am missing something, but the sequence is <?>?>

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

for question C you should put a hint (use a stack) as only knowing this information made me solve it

overall, good question and perfect tutorial thanks

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

In problem $$$C$$$, I was wondering what if we had some $$$Q$$$ queries, where each query is asking the character at queried position and length of string as ($$$N < 10^6$$$).

Any ideas on how we will go about it, like what information do we need to store ?
Or should the constraints be reduced ?
Like any approach for this so called Bonus problem ?

Roms

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

why solution problem C has s+="$". help me

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

Another approach for problem A which is more concise 248334395