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

Автор vovuh, история, 7 лет назад, перевод, По-русски

1256A - Оплата без сдачи

Идея: MikeMirzayanov

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

1256B - Минимизация перестановки

Идея: vovuh

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

1256C - Прыжки по платформам

Идея: MikeMirzayanov

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

1256D - Минимизация бинарной строки

Идея: MikeMirzayanov

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

1256E - Очередное разделение на команды

Идея: MikeMirzayanov

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

1256F - Приравнивание двух строк

Идея: vovuh

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

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

For Problem C,I imimplemented in O(n). 64249894

Main idea is like the tutorial:First place the platform as rightmost as we can ,if the rest positions can't place later platforms,we need move current platform to left.Maybe I am lucky enough to pass all tests.

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

Very Greedy Contest.

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

C in O(n). It's just placing the platforms leftmost you can at first. Got hacked for a simple mistake unfortunately. here 64283716

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

My solution for C is very simple $$$O(n)$$$ 64233289 Idea is following:

  • Set positions of all platforms with space in between exactly $$$d-1$$$. Just don't care about width of river.

  • Now, if beginning of next "virtual" platform is $$$n+1$$$ or greater, then answer is YES otherwise is NO.

  • Last step, we need to pack all platforms back into river. It's very easy to do. Let $$$n+1$$$ to be beginning of "virtual" platform, now iterate over all platforms from the last to the first, and if the platform overlap "virtual" platform, them align end of the platform to beginning of virtual platform. Now, set virtual platform to be this aligned (or not) platform and continue.

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

I think there is missing part of editorial for F.

Regarding case when all characters in both strings are distinct. Suppose that there is way to make them equal. It means, that if you apply all operations for first string instead of doing them simultaneously, and then apply all operations on the first string that was supposed for the second string in reverse order, you should get second string. In other words, steps to make the second string from the first string is: operations of first string in normal order plus operations on second string in reverse order. But count operations of same length is even, because each simultaneous operation produce two operation of same length. Thus, you need to change parity even times, which means no parity change is possible.

What I don't understand though, is how you can prove that you always can do that when parity is same. All I did is prove that you can't make it if parity is different.

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

In problem E, Why the maximum size of a team is 5??

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

it's hard to see when you have 11 correct hacks ( for the first time ) but still no hacking leaderboard vovuh

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

from the solution of[problem:1256D] problem D can anyone explain what we do if s[i]=='0' but k<cnt?

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

Задача C довольно легко решается за линейное время - 643166051.

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

For question A, why do we need to do S % n? I mean what would we get by doing this? I know it would be quite basic but still, I didn't get it. Thanks in advance

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

I can't understand Then let's sort the second string also by swapping adjacent characters but choose the pair of adjacent equal characters in the first string (it always exists because the first string is already sorted). for problem F.

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

You can solve E with segment tree & DP,but just DP solution is way more easier.

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

I think Problem B can be solved in $$$O(n)$$$, it's too late at night to code it though

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

    Here's my code for $$$O(n)$$$: 64340316

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

Here is O(n) solution for problem C: 64232235

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

$$$O(n)$$$ solution for C: I didn't put the board greedily. I tried to break the gaps between the boards evenly.

My Submission: 64221433

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

In problem F, How does one get an idea to consider the parity of inversions ? I mean it is not at all obvious to me . If this is a popular idea , can someone give some problems related to it ?

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

In problem E , how would we approach if we have to minimise the number of teams as well?

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

    You would combine all consecutive teams into one team where it does not make a difference in the diversity. ie the ones where the score of the highest member of the team is one less than the score of the lowest member of the next team.

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

