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

Автор cry, 3 года назад, По-английски

We hope you enjoyed these problems :) This contest has been in the works for almost a year.

About the Authors

UPD: D1D Editorial have been updated

UPD 2: D1D Editorial now has images by EmeraldBlock. As an apology gift for being so slow, the image generator is programmatic and available here.

1853A - Desorting

Problem Credits: buffering

Analysis: buffering

Hint 1
Solution
Code (C++)

1853B - Fibonaccharsis

Problem Credits: ntarsis30, cry

Analysis: cry

Hint 1
Solution
Code (C++)

Bonus: Solve for $$$n, k \leq 10^9$$$

Bonus Solution

1852A - Ntarsis' Set

Problem Credits: nsqrtlog

Analysis: nsqrtlog, buffering

Hint 1
Hint 2
Solution
Code (C++) -- Model Solution
Code (C++) -- Simulation (more readable)

1852B - Imbalanced Arrays

Problem Credits: nsqrtlog

Analysis: buffering, nsqrtlog

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)

1852C - Ina of the Mountain

Problem Credits: fast-fourier-transfem

Analysis: fast-fourier-transfem, EmeraldBlock, GusterGoose27

Hint One
Hint 2
Hint 3
Tutorial
Code (C++)

1852D - Miriany and Matchstick

Problem Credits: ArielShehter

Analysis: EmeraldBlock, emorgan

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)

1852E - Rivalries

Problem Credits: buffering, ArielShehter, fast-fourier-transfem

Analysis: oursaco

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)

1852F - Panda Meetups

Problem Credits: Benq

Analysis: Benq, oursaco

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)
Разбор задач Codeforces Round 887 (Div. 1)
Разбор задач Codeforces Round 887 (Div. 2)
  • Проголосовать: нравится
  • +183
  • Проголосовать: не нравится

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

One of the editorials of all time.

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +144 Проголосовать: не нравится
    Fun facts about my problem D1C/D2E (Ina of the Mountain):
»
3 года назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

such a well written editorial :heart_eyes:

also i get photo credits :OO

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

great contest and Very interesting problemset :) ,but HUGE skill gap between div2B and div2C

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

Interesting Problems and quick editorials :3

I like problems 1A 1C very much, but have not enough time for 1D...

Also, isn't 1A too difficult for this place?

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

wow, that is fast

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

the hardest div 2 i have ever seen :<

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

Slightly sad that more people didn't find the really cool O(n) solution for C, but glad that people who solved it seemed to like it

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

    Can you explain the $$$O(n)$$$ solution?

    Additionally, my solution for D1A was $$$O(k \log n \log nk)$$$ and I can't understand the editorial of $$$O(n + k)$$$ solution, can you explain it more in details!?

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

      I can take a stab at it! I am not sure if this is the same as the editorial, but the following submission: 215239360 has the same complexity O(n+k).

      The first thing to notice is that the answer is at least the mex of the array. Therefore, we can start from the mex. If this is 1, then the answer MUST be one which should be intuitive. Otherwise, lets sort the array and try to build the answer from day 1 to day k.

      Notice that with any day, the answer will increase by an amount equal to the current prefix of the array we take.
      ie. Let us say we have the array [ 1 , 15 , 30 ]. The answer will increase by 1 while it is <15, then we "take" 15 and the answer will increase by 2 while it is <30, then the answer will increase by 3 for the rest of the days. Using this idea, all we have to calculate is the number of days until we can take the next element. Look at the above solution for more details :) Let me know if you have any questions.

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

        hi, but in the example that you showed I understood that we keep on taking 1 while the answer is < 15 but how are we going to take into account the fact that the elements at the position 15 and 30 are going to be removed because If we don't take that into account and I am assuming that ans in your solution represents the current mex then when we reach 30 it is already removed similarly 31 is already removed and ...

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

The condition that "no two elements sum to 0" implies that every bi has a distinct absolute value

Why?
For a = [4,4,4,4], b = [ 4,4,4,4] is a valid solution.

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

in C you have four paragraphs of absolutely obvious text then only one sentence related to the solution and it's absolutely unclear

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

good 1a/1b/1c! I'm trying to improve my IQ for 1d.

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

Another way to solve Div2C is to note that the answer for $$$day=k$$$ is the $$$\text{(answer for day=k-1)^{th} }$$$ mex of the array $$$a$$$.

