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

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

<almost-copy-pasted-part>

Привет! В 28.06.2020 17:35 (Московское время) начнётся Codeforces Round 653 (Div. 3) — очередной Codeforces раунд для третьего дивизиона. В этом раунде будет 6 или 7 задач (или 8), которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов. Я постарался сделать приличные тесты — так же как и вы буду расстроен, если у многих попадают решения после окончания контеста.

Вам будет предложено 6 или 7 (или 8) задач и 2 часа на их решение.

Штраф за неверную попытку в этом раунде (и последующих Div. 3 раундах) будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в двух рейтинговых раундах (и решить в каждом из них хотя бы одну задачу),
  • не иметь в рейтинге точку 1900 или выше.

Независимо от того являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.

Спасибо MikeMirzayanov за платформы, помощь с идеями для задач и координацию моей работы. Спасибо моим очень хорошим друзьям Дарье nooinenoojno Степановой, Михаилу awoo Пикляеву, Максиму Neon Мещерякову и Ивану BledDest Андросову за помощь в подготовке и тестирование раунда. Также спасибо Артему Rox Плоткину и Дмитрию _overrated_ Умнову за обсуждение идей и тестирование раунда!

Удачи!

</almost-copy-pasted-part>

UPD: Также спасибо lov.ish за тестирование раунда и отдельное спасибо Дмитрию _overrated_ Умнову, Артему Rox Плоткину и, конечно же, Михаилу MikeMirzayanov Мирзаянову за обсуждение идей и помощь с подготовкой раунда!

UPD2: Разбор опубликован!

  • Проголосовать: нравится
  • +450
  • Проголосовать: не нравится

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

vovuh orz!

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

This is missing from the announcement after everyone thought our man vovuh retired...

You know I'm back like I never left (I never left)

Another sprint, another step (another step)

Another day, another breath (another breath)

Been chasing dreams, but I never slept (I never slept)

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

This has been happening in the last couple of months :)

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -7 Проголосовать: не нравится
At last vovuh come back in div-3 with his interesting problem-set. We missed him 2 continuous div-3 contest.
#650(He was not there) And #644(Just in the tester list).

Edit: Ok. Only vovuh fans missed him And I am one of them.

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

div3 by vovuh are best

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

Deleted

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

I am not able to register for the contest. When I click on the CONTESTS options above, I am able to see only ICPC challenge 2020 registration option.

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

I don't see any difference between vovuh problems/non-vovuh problems.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится
  • No One:
  • Literally No One:
  • Not Even A Single Soul:
  • Not even Codeforces:
  • vovuh fans: "Vovuh orz!!!!!!!!!! vovuh is back baby!!!! Missed you Vovuh ❤❤"
»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +9 Проголосовать: не нравится

.

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

Vovuh orz!!!!!!!!!! vovuh is back baby!!!! Missed you Vovuh ❤❤

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

Starting RN I'm gonna explain my family members to keep quiet during 8:00 — 10:00 Tomorrow ! Maybe they'll understand this time

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

vovuh : "The man the myth the legend !"

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

Div-3 and vovuh perfect combination.

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

Finally vovuh is back :)

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

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

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

This comment has been deleted due to negative feedback!

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

I don't know about this man vovuh but going through these comments makes me feel there's a good contest ahead ! Wishing it's true ... All the best to all participants

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

meanwhile vovuh counting all the money he made setting div 3 contests!

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

MikeMirzayanov No more Div.4 rounds?

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

i love doing contest set by vovuh, thanks and keep giving us more contest

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

I can nearly always solve div2 C but I can't solve div3 D should div3 D be harder than div2 C ?

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

Does Div-4 contests are discontinued?

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

Cringe overloaded

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

meme

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

pls can someone tell me what happens in hacks ?

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

I know here is not a good place to ask this question but what happened for div4 contests ??

are they removed from codeforces contests or we can see them back soon ??

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

It is high time to introduce filters to comments section on codeforces -_-.

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

Harder than usual div 3 :)

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

The gap between E1 and E2??

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

