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

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

1598A - Компьютерная игра

Идея: BledDest

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

1598B - Деление на группы

Идея: fcspartakm

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

1598C - Удаление двух элементов

Идея: fcspartakm

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

1598D - Тренировка

Идея: BledDest

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

1598E - Лестницы

Идея: BledDest

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

1598F - ПСП

Идея: BledDest

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

1598G - Сумма хороших чисел

Идея: BledDest

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

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

The easiest solution for C(in my opinion): 131432277

P.S. sum * (n-2) = (sum — a[i] — a[j]) * n => we can find for every a[i] all a[j] in O(n log n) using binary search

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

sorry i forgot that x is a good number :-_

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

IDk why but my solution for C gives TLE on Test 17 even though it's the exact same solution as the tester's : https://mirror.codeforces.com/contest/1598/submission/131542518

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

Why using unordered_map gives TLE in this question... searching elements using hash map should be faster than the map which takes log(n) time to search instead.
131514464

Also I don't get it... how by adding just these 2 lines which where on a blog,
mp.reserve(1024);
mp.max_load_factor(0.25);
solves the problem of TLE and my soln gets accepted.
131524838

Then I tried a custom hash function rather than the built-in hash function. Which also got accepted. Also the same solution gets accepted in python using dictionaries which also uses hashmap.
Does this mean that the C++ built-in hash function is not good ?
131520347

I tried to find but didn't get some concrete answers when to use map or unordered_map ?
Or using custom hash is better not ?
Please if anyone can help it in.

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

Nice solution for D!

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

I suppose that the time complexity of F should be $$$O(n2^n + A\log A)$$$ instead of $$$O(2^n + A\log A)$$$. (:

Could someone tell me if there are some mistakes?

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

Any other solution for problem D?

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

In Problem D, I don't understand why the only bad triples are (xa,ya),(xb,ya),(xa,by). Isn't there a possibility of having three same topics, such (1, 1), (1, 2), (1, 3)? I've been looking at the explanation for so long but still can't figure it out :(

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

For D, can someone explain to me why there can't be a triple of the form [(Xa, Ya) , (Xb , Yb) , (Xa, Yb)] ? EDIT: I figured it out, it's actually the same thing except that the third pair is the central one, instead of the first.

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

For 1598C:

No, you don't have to use map in such a hacky way (or in another word, full of patches).

131572801

======================================

Instead of keeping a map of all elements, we keep a map for number of first i items ([0, i-1])

So the core logic can be much more easier:

in C#:

for (int i = 0; i < n; i++){
    // update the answer
    if (cnt.ContainsKey(target - data[i])) answer += cnt[target - data[i]];
    // update the cnt map, for (i + 1) to use.
    if (!cnt.ContainsKey(data[i])) cnt.Add(data[i], 0);
    cnt[data[i]]++;
}

or in C++:

for (int i = 0; i < n; i++){
    // update the answer
    answer += cnt[target - data[i]];
    // update the cnt map, for (i + 1) to use.
    cnt[data[i]]++;
}
»
5 лет назад, скрыть # |
Rev. 12  
Проголосовать: нравится 0 Проголосовать: не нравится

i tried to add photo for my comment but the comment become empty any one can help me

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

In problem D can anyone please explain why we won't be overcounting in the editorial solution?

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

Alternative solution for 1598D - Training Session. I did see restriction that all problems pairs of parameters are different, but I had no idea how to use this fact. My solution doesn't rely on this fact at all. Solution turned out to be much harder so I wasted a lot of time to implement it during round.

Here is main idea. Think of how to calculate all triples with different topics.

There is easy way

Apply the same idea to problem's difficulties. We count something twice. What to do?

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

Detailed description how to implement 1598E - Staircases in $$$O((n + m + q) \log (n+m))$$$ time and space.

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

for que B https://mirror.codeforces.com/contest/1598/submission/131729850 can u check this once i don't which test i am missing so pls

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

A slightly different solution of 1598F - RBS.

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

in problem C why i am getting tle.. Pls tell[problem:1598C] https://mirror.codeforces.com/contest/1598/submission/131512968

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

    This is due to the use of unordered_map instead of map. Try map and you will get AC.

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

      even , i used unordered map earlier it also gave me tle but when i am using map it is not giving tle . can anyone explain why is it so ? please.

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

        I think it may be because of special anti-hash testcases.

        Unordered map relies on hashing to determine where the value of a key is stored. When there are hash collisions, the the hash function makes the collided keys share the same position. This is done with a linked list, which needs to be linearly searched if you are looking for a key that has collided with other keys.

        Essentially, you can design testcases that abuse this workaround, causing unordered_map access complexity to approach O(n)

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

132438878 can anybody help me with this I'm getting tle even though the time complexity of my son is same as that of the solution :)

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

My solution for F fails at test 32. Can someone please look at the submission and point out the error?

I would be happy to explain what my code does if it is not clear. Thanks.

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

A Dp approach to problem E in $$$O(NM + Q*min(N,M))$$$

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

For problem D, is there anyway to find the number of triples that are different both in topic and in difficulty?

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

Problem A can be solved using DFS like this: 161393885.

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

hey I have a doubt in ques C sorry if its too silly.. should not the ans+=min(freq of a[j] , freq of (2*sum/n a[j]). ie minimum of the counts should be added right? because if needed sum is 10 and freq of 7 is 4 and freq of 3 is 2 then pair with sum 10 should be only 2 right?