Overall time complexity is $$$O(n+k*\log_2(n))$$$.

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

    can you share how did you reached to this conclusion? Non-origination

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

      Denote $$${mex}_i$$$ to be the $$$i^{th}$$$ mex of the array $$$a$$$, i.e. the $$$i^{th}$$$ smallest positive integer that is not present in $$$a$$$. The values remaining after Day 1 are seen to be $$${mex}_1,{mex}_2,{mex}_3,{mex}_4,\ldots$$$. View this sequence as just a symbolic replacement of the values remaining initially($$$1,2,3,4,\ldots$$$). Since the algorithm of removal is the same for each day, it follows that the values remaining after Day 2 are $$$mex_{mex_1},{mex}_{{mex}_2},{mex}_{{mex}_3},{mex}_{{mex}_4},\ldots$$$. This pattern holds for the values remaining at the end of any Day by induction.

      For example, consider the second sample test case. Here $$${mex}_1=2,{mex}_2=4,{mex}_3=8,{mex}_4=9,{mex}_5=10,\ldots$$$. The values remaining at the end of Day 1 are $$$2,4,8,9,10,\ldots$$$ i.e., $$${mex}_1,{mex}_2,{mex}_3,{mex}_4,{mex}_5,\ldots$$$. $$${mex}_{{mex}_1}={mex}_{2}=4,{mex}_{{mex}_2}={mex}_{4}=9,{mex}_{{mex}_3}={mex}_{8}=13,\ldots$$$. The values remaining at the end of Day 2 are indeed $$${mex}_{{mex}_1},{mex}_{{mex}_2},{mex}_{{mex}_3},\ldots$$$=$$$4,9,13,\ldots$$$.

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

        How are you keeping track of k-1th mex of the array?

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

          In my submission, I iteratively compute the ith mex of the array for all 1≤i≤k. You can refer to my submission https://codeforces.me/contest/1853/submission/215255944

          Here $$$f(a,prefix,i)$$$ computes the ith mex of the array $$$a$$$. The jth element of the prefix array stores the number of positive integers that are not present from $$$1$$$ till the value of the jth element of the array $$$a$$$ (So $$$prefix[j]$$$ is actually just $$$a_{j}-(j+1)$$$ in 0-based indexing). You can binary search the value $$$i$$$ in this prefix array in order to calculate the ith mex of the array in $$$log2(n)$$$ time. The base case where $$$i=1$$$ is calculated beforehand and the ith mex for 2≤i≤k can be calculated by iteratively calling the function $$$f(a,prefix,\text{answer for day i-1})$$$.

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

I was about to become Candidate Master today but got FST (Failed System Testing) on the B problem : (

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

Quoting from 1852B/Solution -

The condition that "no two elements sum to 0" implies that every $$$bi$$$ has a distinct absolute value.

That is incorrect. Two elements can still have equal absolute value (for e.g. -3 and -3). However it can proved that if a solution with two equal elements exists, then there must also be a solution having every $$$bi$$$ value distinct.

Luckily, I made the same conclusion as given in the editorial at the time of the contest, so I did not have to prove the above statement mid contest. But those who did realize it, I feel bad for you for having to prove it xD

P.S. great problem, btw!

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

Love the editorial with hints :) Also C was hard, I solved B fast but stuck at C until the end of the contest lol.

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

tnx 4 fast editorial

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

Must problem div2C use long long? I found one of my friends passed it without using long long.

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

I solved Problem C with binary search. I search if we can delete a prefix of numbers 1, 2, 3, ... x using given operations. If we can delete it then we can also delete prefix upto x-1, x-2 and so on.

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

A recursive solution of 1853B - Fibonaccharsis:

If n equals to the k-th Fibonacci number F[k], then the answer is 1.

If n < F[k], then the answer is 0.

Otherwise, let us replace n by n-F[k]. Note that the difference of any fibonacci-like sequence and the standard fibonacci sequence is also fibonacci-like, unless the case where the first two elements of our initial sequence are equal. But this happens if and only if n is divisible by F[k+1], and this adds precisely 1 to the answer.