Help me with D after the contest...

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

    D problem was giving TLE when i used unordered_map and when i changed it to map it got accepted. You just have to calculate the minimum number which we have to add to the numbers of the array after which they are divisible by k.

    This can be calculated by taking mod.

    for example the numbers are 5,1,3,4 and value of k = 3

    so for the first element we need to add 1 to get the divisible number

    this number can be calculated by taking mod of a[i]-k & k.

    -> (k + (a[i]-k)%k)%k;

    now similarly for other numbers also we'll calculate in the same way so -> 1,2,0,2 is the required array.

    Now Notice that at a time we can select only one element from the above calculated array. It means that when we see 2 or more elements of same type we can't give the same x to them.

    It means we have to calculate the next greater number which must be added so that the given number is divisible by k.

    the next number can be calculated by multiplying k with the number of times this number has previously occurred, which means we have to maintain the hash table for it.

    Your code here...
            long long int n,k;cin>>n>>k;
            long long int a[n],maxm=-1;
            for(int i=0;i<n;i=i+1) scanf("%lld",&a[i]);
            
            map<long long int,long long int>mp;
            vector<long long int>rem;
            
            for(int i=0;i<n;i=i+1)
            {
               long long int val = mod(k-a[i],k);  // taking mod and storing it.
                if(val)rem.push_back(val);
            }
            for(int i=0;i<rem.size();i=i+1)
            {
    
                long long int val = k*mp[rem[i]] + rem[i];
                mp[rem[i]]++;
                maxm = max(val,maxm);
                
            }
            maxm++;
            printf("%lld\n",maxm);
    
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    My approach:

    for all the array elements calculate the value required to make it a number divisible by k and store it in map and keep incrementing its value if it repeats.Then, find the max "value" in the key-value pair and ans= key+(value-1)*k+1. If two keys have the max value, take the max key.

    eg: second example, 5 repeats 3 times. so ans= 5+(3-1)*6+1=18.

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

      Can you explain why this works ?

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

        To make a such that a%k==0 you have to increase a by k-(a%k). Now if there is another element with the value of a , minimum increment to make a%k==0 is k-(a%k). But according to statement we can not choose multiple indices to increment by same x. So the next minimum value is k-(a%k)+k. If there is another element with the value of a then we have to increment it by k-(a%k)+k+k. So generally,

        required minimum increment for a value 'a' = k-(a%k) + (frequency of a - 1)*k

        Maximum of these value for each distinct element is the optimal answer. (As values of other element are less than the answer we can increment them accordingly on the way to the answer )

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

          I think your this approach might not work.

          Consider the case 2 6 3 9 for 3 the minimum required increment = 3 for 9 the minimum required increment = 3

          And max of (3, 3) will give 3.

          But the answer here would be 9

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

            Yes. I'm sorry i forgot to mention a really important thing. when calculating the frequency of each element we must take the mod of them. Because as in your case the increment needed for both 3 and 9 is 3. As we are focusing mainly on the x (increment) 3 and 9 is same for us. (3%6 = 9%6 = 3).

            Then the answer would be,

            6 - 3 + (2 - 1) * 6 = 9

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

    https://mirror.codeforces.com/contest/1374/submission/85372487

    Isn't this linear ... why it's giving TLE?

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

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

Now I see why vovuh rounds are so amazing. Thoroughly enjoyed the round!

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

Easy solution to E2: Copy a solution to this problem https://mirror.codeforces.com/contest/799/problem/E which is the exact same except you don't have to reconstruct the indices. Then add boring code to reconstruct the indices

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

https://ideone.com/oNqhoj

My code is obviously wrong (fails sample test case 2 lol).. But I spent more then an hour can't find where my logic is wrong :/.. I'm almost convinced my 24 IS the correct answer haha..

