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

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

Спасибо за участие!

1492A - Три пловца придумал meshanya, а подготовил ch_egor

1492B - Колода карт придумал Noam527, а подготовили ch_egor, adedalic

1492C - Максимальная ширина придумал и подготовил Jatana

1492D - Ход гения придумал voidmax, а подготовил rip

1492E - Почти отказоустойчивая база данных придумал wrg0ababd, а подготовил Sehnsucht

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Codeforces Round 704 (Div. 2)
  • Проголосовать: нравится
  • +221
  • Проголосовать: не нравится

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

Why was B unusually hard for me?

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

What a fst round :(

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

Test case 73!

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

Video editorial for problem C: https://youtu.be/7uXOxPAej7Y

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

fstforces

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

Why downvoting? The problems were great and the editorial is clear. It just has weak pretest. Even so why not to downvote the announcement instead of editorial?

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

I know pretests of problem D were weak but otherwise it was a good contest. I don't think it's right to downvote it's editorial.

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

ch_egor, can you translate the name of the problem E to English in the bottom of the editorial? It is in Russian now.

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

FSTforces。:(

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

My answer to A is $$$\min(a-p\bmod a,b-p\bmod b,c-p\bmod c)$$$. Maybe the idea is easier?
UPD: You need to check that if $$$p\bmod a=0$$$ or $$$p\bmod b=0$$$ or $$$p\bmod c=0$$$.

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

Why for 0 1 0 in problem D answer will be No while 1,1 satisfy the given condition

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

Thanks for fast editorial and good problems.

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

my easy answer E

randomly select elements from arrays and test it is real.×100times

https://codeforces.me/contest/1492/submission/108293277

UDT this is very easy to hack, i tried some another way to pass, but maybe random can't

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

You wrote special case a = 0 for problem D in editorial but no pretests for this? Seems someone likes to see fst

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

CDE are nice, B is kinda "guess-by-sample" problem, and A just boring.

Great contest overall

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

The system tests of problem E are weak too. Some random solution like https://codeforces.ml/contest/1492/submission/108282677 can be hacked by this test case:

62500 4

1 1 1 1

1 1 1 1

1 1 1 1

...

2 2 2 2

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

Problems were really interesting and looks like pretest were really strong as many solution got failed during system testing. Superfast editorial as well .....

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

Although I didn't count how many people failed to pass the system test on some problem, I found that my rank changed from 1238 to 764.

This round was really Fst forces!

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

only if a+b-2==k testcases were included in pretests for D :()

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

Everyone's commenting "Fstforces". What does it mean?

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

Can anybody explains to me how B can be implemented in O(N)?

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

This gives me RE on pretest 5

RE

whereas this gets AC on pretest

AC

I have changed only this much part of the code and nothing else. Someone please help me out in debugging the error.

UPD: I got the mistake I was doing. Thank you all.

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

Solve D in ten minute, WA after two hours.

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

in C

what if we just find the right dp array and iterate over s from left to right and keep updating our answer for each s[i], like:

ans=max(ans,max_possible_right_for[i+1]-current_t_i);

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

Editorial of E seems incomplete :(

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

[Deleted]

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

My performances during the contest

Quite awful. I opened the problem pages, after a couple of minutes, I finally see the statment of A, I think I spent little time solving it, but I forgot to save the code after I have a few changes, and I submit the code without realizing it. So I got a wrong attempt.

The following story is boring, until I try to solve D, at first I think there is only one way to make the answer have digit 1 :1000-0001=0111. Obviously some cases were left behind, so I got WA on pretest #8. I suddenly find the problem, and I deside to recode — that is, to delate the original one and to solve the problem again from zero.

That is proved to be a bad idea, for the method when I recoded havn't been design carefully. So I finally WA in main test #64, and I didn't get in the first 1000.

But if I didn't recoded and chose to mend the code I write first, everything may be changed.

So I got a lesson after the contest: Think twice, code once.

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

Lots of contestants passed E with a random algorithm like 108293277. There is a hack test:

50000 5
1 1 1 2 2
1 1 2 2 1
1 2 1 1 2
1 2 1 2 1
1 2 2 1 1
2 1 1 1 2
2 1 1 2 1
2 1 2 1 1
2 2 1 1 1
rand() rand() 1 1 1
rand() rand() 1 1 1
...

The answer is 1 1 1 1 1 but if you randomly choose the answer from every sequence, the accuracy is $$$O(\frac{1}{n^2})$$$.

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

Really thank you for the GREAT pretests with Problem D.

Please make pretests STRONG next time.

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

FST Round The pretests of D are too weak :(

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

Let s be codeforcescontest704d and t be fst, the maximum width of p is 7 XD

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

    UPD: To be frank, I really wonder why you guys tend to downvote me:(


    How did my comment become a downvote attractor? :( The meaning I wanted to explain was similar to the one the guy upstairs(Chinese:楼上, which means the previous comment or its poster, translated literally) referred to. :( One of my classmates used his three accounts or so to downvote me, and now there're so many:(

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

Learning from Problem A especially for JAVA users :

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

    actually this problem is also in C++ . I submitted by using ceil function and converting denominator to floating point by multiplying with 1.0 but it gave WA mostly due to precision issue.

    we can do $$$(num+den-1)/den$$$ for ceil.

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

    Why is this getting downvotes?
    I have faced some problems, so I write it so that many users can correct the same mistake.

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

      Because of two reasons:

      1) In every single contest that requires ceil, there is a ton of comments describing exactly what you just did, it is clear that most people don't really enjoy repetition in comments thus they downvote.

      2) The algorithm you provide to get ceil is not really 'optimal', to be more precise most people use (A+B-1)/B (as the guy above me said) because it requires only one line of code and even is a bit faster because it doesn't use multiplication.

      To sum up, you did not do anything wrong by describing your issues, but people get tired of reading this exact comment every time there is a task that requires a ceil operation.

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

i think my solution to the Problem A was correct,but my submission to it didn't pass the test cases. Could you pls hava look over over it and correct me if i am wrong and where did i go wrong???? https://codeforces.me/contest/1492/submission/108247518

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

How can I optimize my B solution? My solution
Any help would be appreciated.

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

For problem A, this was my following code:

from math import ceil
for _ in range(int(input())):

    p,a,b,c = map(int,input().split())
    print(min(ceil(p/a)*a,ceil(p/b)*b,ceil(p/c)*c)-p)

It is giving me WA on pretest 2. What am I missing?

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

Alternative solution for 1492E - Almost Fault-Tolerant Database is following: find any two vertices of diameter, then try all 2^(diffs) variants. Is it wrong? Can someone prove it or hack it? 108299916

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

tests are wonderful!!!!

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

Can somebody please tell why my solution for C failed .. - I have calculated max, min possible indexes for each t[i] keeping my mind p1<p2<p3 .. - where max of every index is smaller than max of i+1 - and min of i is greater than min of i-1. - and calculating the ans as the max of (max[i+1]-min[i]) for valid indexes. - and if we get answer from certain i, we can use max of each indexes >i+1 so that given condition is verified. Here is my submission: https://codeforces.me/contest/1492/submission/108280740

upd: got AC now :)

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

    I have a doubt, if p1<p2<p3... then why isn't the min of i greater than max of i-1.Because if min of i is smaller than max of i-1 then there will be some values of pi which will be smaller than p(i-1).

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

      Yes but i was ONLY looking for answer using min of i and max of i+1(so that I get maximum absolute diff).. so if a pair of(i,i+1) gives me the max width,then all the other indices less than i can be set to their minimums ( which will be less than min of i used ) and all indices greater than i+1 can be set to their maximums similarly

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

When Problem D is doable in O(n), why restrict the limits to $$$2\times 10^5$$$? The editorial doesn't even mention DP or any alternative solution that only works below $$$2\times 10^5$$$.

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

Я отправлял такое же решение в A, но оно не проходило 2 претест. Что я делал не так?

import math
 
for i in range(int(input())):
	p, a, b, c = map(int, input().split())
	a = math.ceil(p / a) * a
	b = math.ceil(p / b) * b
	c = math.ceil(p / c) * c
	
	print(min(a - p, b - p, c  - p))
  • »
    »
    6 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    При делении постоянная ловля на ошибки представления чисел с плавающей точкой (хотя в большей степени это встречается в educational раундах). В данном случае лучше использовать целочисленное деление, а не math.ceil()

    t = int(input())
    for _t in range(t):
        p, a, b, c = map(int, input().split())
        m1 = ((p - 1) // a + 1) * a - p
        m2 = ((p - 1) // b + 1) * b - p
        m3 = ((p - 1) // c + 1) * c - p
        print(min(m1, m2, m3))
    

    Еще часто ловят на ошибки при взятии логарифма, извлечении корня итп — здесь всегда нужно считать от обратных операций.

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

Codeforces Round #704 (X)

Hackforces & FSTforces Round #704 (O)

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

why am I getting runtime error in this soln

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

E is such a nice problem.

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

Good questions and fast editorial.

Personally, leaving some unexpected spaces for hacks is ok.

But it seems like this contest is another lesson for the authors that it's important to keep an eye on the chances for using randoming algorithms (or other tricks like brute force + #pragma)to pass the tests...

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

How to solve problem E's bonus 2? I can only come up with $$$O(nm+k^kn)$$$.

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

Simple solution for D:

Make x as a zeroes and b ones

Make r as k ones and max(a-k, 0) zeroes

Then if x-r >=0 and x-r contains a zeroes and b ones we found answer, otherwise no solution

108313076

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

Bonus1 seems to be the same as the original task.

In Bonus2, intuitively split nm into 2 cases , where n <= 500 or m <= 500 , to reach the sqrt time complexity.... But have no idea how to keep on :(

Hope to get some hints.

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

Doubt in problem E editorial :

We can ignore each other array that differ with the first array in no more than 2 positions

Take following input : n=3 m=3 , 1 2 3 , 4 5 6 , 3 3 7

We can see that 3 5 3 will work .

Now if input was : n=4 m=3 , 1 2 3 , 4 5 6 , 3 3 7 , 1 3 7

Then according to editorial 3 5 3 should work as answer because we ignore the 4th array . But then 3 5 3 differs from fourth array at 3 positions.

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

    Then according to editorial 3 5 3 should work as answer because we ignore the 4th array . But then 3 5 3 differs from fourth array at 3 positions.

    "Ignoring" an array doesn't mean that we immediately throw away it from input.

    The solution is to try to consider the first array as an answer, therefore we can skip ("ignore") other arrays which doesn't differ in more than 2 positions.

    If it doesn't work, then we change the first array and check again. In particular, after changing, "ignored" arrays may be differing in more than 2 positions (and therefore stop being "ignored").

    So, although you ignored the 4th array when considering "1 2 3" as a possible answer, you can't ignore the 4th array when considering "3 5 3" as a possible answer.

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

can anybody tell me why am i getting WA after using same logic for question : https://codeforces.me/contest/1492/problem/C my solution : https://codeforces.me/contest/1492/submission/108314097

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

test case 64!

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

Why are some editorials in english and some in russian?

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

some people have used randomized solution for problem E . Could someone please explain how to solve problem E using that.

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

Can someone explain how to approach the problem B if we have random numbers in the array. If we have test cases of random numbers like [9,10,1] then the greedy logic fails

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

Thanks in Advance.

I cannot understand why my submission for C got the wrong answer on Pretest 5.Can anyone please provide me a simple test case (for which my program will fail) so that I can understand my error.

Here is my submission : C.Maximum Width

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

Hi, for problem E, can anyone explain a little bit what does the variable cnt mean in the dfs() function of this submission?

https://codeforces.me/contest/1492/submission/108321457

Thanks for help.

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

In the editorial of problem C, I think the answer should be $$$\max_{i=1}^{i=m-1}\textit{right}_{i+1}-\textit{left}_{i}$$$ ($$$n$$$ is replaced by $$$m$$$.)

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

Problem C, 108446832 is getting WA on test 7. Can anyone provide a testcase?

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

Hello, can someone please explain how the solution to E is not 6^2 * (n*m) ^ 2? The way I understand it is like this: We go trough the list o(n * m), for every single guy, if he has more than 2 differences we go into the maximum of 6 ways of completing him (so times 6). For every one of those n * m * 6, we go trough the list a maximum of one more time, to look for another array that has a difference of more than 2 with our current solution array. So n*m*6*n*m. o((n * m) ^ 2 * 6) so far. Now once we find one we have a maximum of 6 ways to change our solution array so o((n * m) ^ 2 * 6 ^ 2) is our final complexity. Where am I misunderstanding?

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

    I implemented the solution in editorial in following way (I will the prove it's complexity) :

    We can notice that we can make atmost two changes to the first array so that it becomes original array and all array differ from it in atmost $$$2$$$ positions.

    Now we compare first array to all other arrays and we find another array such that it differs in more than $$$2$$$ positions then we must modify atleast one position in first array . Number of ways we can modify one position in first array is $$$4$$$ in worst case because as editorial says , the case with more than $$$4$$$ difference will not have answer.

    After the modification in first array , we again compare it with all other arrays and if we find some array differing in more than $$$2$$$ positions we must again modify it in one position. We will consider all possibility and maximum possibilities here will be also $$$4$$$.

    Thus it's like calling compare function recursively after modification , also in particular recursive function , we won't compare further once we found array with difference greater than $$$2$$$.

    Number of times we will call this recursive function is atmost $$$3$$$ because we can make atmost $$$2$$$ changes.

    So suppose in first function call in worst case we found the last array which differs in greater than $$$2$$$ position then number of operations in first function call would be $$$O(n*m)$$$.

    Number of operations related to second function call will be $$$O(4*n*m)$$$ because previous function will call this function atmost $$$4$$$ times.

    Number of operations related to third function call will be $$$O(4*(4*n*m))$$$ because number of times previous function will call this function will $$$16$$$.

    Thus total operations will be $$$O(21*n*m)$$$. The key point which saves time complexity from being $$$O((n*m)^2)$$$ is that in particular instance of function call , we don't compare with further arrays once we find the array which differs in greater than $$$2$$$ positions with first array.

    submission related to above reasoning.

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

Мне понравилось, топчик.

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

I am unable to find out what wrong am I doing here: https://codeforces.me/contest/1492/submission/108491871

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

Can someone explain the recursive backtracking solution for Problem E?

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

Can somebody help me why I am getting Time Limit Exceeded Error https://codeforces.me/contest/1492/submission/108665110

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

Can somebody point out the mistake in my solution to the problem C? Here's my solution: https://pastebin.com/yE5tDG5s

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

Why am I getting WA on test 5 — 141222690 :(

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

even full test cases of D are extremely weak for example this sub-optimal solution almost passed in fact it failed in the very last test 93rd test is the final one which I saw in my AC solution ,also there can be numerous counter easily makable tests