Вопрос по задаче Минимизация перестановки. Для исходной последовательности 1 4 5 2 3 за 4 операции можно перейти к 1 2 3 4 5. Почему это неправильный ответ? (Тест #2)

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

    Из условия: "i-я операция позволяет вам поменять местами элементы заданной перестановки на позициях i и i+1. Каждая операция может быть применена не больше одного раза." То есть, если ты поменял один раз элементы на позициях і, і+1, больше на этих же позициях менять элементы нельзя. Максимум для этого теста — 1 2 4 3 5, независимо от количества операций что у тебя остались.

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

In problem E. help help me... My code is a little different from the offcial solution, but I think they are roughyly the same. However, it is TLE. Here is the central part of my code.

for(int i = 2; i < min(5, n); i++) { dp[i].first = wd[i].first — wd[0].first; dp[i].second = i + 1; }

int len = 0;int temp = 0;
for (int i = 5; i < n; i++)
{
    if(dp[i - 3].first + wd[i].first - wd[i - 2].first < dp[i - 4].first + wd[i].first - wd[i - 3].first) 
    {   len = 3;    temp = dp[i - 3].first + wd[i].first - wd[i - 2].first;}

    else
    {   len = 4;    temp = dp[i - 4].first + wd[i].first - wd[i - 3].first;}

    if(temp > dp[i - 5].first + wd[i].first - wd[i - 4].first)
    {   len = 5;    temp = dp[i - 5].first + wd[i].first - wd[i - 4].first;}
    dp[i].first = temp;
    dp[i].second = len;
}
»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I got a detailed prove for F. Regarding case where the characters of both string are distinct. let's consider the pair in string a, a(i) > a(j) and i<j, and there are t characters between them, so it's easy to know that we need 2*t+1 times swap to get a(i) and a(j) swap while keeping others unchanged(t+1 for a(i) to reach j, t times for a(j) to reach i), so the cost is always odd. if we have parity of the number of inversions odd in both string, then we can say both need odd times to get the string sorted, and the difference between two times if even, also we can always do even times adjacent swap and keep string unchanged, finally two strings become the same. and so the even situation.

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

for the problem B the first testcase is $$$[5 4 1 3 2]$$$

My approach is:

$$$[5, 4, 1, 3, 2]$$$
$$$[5, 1, 4, 3, 2]$$$
$$$[1, 5, 4, 3, 2]$$$
$$$[1, 5, 3, 4, 2]$$$
$$$[1, 3, 5, 4, 2]$$$

and the answer is [1, 5, 2, 4, 3], but clearly my answer is lexicograhically smaller, so anyone can tell me where is the problem?

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

    It is mentioned that for a particular index i you can swap only once. For i=2 you can swap (4,1) after that you cannot swap number at position i=2. i.e.(5,3)

    Second paragraph of question: " You can perform at most n−1 operations with the given permutation (it is possible that you don't perform any operations at all). The i-th operation allows you to swap elements of the given permutation on positions i and i+1. Each operation can be performed at most once. The operations can be performed in arbitrary order. "

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

a more general solution for E:

  1. sort by skill
  2. let dp[i] = minimum diversity that we can do starting at index i
  3. then dp[i] = min(dp[k+1] + a[k] − a[i]) for all k, such that i + 2 <= k <= n − 4
  4. since a[i] is independent of k, dp[i] = − a[i] + min(dp[k+1] + a[k]) for all k, such that i + 2 <= k <= n − 4

if we want to implement this it would take o(n^2), but we can notice something by looking at dp[i + 1]

dp[i+1] = − a[i + 1] + min(dp[k + 1] + a[k]) for all k such that i + 3 <= k <= n − 4

thus dp[i] = − a[i] + min(a[i + 1] + dp[i + 1], a[i + 2] + dp[i + 3])

the idea is that dp[i+1] would already have the minimum for all k >= i + 3, so we only need to test for k = i + 2 and then compare it with dp[i +1] + a[i + 1]

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

Can someone explain why my solution failed on test case 2? https://mirror.codeforces.com/contest/1256/submission/65338281

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

In problem B why i can't start by swapping 1 to arrive to the beginning of array then swap 2 to the nearest index can be reached then 3 and so on... Why i have to move the largest element to the end of array starting with (n-1)th (move if i can) and finish with 1st element.

What is the difference between tow processes.

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

How is my naive dp solution of time complexity O(nmd) (approx 10^9 operations) passing all test cases of problem C ? 70828229

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

Can anyone tell me how is problem B different from problem D? I mean, aren't just we minimizing the given sequence in both of the problems?

For problem B, all I did was to first loop through the array from right to left (from n-2 to 0) swapping all elements where, a[i] > a[i+1], and then, once again from left to right (from 0 to n-2), doing the same operation, but making sure that the "i" was not repeated when going through the loop the second time, this can be done by maintaining a map.

However, this approach for problem D turned out to be wrong when I ran it on my local machine, is it because of the restriction of "k" ?

Sorry for my bad English.

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

Problem C is can be done in O(n) and without needing terrible implementation, here is my submission 83591516 , just think about gaps, there are n-(summation of all plank lengths) gaps, and places=m+1 positions to fill them ( each side of a plank), now lets say we are going to place k=gaps/places zeroes contigously, we need to take care of rem gaps%places as well...

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

in editorial it says dp for E is so standard tho i can't understand it :||

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

is there a binary solution for problem E?