Code: 215213454

  • »
    »
    3 года назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится
    • Thankyou so much for sharing. I also had a similar observation but being a noobie couldn't build a solution.
    • I understood how the recursion will work-out by using the fact that "...Note that the difference of any fibonacci-like sequence and the standard fibonacci sequence is also fibonacci-like"
    • I did not understand this part "...unless the case where the first two elements of our initial sequence are equal. But this happens if and only if n is divisible by F[k+1], and this adds precisely 1 to the answer." Can you PLEASE explain this a little more. I tried for a good amount of time but can't figure this out.
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Cannot understand editorial of div2C

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

Well, I couldn't solve B yet I want to know if the following observation is correct ? "if the k-th element of a real-fibonacci(starting with 0,1) is greater than the required n, then the ans has to be zero". I just don't trust myself so it would be nice if anyone could point out if this wrong ?

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

1852D — Miriany and Matchstick

how would ABABAABAB be a valid answer for:

9 17 BAAABBAAB since its just 13 and k is 17 ?

B A A A B B A A B | | | | | | A B A B A A B A B

thats 6

A_B_A_B_A.A_B_A_B

and thats 7

what I miss ?

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

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

div1D can also be solved using greedy, because most of the time, each operation only adds one to the answer.

Here's my code: https://codeforces.me/contest/1852/submission/215259895

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

I used a mysterious method to pass this problem in C of Div2, with time complexity O(n). Is anyone interested in proving the right thing to do? https://codeforces.me/contest/1853/submission/215254923

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

Was somebody able to AC div1D with divide and conquer + fft/ntt in O(nlog^2n)? My code ACs in around 15s, which is not close to the TL, but maybe it's possible to squeeze it in the TL with a faster fft/ntt implementation

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

I saw many solving C with binary search, can anyone explain it?

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

    I solved Div2 C by binary searching on the minimum length $$$\ell$$$ of the set $$$A_\ell = [1, \ldots, \ell]$$$ such that performing the operations on the (finite-size) array $$$A_\ell$$$ left the set nonempty after $$$k$$$ steps. Observe that if $$$A_\ell$$$ is empty after $$$k$$$ operations but $$$A_{\ell+1}$$$ is not, then $$$\ell+1$$$ is our answer. For a given $$$\ell$$$ my solution determined the smallest $$$k'$$$ such that $$$A_\ell$$$ is empty after performing $$$k'$$$ steps, and compares $$$k'$$$ to $$$k$$$ to update the search bounds.

    To simulate the procedure for a given $$$\ell$$$, notice that up to relabeling, all that really matters at each step is the number of elements $$$x$$$ remaining in the set. This allows us to simulate the deletion in $$$O(n)$$$ regardless of $$$\ell$$$ by repeatedly (1) updating the number of elements $$$m$$$ that will be removed (i.e., the maximal $$$m$$$ such that $$$a_m \lt = x$$$) and (2) performing the maximum number of steps removing that many elements in $$$O(1)$$$.

    The answer is upper bounded by $$$nk + 1$$$. The total runtime is thus $$$O(n \log (nk)) = O(n \log n + n \log k)$$$.

    Submission: 215276044

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

      My binary search is similar. I do binary search on the answer (that is $$$l+1$$$, but call it $$$ans$$$), and check if it is deleted from $$$a_n$$$ to $$$a_1$$$.

      Suppose the number deleted by $$$a_i$$$ in the $$$j$$$-th round is $$$x$$$. Since in this round i numbers $$$\le x$$$ are deleted, the number deleted by $$$a_i$$$ in the $$$(j+1)$$$-th round should be the $$$i$$$-th undeleted number after $$$x$$$. The numbers deleted this time which are greater than $$$x$$$ must be deleted by $$$a_{l \gt i}$$$, so do it from $$$a_n$$$ to $$$a_1$$$.

      Suppose $$$y$$$ numbers smaller than $$$ans+1$$$ are deleted by $$$a_{n},a_{n-1},\dots,a_{i+1}$$$, there're now $$$ans-a_i+1-y$$$ numbers not deleted in $$$[a_i,x]$$$. Since it goes $$$i$$$ steps each time, the answer for $$$a_i$$$ is $$$\lceil\frac{ans-a_i+1-y}i\rceil$$$.

      Just sum them up and check if the value is $$$\le ans-1$$$. If so, the real answer should be less or equal to the current. The time complexity is $$$O(n\log \text{ANS})$$$

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

      esr6vqa LMydd0225 thanks to you both, I got the intuition and how we could come up with such solution,thanks again.

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