Any help is appreciated. (Would be awesome if you don't spoil the problem but hint me where I went wrong)

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

Hints for F?

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

    Just simulate. If it does not end in correct ordering, then do one triple swap including two same elements from a[]. The simulate again. If still not correct ordering it is impossible.

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

      Thanks for the solution! I thought of this solution, but I am still figuring how to prove that it will be impossible, in case both simulations fail.

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

        Seems that it does not work good :/

        Here is the submission of #1 85347474 He does count invariants, and if odd parity, does one swap in two same elements.

        Then sorts with triple swaps, but including the indices in comparison, which does not change the order of elements, but makes the parity even.

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

        The idea behind proving whether it is possible/impossible is based on the following idea:

        Define f(P) for some permutation P to be the number of pairs of indices (i, j) such that i and j are the 'wrong way round' — that is, i < j but in the permutation p, j is to the left of i.

        For example if n = 4 and P = {1, 2, 3, 4} then f(P) = 0. f({2, 1, 3, 4}) = 1 and f({4, 3, 2, 1}) = 6 (everything is the wrong way round).

        We claim that each cyclic shift is invariant mod 2 for f(P) — that is, f(P) will change by -2, 0 or 2 with each shift. This is because if [a, b, c] --> [c, a, b] then the pairs (a, c) and (b, c) have reversed (now a, b are to the right of c when before they were to the left). So since there are two changes, then f(P) goes up by 2, stays constant or down by 2.

        This also explains why we need to do two simulations — if two elements in the original array are the same, then we label them (x, x') in one simulation and (x', x) in the other simulation. Then for the starting configuration, f(P) will be odd for one of them and even for the other, and at least one of them should work.

        From this we can conclude that it's impossible if both below conditions are met:

        • there are no duplicate elements (otherwise by the above, at least one of the x, x' or x', x should work)
        • the original permutation has f(P) odd (then it can never reach 0 since it's always odd)
»
6 лет назад, скрыть # |
 
Проголосовать: нравится -6 Проголосовать: не нравится

Really enjoyed this round. hail vovuh

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

What's the limit for compilation time? I submitted my code for E2 nearly the end of contest and got this verdict. "Can't compile file: Compilation process timed out." I guessed the reason is that my code is too long, but I don't think I can make it significantly shorter. Do you know how to make it compile?

85381670

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

Can someone tell me where my code is wrong for E1? https://mirror.codeforces.com/contest/1374/submission/85384974

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

Please a fast editorial , i need to upsolve

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

What is the test 4 of problem E like ?

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

What is the test 4 of problem E like ?

I tried to use priority_queue a(only a like), b(only b like), c(both a and b like)

Then with ca(number of chosen a), cb(number of chose b)

  • If (ca < k), I will take min if exist (a.top() and c.top())

  • If (cb < k), I will take min if exist (b.top() and c.top())

  • If (c.top()) is selected I will increase both (ca) and (cb) else I only increase 1 (a.top() -> ca and b.top() -> cb)

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

E2 would have been better easier if it didn't have to traceback indexes.

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

What a huge implemention on E1.

Three pointers and so many if-else, I am about to not to solve it. Luckily, before the end of the contest I finally solved it by huge implemention :), hope not to be FST.

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

How to Solve F ?

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

Why am I getting TLE on test case 8? 85389867

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

D: Could someone please tell why this is giving TLE?

http://mirror.codeforces.com/contest/1374/submission/85383846

inline bool c(ll a, ll b) { return (a >= b); }

int main() { ll t; scanf("%lld", &t); while(t--) { ll n, k; scanf("%lld %lld", &n, &k);

ll p = 0;
unordered_map<ll, ll> mxx;
for(ll i = 0; i < n; i++)
{
  ll x;
  scanf("%lld", &x);

  x = x % k;
  if(x == 0)
    continue;

  x = k - x;
  mxx[x]++;
}

for(auto i: mxx)
{
  ll v = i.first + k * (i.second - 1) + 1;
  p = max(p, v);
}

printf("%lld\n", p);

} }

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

I see C easier than A ;) :v

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

https://mirror.codeforces.com/contest/1374/submission/85372487

I think this solution is linear. Anyone explain the reason for TLE?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
For D ,Even O(n*t) solution is resulting in TLE , Is there still any scope left for improvement in my code .

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

What's wrong with this code. (Problem D) It gives MLE at test case 5. Thanks in advance.

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

