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

Автор natalina, 3 года назад, По-русски

1846A - Рудольф и перерезание верёвки

Автор: Sasha0738

Подсказка 1
Подсказка 2
Разбор
Решение
Оценка задачи

1846B - Рудольф и крестики-нолики-плюсики

Автор: Sasha0738

Подсказка 1
Разбор
Решение
Оценка задачи

1846C - Рудольф и очередное соревнование

Автор: vladmart

Подсказка 1
Подсказка 2
Разбор
Решение
Оценка задачи

1846D - Рудольф и елочка

Автор: vladmart

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Решение
Оценка задачи

1846E1 - Рудольф и снежинки (простая версия)

Автор: natalina

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Решение
Оценка задачи

1846E2 - Рудольф и снежинки (сложная версия)

Автор: natalina

Подсказка 1
Подсказка 2
Подсказка 3
Подсказка 4
Разбор
Решение
Оценка задачи

1846F - Рудольф и мимик

Автор: Sasha0738

Подсказка 1
Подсказка 2
Разбор
Решение
Оценка задачи

1846G - Рудольф и CodeVid-23

Автор: vladmart

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Решение
Оценка задачи
Разбор задач Codeforces Round 883 (Div. 3)
  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится

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

Автокомментарий: текст был обновлен пользователем natalina (предыдущая версия, новая версия, сравнить).

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

HacksForces

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

For E2 there is a simpler solution to check if there exists a $$$k$$$ such that $$$1 + k + k ^2 = n$$$.

You can rearrange the equation to $$$k(k + 1) = n - 1$$$. It follows that the only $$$k$$$'s you need to check are $$$\lfloor \sqrt{n - 1}\rfloor$$$ and $$$\lfloor \sqrt{n - 1}\rfloor - 1$$$. This is a modified version of the official solution : code

EDIT : as davi-v pointed out,there is no need to check for $$$\lfloor \sqrt{n - 1}\rfloor - 1$$$.

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

    Great!

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

    can you explain why are checking the equation for k=2 and why we only floor(sqrt(n — 1)) and floor(sqrt(n — 1)) — 1 ?

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

      Sure! I assume you meant $$$exponent = 2$$$,not $$$k = 2$$$. If you deal with all $$$k$$$ $$$ \lt =$$$ $$$10 ^ {6}$$$ (for example by precalculating a set of valid numbers),for all other $$$k$$$ $$$ \gt $$$ $$$10 ^ {6}$$$ the exponent must be exactly $$$2$$$. That is because the minimmum exponent is $$$2$$$ and if the exponent was $$$3$$$ the sum would be larger than $$$10 ^{18}$$$.Now we have to check that there exists a $$$k$$$ such that $$$1 + k + k ^2 = n$$$. This is the same as checking if there is a $$$k$$$ such that $$$k(k + 1) = n - 1$$$. Now, let $$$r = \sqrt{n - 1}$$$. It is easy to see that $$$k \lt r$$$. However, $$$k$$$ must be as large as possible so $$$k$$$ is either $$$\lfloor r \rfloor$$$ or $$$\lfloor r \rfloor - 1$$$ when $$$n - 1$$$ is a perfect square.

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

    Very inefficient approach. It can be done with binary search sir !!!

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

    can u explain "if (p > (long long)(1e18) / k) break;" Why this statement is necessary?

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

    You don't need to check $$$\lfloor{\sqrt{n-1}}\rfloor - 1$$$. Let $$$m = n - 1$$$. For $$$k(k+1)=k^2+k$$$ to be $$$m$$$, $$$k \lt \sqrt{m}$$$. Let $$$x = \lfloor\sqrt{m}\rfloor$$$. The question is: which numbers of the form $$$k=x-c$$$, $$$c \ge 0$$$ do we need to check?

    Substituting in $$$k(k+1)$$$, we get $$$(x-c)(x-c+1)=x^2+x(-2c+1)+c^2-c$$$. Note that $$$x(-2c+1)+c^2-c$$$ must be $$$\ge 0$$$, as $$$x^2 \le m$$$. We need to show that if $$$c \gt 0$$$, $$$x(-2c+1)+c^2-c \lt 0$$$, so $$$x^2+x(-2c+1)+c^2-c$$$ can't equal $$$m$$$.

    Note $$$c \le x$$$, otherwise $$$k$$$ would be negative. Let $$$x = c + d, d \ge 0$$$. Substituting, we get

    $$$ x(-2c+1)+c^2-c = (c+d)(-2c+1)+c^2-c\\ =-2c^2+c-2cd+d+c^2-c=-c^2-2cd+d. $$$

    If $$$c \gt 0$$$, $$$-c^2-2cd+d=-c^2+d(-2c+1) \lt 0$$$, as $$$-c^2 \lt 0$$$ and $$$-2c+1 \le 0$$$.

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

      You are correct! Thank you for pointing out my mistake, I will make sure to correct it shortly. Also, I found a simpler proof to prove we don't need to check $$$ \lfloor \sqrt{n - 1}\rfloor$$$ :

      I claim that for any number $$$a = k ^ {2},k\in\mathbb{N},\nexists b \in \mathbb{N}$$$ such that $$$b \cdot (b + 1) = a$$$. When $$$b = k,b \cdot(b + 1) \gt a$$$ and when $$$b \lt = k - 1,b \cdot(b + 1) \lt a$$$. Because $$$b \cdot(b + 1)$$$ is either $$$ \gt $$$ or $$$ \lt $$$ than $$$a$$$,we can conclude that $$$b \cdot(b + 1) \neq a$$$.

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

    yeah properties of triangular numbers, same technique used in proving cantor pairing (2d lattice hash)

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