Bonus solution of D2B can be optimized up to O(1) per testcase (with the precalc of Fibonacci numbers) knowing that

$$$F_{k-2} * F_k - F_{k-1} * F_{k-1} = +-1$$$
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This div2C is where I doubted my entire existence :( --> cries in low IQ

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

Is it just me or C was harder than D?

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

In problem D(Div2),can someone please explain the Hint1 given in the editorial(I mean why is this statement true).

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

    Let's say you have 2 ones in $$$b$$$. Then you didn't use at least one number from $$$1$$$ to $$$n$$$ as the absolute value. You can add 1 to all numbers, which absolute values are less than that missing number, then you won't have $$$2$$$. Then you can replace one of ones with two and all constraints will still be true.

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

Another solution for Div $$$2$$$ B.

We can write $$$f_k$$$ as a linear combinaison of $$$f_1$$$ and $$$f_2$$$. Thus by precomputing these coefficient for $$$k \le 30$$$. Let $$$f_k = a \cdot f_1 + b \cdot f_2$$$ the problem is reduced to finding $$$f_1$$$ and $$$f_2$$$ for which $$$f_k = n$$$. now knowing that $$$f_1 \le f_k$$$ since $$$(f)_n$$$ is increasing we can try all $$$0 \le f_1 \le n$$$. Since $$$a, b, f_k$$$ are fixed we can check if there is $$$f_2$$$ verifying the aforementioned conditions. Submission

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

The explanation for div1D is kinda bad. "we can show that [...]" isn't sufficient, please show it. It took me a long time to realize that when you flip b2...bn-3, then the thing changes by some odd value.

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

A little late, but I wanted to share my solution for div2C/div1A that runs in $$$O(k \log n \log a_i)$$$ time.

Consider binary searching on the answer. To check if a certain $$$mid$$$ is valid, we have to determine if all the values $$$\leq mid$$$ will end up getting deleted over the course of the $$$k$$$ days. To determine the number of values $$$\leq x$$$ which get deleted for some $$$x$$$, we just have to find the number of values in $$$a$$$ that are $$$\leq x$$$. This can be done with a second binary search or builtin functions like std::upper_bound. After determine the amount that are deleted, we can subtract this from $$$mid$$$ and simulate the remaining days on the new $$$mid$$$. This gives an $$$O(k \log n$$$ check function and an $$$O(k \log n \log a_i)$$$ sol overall.

Code:


#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ cin.tie(0) -> sync_with_stdio(0); int T; cin >> T; while(T--){ int n, k; cin >> n >> k; vector<long long> arr(n); for(auto& x : arr) cin >> x; long long l = 0, r = 1e18; while(l != r - 1){ long long mid = (l + r)/2; for(int i = 0; i<k; i++){ mid -= upper_bound(arr.begin(), arr.end(), mid) - arr.begin(); } if(mid <= 0) l = (l + r)/2; else r = (l + r)/2; } cout << l+1 << "\n"; } return 3366^3366; }
  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    This is basically what I did; the inner check can additionally be done in $$$O(n)$$$ by maintaining a pointer to the amount $$$m$$$ subtracted off (it can only decrease) and additionally subtracting off as many multiples as possible in a single step. In my code this looks like

    lli pos = (lo + hi) / 2;
    lli ct = pos;
    lli t = 0;
    lli m = n - 1;
    
    while (ct > 0) {
        while (arr[m] > ct) --m;
        int times = 1 + (ct - arr[m]) / (m + 1);
        t += times;
        ct -= (m + 1) * times;
    }
    

    This nicely allows larger constraints on $$$k$$$.

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

i love cerealcodes <3

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

Great round! but the statement of 1852D is a little unfriendly to people suffer from red-blindness like me, it will be better if you show "the pairs of different characters" in bold rather than in red.

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

Tough round. Yes, I cry.

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

Good round! I love the ideas, very stimulating. Here's another solution for D1B/D2D, using hashing.

Firstly sort $$$a$$$, then $$$b$$$ becomes a increasing sequence. Try to find a $$$pos\in [0,n]$$$ satisfies that $$$b_{pos} \lt 0$$$ and $$$b_{pos+1} \gt 0$$$ (we assume that $$$b_0=-\infty$$$ and $$$b_{n+1}=+\infty$$$). Notice that for a $$$b_i \lt 0$$$,it will exactly match up with $$$[n,n-a_i+1]$$$. and for a $$$b_i \gt 0$$$, it match up with $$$[pos+1,n]$$$ in addition. Now we say there's a solution, if and only if there's a $$$pos$$$ that satisfies every index $$$i$$$ have been matched exactly $$$a_i$$$ times.

Now let's construct a solution to prove it. Assume that $$$b_{pos},b_{pos+1},…,b_{n}$$$ equals to $$$1,2,…,n-pos$$$ at the beginning. For every $$$b_i \lt 0$$$, we let $$$b_i=b_{n-a_i+1}$$$, and add $$$1$$$ to all the $$$b_j(j\not =i)$$$ that are equal or greater than it. In the end it will generate a correct $$$b$$$. We can use a difference array to make it in $$$O(n)$$$.

Then the problem is how to find a $$$pos$$$. Check every possible value. Process the hash value of sequences like $$$1111…1$$$, then you can check each value in $$$O(1)$$$.

The total time complexity is $$$O(n\log n)$$$ due to sorting.

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

In div1C, I try to use dp to solve it but failed. let dp[i][j] be the min operations that position i is decreased by a[i]+j*k times and dp[i][j]=min dp[i-1][j']+max(0,a[i]+j*k-a[i-1]-j'*k) I don't know if there are anywhere wrong.

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

It's been a day but I still don't understand what is the (a[inc] — ans + inc — 1) in the problem Ntarsis' Set :-(

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

thanks for information

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

can someone explain how they solved B(1853B — Fibonaccharsis) by using binary search....

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

I remember that this div1A appeared as the last problem in some div1 contest but with many queries asking for the number at position P at time T. Anyone that upsolved that one can link it here?

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

I can not understand jiangly's 1A.

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

Hi, I was just curious what does "Analysis" in editorial mean. Is it preparation of testcases or finding the solution to the problem and proving it or maybe converting idea into problem statement.

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

In editorial for div1C "Our goal is to find a path of minimum cost from (0,0) to (k+1,0)", shouldn't it be (n+1,0) ?

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

samples are really great

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

link to problem: https://codeforces.me/contest/1853/problem/B

I have come up with an O(n*log(n)*k) solution where I loop through all possible f1, then binary search on f2. I confirm the f1 and f2 combo works through a memoized Fibonacci dp, that runs in O(k) where k denotes the kth term. But when I run it, my program times out.

Can someone help me identify what is taking my solution so long? (implementation or strategy)

I submitted it so you can view my solution: https://codeforces.me/contest/1853/submission/216182584

If you hate java like me, here is the c++ version: https://codeforces.me/contest/1853/submission/216183198

Thank you in advance

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

In Problem — D — Codeforces,dose the dp only consist two intervals which are adjacent

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

There are codes here,it's really great tutorial!

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

I found a interesting solution for problem B in O(number of fibonacci numbers under n)

        vector<double>fib(35);
        fib[1]=1;
        for(int i = 2;i < 32;i++){
	  fib[i]=fib[i-1]+fib[i-2];
        }
	int n,k;
	cin >> n >> k;
	if(k>30)cout << 0 << nl;
	else{
	    if(k%2==0){
		cout << floor((fib[k-1]*n)/fib[k])-ceil(((fib[k-2]*n)/fib[k-1]))+1 << nl;
	    }
            else{
		cout << floor(((fib[k-2]*n)/fib[k-1]))-ceil((fib[k-1]*n)/fib[k])+1 << nl;
	    }
	}
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

On the surface, it looks like you have put a lot of effort in writing the editorial. But for someone, who was not able to solve a problem, to be able to read what you have written, understand it and solve it on their own is simply not possible.

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

My Solution:381529268

I find this approach much easier to understand.

The nth term is just a linear combination of the first two terms: xa + yb; where a and b are the first and second terms respectively. We first find the values of the coefficients x and y simply by iterating the fibonacci pattern. Then we just find for what integer-values of a and b the equation xa + yb = n is satisfied.

Edge case of the hint should be handled accordingly.