How to solve D if the first operation can be performed any number of times on each $$$i$$$.

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

    You mean [k = 3, a = {2, 2, 2, 2}]?

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

      I mean let's say $$$k$$$ = 4 and $$$a$$$ = $$$[1,4,8]$$$. In original problem answer would be 4 because we can perform operation $$$a_i = a_i + x$$$ on a particular $$$i$$$ at most once. How to solve it if we can perform it any number of times. Like in this case answer would be 3 as we can perform $$$a_1 = a_1 + 1$$$ and $$$a_1 = a_1 + 2$$$.

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

    If x is answer to the current question, then an O(x).k solution can be easily found for the modified question. We maintain a frequency array of size k, to store the remainders and another frequency array of size k to store currently available remainders . While processing x, we can check if it can make a remainder which is needed, and we can modify accordingly.

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

    I initially didn't read that line and was getting hopeless. I mean there won't be any fast algorithm, I have a felling that there won't be any polynomial time algorithm

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

My A, B, C, D, E1 solution`s
A: 85388328
B: 85388390
C: 85388427
D: 85388457
E1:85388485
If you have questions regarding the logic of the solution or the principle of the code — write here

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

Tutorial of problem C: First, solve this, then assume your output is $$$ans$$$. Now, back to C, and print $$$(n-ans)/2$$$ for each testcase. I wish I've made a clear solution and stay tuned for my YouTube channel :'D

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

Can someone help me in finding bug in my E2(Hard Version) solution?
Here is my solution 85387601
It is failing in 12th test case. Thanks in advance.

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

Can anyone please tell me what's wrong with my solution in E2??

giving RE on test case 5.

https://mirror.codeforces.com/submissions/Lord_Saga

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -62 Проголосовать: не нравится
Question D should be rejudged , as it has extreme time limits , there are people who used map , passed their tasks , while i got TLE using unordered_map , which is faster .

In O(n*t) time limit , even the time complexity to take input is O(n*t) , there is no way my solution should fail . Definitely , There is a big scandal behind all this . We want Enquiry.

Hope , Mike sir will look into this matter .

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

what a bad day for me, my rating continously decreasing from past 4-5 contest and my current rating is just 1615 and this contest is unrated for me in which my rank would be in top 10. hope this would never happened to anyone

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

is vovuh from BTS?

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

I'm going to assume that my solution for problem E2 using treap is not the intended one, because that would be very weird for a div3 contest. But I usually try to kill a mosquito with a bazooka during contests, so I'm sure that there is a simpler and nicer way to solve the problem :P

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

    Can you please explain your treap solution?

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

      Fix the amount of books of type 1-1 that you will take. You can calculate how many books of type 1-0 and 0-1 you will need to force that both people have at least k books. Obviously, you will take the ones that have lower cost for each group of books. This works for E1.

      Now for E2, you should keep the same strategy, but maybe you have to use a few more books to complete the M books you need to take. But both people already have at least K books, so you can take any other book you want (even if it is a 0-0 book). Obviously, you will take the smallest amount of books you need (let's say X). Here is where treap comes up to help us: you can use it to calculate the sum of the first X smallest values in the remaining books that you didn't take before.

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

Can someone explain how to solve E2? I saw some people using treap to solve the problem.

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

    I think the main part of this problem is how to find k-smallest elements sum. Usually you can do this by binary search tree, so treap can do the job. The easiest way to implement for me is to use segment tree that each node store pair of (number of element, sub of element) in subtree. To get sum of k-smallest elements. Check if left node size greater than k or not. If yes, try searching on left subtree, otherwise subtract sum of left subtree and search on right subtree. Fenwick tree can also do the job if you keep two fenwick trees that one store sum and one store number of elements and use binary lifting or binary search to find sum of k-smallest elements.

    I saw many people solve using priority_queue or multiset, but I don't know how it works though.

    Edit: I think I get it now. It’s similar to finding median by priority_queue or multiset. Notice that k is always increasing. So you can simply do the same thing. When you encounter query, just transfer elements between 2 multiset respected to value of k. The total number of operations will still be $$$O(n)$$$

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

Thanks for this contest! Through this contest, I realized that my implementation skill is very very weaker than others In F, I observed the main idea very quickly, but that is all.. I failed to write accurate code...

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

https://mirror.codeforces.com/contest/1374/submission/85392451 its showing TLE for using map also. pls someone find the fault.

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

Can anyone tell me why I am getting this runtime error in TC 5 for E1 ?
Link for submission — https://mirror.codeforces.com/contest/1374/submission/85375093
I am pretty sure this has to do something with my comparator function for sort but I cannot figure it out.

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

Can someone help me with D? I am not able to understand what's wrong with my code. Main logic below

lli == long long int

        lli mx = 0, mxval = 0;
        map<lli,lli> mp;
        while(n--)
        {
            lli x;
            cin>>x;
            if(x % k == 0) continue;
            lli diff = (k - x%k)%k;
            mp[diff]++;
            if(mp[diff] >= mx)
            {
                mx = mp[diff];
                if(diff >= mxval)
                    mxval = diff;
            }
        }
        if(mx == 0 and mxval == 0) cout<<0<<endl;
        else cout<<(mx-1)*k + mxval+1<<endl;
»
6 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится +4 Проголосовать: не нравится

Here is my screencast of this contest, do check out it :)

Link: https://youtu.be/afn_V7YkX3U

On my channel I do educational content, so if you want to improve, make sure to subscribe to the channel!

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

Can Anybody explain me C please

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

    Keep a counter, initialised to zero. Traverse through the string now, whenever you encounter ( counter++, otherwise counter--

    Now if the counter becomes negative at any moment l, it means that you have a extra closing bracket, in this situation move it to the end of the string. This approach will ensure that every opening bracket is matched to some closing bracket. And also set the counter to 0.

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

    Suppose you have variable $$$bal$$$ which stands for balance. We go through string from left to right, if we have $$$"("$$$ now then do $$$bal+=1$$$ and $$$bal-=1$$$ if we have $$$")"$$$. The answer is the global minimum value of $$$bal$$$. For example $$$s=)))((((())$$$, then balance will be $$$-1, -2, -3, -2, -1, 0, 1, 2, 1, 0$$$. The most minimal value of $$$bal$$$ was -3, thus the answer is 3. So you can fix the sequence by 3 moves. You can take 3 rightmost opening brackets and move them to the front of the string. So string $$$)))((((())$$$ will become $$$((()))(())$$$.

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

How to solve problem D ?

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

Kindly explain the statement of problem E1.

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

using min_heap (priority_queue) for D seemed more intuitive to me.

Submission

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

can anyone plz try to hack my first E1 submission i think it is wrong!!
upd-: never mind that solution is correct

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

My weird solution for problem B! 85335681
How fool and stupid I'm!

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

My Video solution for the contest

A,B,C The video is time stamped for your convenience (check the description).

D
E

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

As usual, video solutions to all problems are available at the end of my screencast of the round.

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

Can anyone give a proof for the solution to F?

What i used -> sort the first n — 2 part and then if the remaining 2 elements are not sorted then sort them using some element which has a duplicate. Im unable to prove why it works.

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

have the people got the rating for this round anyone please help me

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

In E2, I made 4 arrays, 1st is "common books", second is "books interesting Alice only", third is "books interesting Bob only" and fourth is "books both are not interested in". Then I sorted them and took corresponding books from second and third array and added them to form pairs of books that interest either one of them. After both have read 'k' books of their interest, I am checking if a total of 'm' books have been read.

Let 'num' be the books read till now.

My code is failing on test 12, and with furthur debugging, I found that this case is where num<=m. So now I am taking all the remaining books(common,interest for alice only,interest for bob only and books none of them are interested in) and sorting them by time. after this I am taking the first (m-num) books to get the final ans.

Link to the code

Please can someone help me in debugging. Thanks

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

Why map can ac

unordered_map time out problem D:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
int main() {
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    ll a, b, c;
    while(t--) {
        cin >> a >> b;
	// time out
        // unordered_map<ll, ll> mp;
        // ac
        map<ll, ll> mp;
        ll tmpa = 0, tmpb;
        for(ll i = 1; i <= a; i++) {
            cin >> c;
            ll tmp = b &mdash; c % b;
            if(tmp == b) {
                tmp = 0;
                continue;
            }
            mp[tmp]++;
            if(mp[tmp] > tmpa) {
                tmpa = mp[tmp];
                tmpb = tmp;
            } else if(mp[tmp] == tmpa && tmp > tmpb) {
                tmpb = tmp;
            }
        }
        if(mp.size() ==0) cout << 0 << endl;
        else cout << (tmpa &mdash; 1) * b + tmpb + 1 << endl;
    }
 
 
    return 0;
}
»
6 лет назад, скрыть # |
 
Проголосовать: нравится -6 Проголосовать: не нравится

Hello, I am stuck at this solution as to why it is giving MLE on TC 5. I am just storing the remainders in a map. Please can anyone help?


ll == long long; loop == for int n,k,p=0;cin>>n>>k; map<int, int> mp; bool y=false; loop(i,0,n){ int h;cin>>h; h %= k; if(h!=0){p++;y=true;} mp[(k-h)%k]++; } ll ans=0,x=0, cnt=0; if(!y){ cout<<0<<endl;return; } y=false; while(cnt<p){ ll j = x%k; if(mp[j]>0){ mp[j]--; if(j!=0)cnt++; } ans++; if(cnt>=p)break; x++; } cout<<ans<<endl;

I can see that it should give TLE but why MLE?? Submission[submission:85385727]

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

    I didn't look carefully, but if you write mp[j] and j is not a key in the map, then j will be added to the map as a key with value 0. If you don't want to add a key you can write if(mp.count(j)) instead of if(mp[j] > 0).

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

.

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

For E1, why am I getting WA on Test case 5? 85405609

My approach was that I iterated on the number of books which they should read, such that both of them liked that book. For the rest of the books, I chose greedily.

UPD: Got it fixed :)

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

I have been hacked on problem A. Here is the submission. https://mirror.codeforces.com/contest/1374/submission/85298617

This is the first time I have been hacked. It says I got TLE. But my program is O(1). So I am certain that it is right. Can someone please tell me 1) If my program is wrong. 2) If the hack was judged successful incorrectly.

Please help me. This was my best performance. I will drop 3000 ranks due to this incorrect (in my opinion) hack.

Edit: My solution is definitely right. I had to switch from input() to sys.stdin.readline() for it to not be on the brim of TLE.

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

    Note that your solution is fairly slow, the test shows Time: 982 ms

    So I assume the hack also used 50000 testcases, but with bigger input numbers. Which is enough to put it over 1000ms.

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

    Your solution is logically correct but not fast enough. Python is a slower language and your solution only just passed the pretests taking 982 out of 1000 ms.

    There are things you can do to speed it up without switching from python:

    -150ms by removing the unused imports at the top.

    -200ms by buffering the output instead of printing every line (eg 85407621 takes 592ms).

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

      By the way, do you know any way to disable flush on a new line inside print/stdout in python? Couldn't find any From what I see the line on a terminal is always flushed when there is "\n".

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

        To clarify. In Python, printing does not flush stdout. It is the call to input that flushes stdout. The implementation of input is that it first flushes and then calls sys.stdin.readline. So to not flush, simply use something like input = sys.stdin.readline. (tested on CPython3, PyPy2 and PyPy3) .

        Here is a code if you want to play around with what flushes stdout.

        Detect flushing

        Btw, just so you know, the built in IO especially in PyPy is pretty slow. During the competition I used sys.stdin.readline and it ran in 654 ms85296367. Most of the time is spent on IO. Doing IO smarter makes it go down to 140 ms 85416929.

        A while back I made a drop in FastIO for PyPy2 and PyPy3 that fixes these issues of slow built in IO (found https://github.com/cheran-senthil/PyRival). With it, my code runs in 155 ms 85417276. anoubhav's code runs in 202 ms 85417590.

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

After giving 15 contests I can say that Yes, Ashish Gupta's round has fastest editorial . Who else agree with me?

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

Is there any other way to do E1 instead of priority_queues and a lot of if-elses?

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

Video Editorial for E1 Video Link

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

In question D, I used unordered_map, why it is giving TLE and Now I just changed unordered_map to map and my solution is accepted. Can anybody clarify this?

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	int T;	cin >> T;
	while(T--) {
		ll n, k;	cin >> n >> k;
		bool allbyk = true;
		ll ans = 1;
		unordered_map<ll, ll> r;
		for (int i = 0; i < n; ++i) {
			ll a;	cin >> a;
			ll rem = a % k;				
			if (rem) {
				allbyk = false;
				r[k - rem]++;
				ans = max(ans, (r[k-rem]*k - rem));
			}
		}
		if (allbyk)
			cout << 0 << '\n';
		else
			cout << ans+1 << '\n';
	}
	return 0;
}

This is my code for reference.

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

Check out the editorials guys:

Problem E1

Problem D

Problem C

Problem A and B

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

where is the editorial??

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

When will the ratings be updated?

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

Hello This is my first contest on codeforces. Please tell me how to find editorial of the contest?

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

Can anyone care to explain who is vovuh?

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

Why hasn't the editorial been provided yet? It has been a while since system testing has been completed.

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

Can anyone help me with this, in E1 my solution with long long fails with runtime error, but the exact same code gets accepted with int.

Submission with int — 85434593

Submission with long long — 85434729

Diagnostics says overflow with long long. How is that possible though?

In the image

Red: Runtime error
Green: Accepted

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

Is my solution for B entirely correct. Submission

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

    It is okay, but a better way of thinking is: prime factorize $$$n$$$, if $$$n$$$ has a prime factor other than $$$2$$$ and $$$3$$$, answer is $$$-1$$$, otherwise, let $$$n = 2^a * 3^b$$$. If $$$a \leq b$$$, then just multiply $$$2$$$, $$$(b - a)$$$ times, then divide by $$$6, b$$$ times. So, answer is $$$2*b - a$$$.

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

there is a message is sent to me about someone else's code is matching with mine, but I can't understand this. And what to do now? I Don't understand how to do now

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

how can in div3 a person get rating even though he was expert (his rating was >= 1600) before the contest?
look at rating of user: beethoven97
MikeMirzayanov please look at this

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

Python WINS at something at last! It has a superior default hash function (the address of the object in the behind-the-scenes C implementation, which is pretty much random).

ENJOY all your TLEs for once CPP users, MUHAHAHA (•̀ᴗ•́ )

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

Still waiting for official Editorials. Problem setters should make editorials along with problems.

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

Why was my rating changed after round? I've thought that bug with registration when you cyan was fixed...

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

Where I can get the tutorial for E2 and F

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

Why is E1 missing the tag 'three pointers'. my submission:85436260

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

Something strange happened with me in this contest... For problem E1, my submission got runtime error on case 35. while it worked fine on my compiler and on ideone.com as well. i tried submitting in C++ 14,11 as well, but result was still same.

when i submitted in C++ 17 64 bit , it got accepted without any changes in code. It would be great if someone could explain this.

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

Can anyone help me with this? The submission 85319608 doesn't get a TLE while 85452045 does. They look exactly the same. I tried hacking the first one using what is now test 3 but was unsuccessful while the same test worked against many other codes with the same asymptotic running time.

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

i did E2 but my implementation is quite messy i have seen solutions of many red coders but i donno why their solution is even messier, can anyone plz explain the logic of solution using BIT or seg tree!!

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

Codeforces Round #653 (Div. 3) D. Zero Remainder Array

In this Problem , if we consider a input — 1 2 5 4 4

then as per the solution provided,the output is 7 but if we conside like —

1 .when x = 1 , we will server one of the 4 (4+1=5 and 5%5=0) then x will become 2 2. when x = 2 , we will add it to the remaining 4 and it will become 6 and x will become 3 3. At this step , x is incremented and becomes 4 4. Now if we add 4 to the 6 , it will become 10 and 10%5==0 and then x becomes 5

So the answer should be 5 . .
Is it ? ? ?

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

    You added $$$2$$$ to the remaining $$$4$$$, which makes it $$$6$$$, and then added $$$4$$$ to it, which is not allowed. You can choose any index at most once. Also, the $$$1$$$ remains in your array.