E2 is a superb binary search question, liked it

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

Hi, can anyone help me debug my submission for E2? Don't know why I am getting WA.Thanks in advance.212818653

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

    I tried the similar approach in python (no overflow) and got WA on tc 16 after increasing the max value upto 1e25... (was AC initially and finally got hacked :(( )

    Further increment gave TLE... maybe the constraints weren't designed for the binary search solution... (unless I'm wrong, in which case I would appreciate if someone pls provided me with an AC solution)

    P.S: My initial approach in C++ was returning LLONG_MAX in the binpow function whenever overflow occured (used a check_overflow() function...) which gave WA on tc 5... Idk why...

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

why is the D in editorial AC without setprecision? what differs from my submission . ik i messed up the setprecision in my code but still why

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

At the time of contest 1846C is accepted so I have done 4th but next day it is showing wrong on test case 10. it's your fault not mine.

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

For E2, there is a much simpler code arising from the result of an inequality.

We can just iterate through the values of p. For each p, we need to check for only a single value of k which is floor(n^(1/j)). This is the only possible value of k that may satisfy the condition for a given value of p. This is because:

k^p < 1+k+(k^2)+....+(k^p) < (1+k)^p implies k < (1+k+(k^2)+....+(k^p))^(1/p) < 1+k

If n is equal to 1+k+(k^2)+....+(k^p), then k should be less than n^(1/p) and as per the above inequality k should be floor(n^(1/p)).

Here's the code.

#include <bits/stdc++.h>
using namespace std;

long long int sumpow(long long int x, int y) {
    long long int p=1;
    for(int i=1;i<=y;i++) {
        p=1+x*p;
    }
    return p;
}

int main() {
    int t;
    cin>>t;
    for(int i=1;i<=t;i++) {
        long long int n;
        cin>>n;
        int decider=0;
        for(long double j=2;j<(log(n)/log(2));j++) {
            long long int c=powl(n,1/j);
            if(sumpow(c,j)==n) {
                decider=1;
                cout<<"YES"<<endl;
                break;
            }
        }
        if(decider==0) {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

So we can take one medicine multiple times in G?

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

    It doesn't matter if it's allowed or not since it would never actually be useful to take the same medicine multiple times anyway.

    I claim that if there is a sequecne of medicine that removes all symptoms and medicine $$$x$$$ is used multiple times, we can keep the last occurrence of $$$x$$$ and remove all earlier ones, and the sequence stays valid.

    Proof: Consider the symptoms medicine $$$x$$$ cures. It doesn't matter if these symptoms are cured or not before the last occurrence of $$$x$$$ since the last time of taking medicine $$$x$$$ cures these symptoms anyway. Thus, taking medicine $$$x$$$ also earlier has no effect.

    Now consider the symptoms medicine $$$x$$$ gives. It doesn't matter if these symptoms are cured or not before the last occurrence of $$$x$$$ since taking this medicine will give these symptoms anyways, and they need to be cured later. Thus, taking medicine $$$x$$$ also earlier has no effect.

    This means that taking medicine $$$x$$$ also earlier than the last occurrence has no effect on any symptoms. $$$\square$$$

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

Задачи интересные, только не понимаю почему людям так не нравится бэшка...

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

this round has really weak testcases. It's not only for B and C, but also for G. This is my submission for G, in no way should it pass but still it passes.

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

My Solution Pretty sure , I have the same solution as that of the editorial . Dunno why I got the TLE though

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

Any idea why this submission is giving a WA for D? I have just subtracted the overlapping area instead of using the trapezium formula.`

https://mirror.codeforces.com/contest/1846/submission/212715188

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

1846-C - Rudolf and the Another Competition

Any idea why my submission gets a TLE here. Time complexity is O(n*mlogm). 212937677

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

can python sqeeze through C and D without TLE?

here's my code and they seem to not work even tho the complexity is exactly identical to the editorial

https://mirror.codeforces.com/contest/1846/submission/212613024 (C)

https://mirror.codeforces.com/contest/1846/submission/212645926 (D)

an explanation or help would be wonderful.

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

My solution in B does not require a review of 4 cases.

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

well , i am still a beginner, but in problem 3 ... i don't get how did we store the solution times for each student by this :

for(int i = 0; i < n; i++){ vector cur(m); for(int j = 0; j < m; j++){ cin >> cur[j]; }

while this should only store the last student only since it overwrites the existing values in each new outer loop ?

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

    You're correct; this only stores the solution times for the last student. But notice that right after reading this, we already handle this student by calculating the optimal number of problems and minimum time penalty for this student. Thus, we don't need to store the problem-specific times for any longer and they can be overwtitten by new data.

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

212951522 For problem F, why does this code give Idleness Limit Exceeded

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

In E2, can somebody tell me the value of k that satisfy 29th test case i.e. n = 64000160000400001, I think this test case is wrong.

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

can someone explain me the problem D in c++? I don't really get the idea of it, thank you in advence

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

Dial's algorithm can be used in G to achieve $$$O(2^n \cdot (m + MAXd))$$$ complexity. 212963777

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

I did think about BS at E2 in the cts, but I couldn't go with that, someone please tell me the editorial of that solution, I really need it. Thank you.

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

    Assume that we have an array {$$$a_k$$$} satisfied $$$a_k = k^2+k+1$$$ , then we can see $$${a_k}$$$ is increasing when k increases. So BS works on this array. We can use BS to check whether the given $$$n$$$ is in {$$$a_k$$$}.Pick $$$l$$$=2 and $$$r$$$=minimum $$$k$$$ satisfied $$$a_k \gt 10^{18}$$$ and BS.Then we can check $$$b_k = k^3+k^2+k+1 $$$ , $$$c_k = k^4+k^3+k^2+k+1 $$$ ... till $$$A_k = k^{63}+k^{62}+...+k+1$$$ .If the given $$$n$$$ doesn't stay in the arrays mentioned above , the answer is "NO".

    You don't really need to construct these arrays and store the value of them (MLE) , just calculate $$$a_{mid}$$$ and compare $$$a_{mid}$$$ with the given $$$n$$$ .

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

can anybody tell me what is wrong with this submission for F.

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

In problem G, you should have mentioned that you can use a medicine several times because without it the problem seems quite complicated. By the way, does anyone know if it's possible to solve the problem if we can use each medicine only once?

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

Try to solve E2 with binary search, Don't know what I've missed

https://mirror.codeforces.com/contest/1846/submission/212862518

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

this solution is accepted in e1 but not in e2,provide me some reason, let n=1+x+x^2......+x^i ------ eq(1) now, we know, x^i<n<(x+1)^i (by binomal theorm) that, means x<n^(1/i)<x+1, now x can be gif(n^(1/i)), we will satisfy eq(1) with x, if it is true ans exist. we will do it for i between 2 to 61.

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

Oooh, F was sooo easy, why I didn't read it during the contest:(

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

In E2 , for n greater 1e12 we can directly use Shree Dharacharya formula to know whether a k exist or not. And for k from 1 to 1e6 we can make a set of sum of G.P . I got this intuition in the contest but was getting TLE while calculating the sum of G.P . :( Got accepted in 1 try post contest.

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

why there is Rudolph and Rudolf?

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

why there is Rudolf and Rudolph?

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

Why there is Rudolph and Rudolf?

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

Can somebody help me to spot why is giving Idleness Limit Exceeded?

https://mirror.codeforces.com/contest/1846/submission/213728138

I've tried several things, but still can't find the issue.

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

Hi, could anyone help debug my submission? This is for 1846B. My submission is https://mirror.codeforces.com/contest/1846/submission/214305302

Thanks in advance!

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

What a deceitful problem C!

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

what is k for 1000015000057 in 11th test in E2?

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

Why do I get a Idleness Limit Exceeded on my code for F? [Code] Please help

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

Hello guys, in 1846F - Rudolph and Mimic, continously getting time limit exceeded, even though I have verified my solution with editorial, and have tried to match it to the author's solution. Can anyone please let me know what could be the issue here :( -> 216464518

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

Как сбросить буфер вывода в C#? С Console.Out.Flush() после каждого вывода получаю ошибку исполнения.

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

    Отбой этого вопроса, как выяснилось, это вообще не нужно. Зато другой вопрос: а почему в строке с массивом могут быть дополнительные пробелы, и почему об этом не написано в условии?

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

alternate dp solution for G

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

1846G is really a nice question,lovely

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

I really liked the author's solution to G. Taught me how to modify Dijkstra's algorithm for dense graphs like this.

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

I dont get why the quadratic formula must be used in E2? wont the set include the sum for the p=2 case anyway?

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

C was a piece of SHIT!

Worst question I ever seen on CF

Comment Down if you feel the same