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

Автор fcspartakm, история, 7 лет назад, По-русски
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Codeforces Round 451 (Div. 2)
  • Проголосовать: нравится
  • +51
  • Проголосовать: не нравится

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

Is there any solution for F without using hashing/probabilistic approaches?

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

    Big integer types

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

    Well, you can get 100% right answer by brute-force checking after the hashes match, and that allows the hash to be wrong a few times, because then you still won't get a TL... ofc that still uses probabilities ;(

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

      Yeah, that's indeed the actual (and almost never used) Rabin-Karp algorithm. First time that I used it (with the O(n) check each time hash collisions occurred).

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

    We can delete some variants (if len1==len2 and len3=len1+1, then 1st digit in third number is to be 1, if len1==len2==len3 then first digit in first number + first digit in second nubmer is to be not bigger than first digit in third number and so on (look at my code to find more dependencies)). Then we should check the other situations. Just iterate in our strings (like long arithmetic) and try to get third number. If we can do it, just print the answer. I'm not sure, if this approach is good, but it can pass all the tests. Also I can't prove it, but it so obviously that too many combinations (len1, len2, len3) is not considered in this solution. This is my solution and sorry for my bad English.

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

How many people used 'exgcd' in 898B ? ...

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

For problem E. My code gives correct input on my system but wrong on codeforces. for 1st test case on my system it gives 2 as output. On server it's giving 0. http://mirror.codeforces.com/contest/898/submission/33309260

edit: It gives 2 on codechef as well.

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

    you have declared "s" twice , and there can be more bugs in your code. on my machine it gives 0 as output

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

      I understand that's a wrong practice but shouldn't change the output as the one inside main must be considered.

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

An alternative solution for E: let f(x) be the minimum number of operations needed to make x a square number, and let g(x) be the minimum number of operations needed to make x a non-square number. We can sort the input array a using the following comparator: a[i] <= a[j] if and only if f(a[i])-g(a[i]) <= f(a[j])-g(a[j]). Then, in the optimal solution, the first n/2 smallest numbers in the resulting order will be transformed to square numbers while the remaining n/2 largest numbers will be transformed into non-square numbers, so the result is (sum i=1 to n/2: f(a[i])) + (sum i=n/2+1 to n: g(a[i])) for the sorted (using mentioned above comparator) array a .

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

    My solution here[submission:33309059] uses a greedy, sort for min distance to square, then claculate the first half as squares and the other as non-square sort for min distance for non-square and sum like before but in reversed order

    the solution is the minimun of the two previous

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

Why E is so easy? :D

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

problem C. why is my output wrong for the first test case http://mirror.codeforces.com/contest/898/submission/33310053

my output :

2

ivan 100123

masha 100123

jury output:

2

masha 100123

ivan 100123

In the question it is mentioned that we can output in any arbitary order.

update: found the mistake .My code was printing an extra space in first line of the output .But i have a doubt like the judging code should have ignored such things ??

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

Can someone elaborate the solution of F? I am not very comfortable with hashing plus the language of the author is a bit rusty(sry).

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

Solution of D without set : Sliding window question :) Using Hashing :)

http://mirror.codeforces.com/contest/898/submission/33305287

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

33320897 I have used a list of a structure node to do the C-Phone Numbers problem. It is a clumsy method but I believe it will work for some test cases. It is running perfectly in my system but giving runtime error Exit code is -1073741819 in codeforces' ide. Could anyone help me out here?

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

    Do not erase from the set inside the loop in case iterator pointing to undefined value after the change.

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

Why in problem E we need a long long?

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

Come on guys.. Problem E was actually the easiest one.. I know I should have read all the problems first but... E is just.. straight up bad(no offense).. it isn't suited to be an E question and this caused a lot of rating spikes...

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

I am not aware about the concept of hashing. I can not understand the solution to the problem F.

The editorial says, "At first we should calculate "hash" by big prime module from the given string, and the base must be equal to 10 because we work with numbers. We can use prime module about 1015, if we will use multiple of long longs by module with help of long doubles."

I don't understand this.

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

How to proof solution of problem D? Why just turn off current alarm is right?

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

    Let's process from left to right. If we come to an alarm that would give us k alarms in the interval (i — m, i], then we must turn it off or there will be too many alarms in the interval. The only other option is to turn off alarms preemptively, that is, before we're forced to. But it is optimal to turn off alarms as late in the day as possible, because these will affect the most intervals in the future.

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

Can anyone please explain the solution idea for problem F and it's complexity. I have read the editorial several times, but can't understand it properly. Thanks in advance.

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

Can someone explain me_ 898F — Restoring the Expression_ .Could not understand a word in editorial.thanks in advance

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

Hello . My submission for 898F gives error on Test Case 19.

http://mirror.codeforces.com/contest/898/submission/33383748

I'm using the Hash Function, where I'm using 2 prime numbers as given in the array prim[], and I'm using base 10. What is the possible problem in my code. Please help.

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

Can someone please explain problem F ?

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

In F problem what are we trying to hash in the editorial?

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

I have solved problem 898F-Restoring the Expression just now and I want to share my idea for this problem with the community.

The key idea or observation for this problem is —

Let a+b=c. and length of a,b,c is x,y,z respectively. Then z-max(x,y) will always either 0 or 1. It means the maximum number between a and b must have length z or z-1 otherwise we can't obtain c by adding a and b.

After this observation now you can check for every possible length of c from 1 to n (where n is the length of the given input string) and from the length of c now you can calculate length of b and c and check whether the a+b=c property is present for the current substrings of the given string. Hashing is the only way to do this check in O(1) complexity. Overall complexity of this solution id O(n).

Here is my submission 33521860

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

Problem F I understand that the only way to compare it, it's using hashing. In fact, in the virtual contest, I thought about it. But the problem I've encountered was how to decided the size of the prime number. I thought about some very small prime numbers, see that it didn't work, and stop thinking about it. Is there any further explanation about hashing that could help me solve problems like this in the future? Maybe something with more theory, that helps me prove what I'm doing is right. Thanks in advance.

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

Please add this editorial to contest dashboard.