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

Автор BlueSmoke, 6 лет назад, По-английски

You can view Chinese editorial here: https://www.luogu.com.cn/blog/Caro23333/codeforces-round-641-zhong-wen-ti-xie

Div2.A Problem and editorial by BlueSmoke

Editorial
Code

Div2.B Problem and editorial by BlueSmoke

Editorial
Code

Div1.A Problem and editorial by mydiplomacy

Editorial
Code

Div1.B Problem and editorial by A.K.E.E.

Editorial
Code

Div1.C Problem and editorial by A.K.E.E.

Editorial
Code

Div1.D Problem and editorial by Rebelz

Part of solution by Elegia

Editorial
Code

Div1.E Problem and editorial by A.K.E.E.

Editorial
Code

Div1.F Problem and editorial by Rebelz

Hard version solution by Elegia

Editorial for easy version
Code
Editorial for hard version
Code

You can also view Div1.F editorial by Elegia here: https://codeforces.me/blog/entry/77280

Anyway, hope you like these problems and thank you for participating!

Разбор задач Codeforces Round 641 (Div. 1)
Разбор задач Codeforces Round 641 (Div. 2)
  • Проголосовать: нравится
  • +296
  • Проголосовать: не нравится

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

Thanks for Editorial. Really enjoyed the contest. Problems were very interesting

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

Good problems!

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

nice problem set (math)

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

can anyone plz check my solution for div2 C (it got accepted during contest) https://codeforces.me/contest/1350/submission/79877064

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

Anyone else solved D1C using bitsets?

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

    Bitsets are expected to get MLE or something else. I'm curious about your solution XD

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

      Well, I have noticed two facts (both are proven in the editorial):

      1. Preperiod of the grid is at most $$$n + m$$$.
      2. Period of the grid is at most $$$2$$$.

      So I have written a function go(vector<bitset<1000>>) which would give me the next iteration in $$$O(nm/64)$$$. It is not hard to come up with a boolean function $$$f(val, l, r, d, u)$$$ which would give the result for the next iteration ($$$l, r, d, u$$$ are the values of adjacent cells). So using this formula we can compute a whole row in $$$O(m / 64)$$$.

      Now for queries with $$$p \lt n + m$$$ I use scanline, and for $$$p \geq n + m$$$ I look at the parity. So I am using $$$O(nm(n + m)/64 + t)$$$ time and $$$O(nm/64 + t)$$$ memory.

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

Another good Chinese round !

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

In d1C, you have used grid instead of cell, for example

for a bad grid $$$\dots$$$

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

save some problems for IMO

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

I would like to give an interesting (although not optimal in terms of complexity) for div 1C. Observe the grid will "converge" to a length 2 cycle after some sequence of move. You can find that out by writing a brute force solution. With some guessing, you may find out you need around $$$n + m$$$ steps to converge, which is consistent with the results in the editorial.

The problem is brute force requires $$$O(nm(n + m) + t)$$$ which is too slow. However, we can speed up the brute force using bitset. By shifting and some bitwise operations, you can check and update the whole row at once. You may also want to use the rolling array technique to fit in the memory limit. The complexity after optimization would be still $$$O(nm(n + m) + t)$$$ but with an additional $$$1/64$$$ constant, which should fit in the time limit.

79891996 The solution is badly written, serve as proof-of-concept only.

Fun fact: with the rolling array technique, my solution uses less memory compared to most solutions.

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

What does this sentence means?

Let $$$E_x$$$ be the sum of probability times time when the game end up with all biscuits are owned by the x-th person

Nice editorial but i wish your English was stronger :(.

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

Can someone explain Div1D better? Thanks

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

    I used Generating Function to solve, and maybe it is easier to come up with such solution if you are familiar with them.

    First, let $$$a_k$$$ be the probability of ending the game in $$$x$$$ turns. Let $$$A(x) = \sum_{k=0}^{\infty} a_kx^k$$$. Then our objective is to find $$$A'(1)$$$, where $$$A'(x)$$$ is the derivative of $$$A(x)$$$.

    Finding $$$A(x)$$$ is hard, so we should multiply something to it to make it easier. From now on, for convinience, assume the game doesnt end even if the ending state occurs. Let $$$b_k$$$ be the probability of one person having all biscuits after moving k steps starting with the state, and that it is the first time that person owns all biscuits. Let $$$B(x) = \sum_{k=0}^{\infty} b_kx^k$$$. Then, we realise that $$$A(x)B(x)$$$ is the generating function of the sequence $$$c$$$, where $$$c_k$$$ is the probability of a person owning all biscuits after $$$k$$$ steps (also enforce that it is the first time that person owns all biscuits). Denote generating function of $$$c$$$ as $$$C(x)$$$.

    $$$C(x)$$$ can be written as sum of $$$D_i(x)$$$, where $$$D_i(x)$$$ is the generating function for the sequence $$$d_{i,k}$$$, where $$$d_{i,k}$$$ is the number of ways to reach the state that $$$i$$$-th person has all the biscuits the first time after $$$k$$$ steps. Consider $$$D_i'(1)$$$, which is the expected number of steps to reach that state. We realise that this value is only dependent of $$$a_i$$$, $$$n$$$, and total number of biscuits. Let's denote it as $$$e_{a_i}$$$. The $$$e$$$ forms a Markov Chain and you can solve all values of $$$e$$$ in $$$O(n*log)$$$.

    Finally we will go back to the original formula, $$$A(x)=\frac{\sum_{k=1}^{n} D_k(x)}{B(x)}$$$.

    Then, $$$A'(1)$$$

    $$$= \frac{B(1)(\sum_{k=1}^{n} D_k'(1))-(\sum_{k=1}^{n} D_k(1))B'(1)}{B(1)^2}$$$

    $$$= \frac{n(\sum_{k=1}^{n} e_{a_i})-n(n-1)e_0}{n^2}$$$

    Which can be computed in $$$O(N)$$$ easily.

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

There is a 1200 points difference between problem C and problem D. Has anyone seen a bigger difference?

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

Tricky Questions

I was fooled by the D2/B problem into n^2 DP, it blocked my mind.

After that my confidence was lost and finally I gave up. and now I found out how iterations were made in the problem and it is kind of like the iteration we make while sieving primes.

Overall, it is depressing!!!

Still, I would like to appreciate and say very good work done by the writer!!

Thank you for the contest

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

Another interesting solution for Div2 C is that the value of gcd of all pairs whose smallest index is 'i' is LCM(a[i], GCD of all a[j] s.t. j>i). The value corresponding to "GCD of all a[j] s.t. j>i" can be easily found using suffix array.

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

In div2C, doing what is said in the problem statement sufficed: 79904920 (After the contest but I am kind of disappointed)

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

please insert sample code of editorials , that will be better to understand .

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

Can someone explain the transformation formula in easy, mostly non mathematical, words?

$$$f_i = \max\limits_{j\mid i, s_j \lt s_i} {f_j + 1}$$$

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

Good problems(especially div2d)! Thanks!

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

Div 2B can't we solve 2B by making an unidirectional graph and finding the longest path?? can anyone see my solution and tell me what's wrong with that.(my submission 79865870)

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

Can anybody explain what that weird symbols mean in Div.1 B solution?

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

I know I was a little rude, but "Read problem statement" kinda pissed me off. Apologies to the setters but the statement was definitely ambiguous.

Div1 C "no adjacent cells with the same color as this cell", I interpreted initially as any two adjacent cells anywhere in matrix. It said nothing about "no adjacent cells to it".

wtf

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

    If you felt uncomfortable with that, we're sorry. But it is a quick option to answer a question, just like Yes, No, No comments and Question is unclear. So I think the usage of this is also reasonable.

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

    +1
    English is bad in this statement. Simply writing "A black cell changes if at least one of its adjacent cell is black and same for white." was sufficient.
    Even after understanding it, I had to read it whenever I need this condition while writing soln.

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

      That's so true. Although the meaning of the statement (condition) is clear for me, I messed up the condition multiple times while debugging. I have to reread the condition again and again just to make sure I did not think in the opposite way.

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

Alternatively for Div 2D/1B, you can try finding any subarray of length at least 2 which has median at least k. If you can find such a subarray, the answer is yes, otherwise it is no. FatalEagle describes how to find number of subarrays with median at least k over here.

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

.

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

I have a very short solution for Div1A which I think is pretty cool, and is not mentioned in the editorial. It uses dp:

#include <bits/stdc++.h>

using namespace std;

long long gcd(long long a, long long b){
  if (a == 0)
      return b;
  return gcd(b % a, a);
}

long long lcm(long long a, long long b)  {
  return (a*b)/gcd(a, b);
}

int main(){
  int n;
  cin >> n;
  vector<long long> a;
  long long ai;
  for(int i = 0; i < n; i++){
    cin >> ai;
    a.push_back(ai);
  }
  vector<vector<long long> > dp(2, vector<long long>(n, 1));
  dp[0][0] = a[0];
  dp[1][0] = a[0];
  dp[0][1] = gcd(a[0],a[1]);
  dp[1][1] = lcm(a[0],a[1]);
  for(int i = 2; i < n; i++){
    dp[0][i] = gcd(dp[0][i-1],a[i]);
    dp[1][i] = lcm(dp[0][i-1],gcd(dp[1][i-1],a[i]));
  }
  cout << dp[1][n-1] << "\n";
}

https://codeforces.me/contest/1350/submission/79884445

Basically the idea is we can keep track of what primes are divisors of all the numbers, and which primes are divisors of at least n — 1 of the numbers. The first row in dp is just the gcd of all the numbers, thus the primes which divide all numbers. The second row of dp is the factors which divide at least n — 1 of the numbers. The first row is easy to calculate, its just the gcd of the current number in the array and the previous column in dp. The second row is a little trickier, but it's just the lcm of the primes which divide all the previous numbers and the gcd of the previous column and the current number in the array. The code itself might explain it a bit clearer.

But basically to get the primes which divide at least n — 1 of the numbers, you can either just take all the primes which divide all of the first n — 1 numbers, or take the primes which divide at least n — 2 of the first n — 1 numbers, and also divide the current nth number, which is how you get the second equation. The final answer after iterating through dp is then just the cell in the second row and last column.

The code itself might make what I'm saying a bit clearer. If this is confusing I can try to explain it better, but I thought this was a pretty neat solution.

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

    Your explanation is pretty clear than editorial for me but it's a little confusing how you are getting factors that divide n-1 numbers. It would be highly appreciable if you explain it with an example :)

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

      Ok let me try:

      So for example let's use one of the pretests:

      10 24 40 80

      We start by assigning dp[0][1] = gcd(10,24) and dp[1][1] = lcm(10,24), as the gcd gives all the primes which divide both, and lcm gives all the primes which divide at least n-1 (so in the case of the first two numbers, we include any prime which divides either). So now we have dp[0][1] = 2 and dp[1][1] = 120.

      Now, calculating dp[0][2] is easy, it's just gcd(dp[0][1], 40) = 2. This is all the factors which divide all of the first three numbers. Now we calculate dp[1][2] by lcm(dp[0][1], gcd(dp[1][1], 40) = lcm(2, gcd(120,40)) = lcm(2, 40) = 40. So here we have that all the prime powers of 40 divide at least (3-1)=2 of the first 3 numbers (when I said factors in the previous post its actually slightly incorrect, as we in fact need any prime power factor to divide at least n-1 of the numbers, not any factor).

      The reason we did lcm(2, gcd(120,40)) is the following: 2 divides all of the first 2 numbers, so it trivially divides (3-1)=2 of the first 3 numbers. On the other hand, prime powers in 120 divide at least (2-1)=1 of the first 2, and so if we take gcd(120,40), the result will also divide 40, and so we get prime powers which divide 1+1=2 of the first 3 numbers. We then take the lcm of these two cases, as any prime power which satisfies either is good.

      Finally, for 80, we have dp[0][3] = gcd(2,80) = 2, and dp[1][3] = lcm(2, gcd(40,80)) = lcm(2,40) = 40, and that is in fact the desired answer.

      Let me know if this helped :).

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

A (maybe) more intuitive way for Div1 D:

Let $$$m=\sum a_i$$$. Like this problem, if we find a potential function $$$f$$$ such that $$$\mathbb{E} \left(\sum_{i} f(a_i) \right)$$$ decreased by $$$1$$$ in each step, the answer is simply $$$\sum f(a_i)-\left((n-1)f(0)+f(m)\right)$$$, which is the initial potential minus the final potential.

To satisfy the condition, we have equaltion

$$$\sum_i f(a_i)=\sum_{i} \frac{a_i}{m} \left((f(a_i-1)+1) + \left(\sum_{j\neq i} \frac{1}{n-1}f(a_j+1)+\frac{n-2}{n-1} f(a_j))\right)\right)$$$

, which is

$$$\sum_i \left(\frac{a_i}{m} (f(a_i-1)+1) + \frac{(m-a_i)}{m(n-1)} f(a_i+1)+\frac{(m-a_i)(n-2)}{n-1} f(a_i)\right)$$$

.

It is not hard to see if

$$$f(a)= \frac{a}{m} \left(f(a-1)+1\right)+\frac{m-a}{m(n-1)} f(a+1)+\frac{(m-a)(n-2)}{m(n-1)} f(a)$$$

for all $a (0\leq a \leq m-1)$, it satisfies the condition.

So simply solve these equations and find the answer.

We can use this method for all problems of this kind.

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

Div 2C/ Div 1A

observe --> lcm[a, gcd(b, c)] = gcd(lcm[a, b], lcm[a, c]) and gcd(a, lcm[b, c]) = lcm[gcd(a, b), gcd(a, c)]

using them the sought answer can be brought down to

gcd of { (a[i]*gcd(a[i+1], a[i+2], .. , a[n]))/gcd(a[i], a[i+1], .. , a[n] | i <= n }

so create an array (say, g) as: g[i] = gcd(a[i], a[i+1], .. , a[n])

check code here: 79893540

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

Anyway, problemset was nice — thx a lot

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

a good contest based on number theory. :)

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

Guys, could you please find the problem in my solution. By my mind it should work. Problem Div.2E-Div1.C .

My solution

I will be thankful.

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

Here is my O( NlogN ) solution to Div2C/Div1C. Code.

I counted the number of instances of each number in a count array mp. Then for each i=2 to 2e5, I have counted the number of elements in the sequence which are divisible by i in cnt[i]. Now if we observe the final gcd will have contributions only from numbers i which have cnt[i] >= n-1. ( They appear in at least one of the numbers for each pair. ) Now since it may happen than cnt[2] = n and cnt[4] = n-1. In that case we may ignore 2's contribution by taking a lcm of the current answer with 4 and similarly for higher powers of a prime. I hope I didn't make it complex for anyone :P.

How is it NlogN ? the loop in which I update cnt runs for (N + N/2 + N/3 + ... 1) which gives NlogN. Thanks to ffao for correcting me and Everule for the explanation why it is NlogN. Also sequential addition of Nlog(N) for calculating the cumulative gcd.

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

Div2 C/ Div1 A Can someone please check why my code is getting TLE. I think it should be within the bounds. My Code : 79910710

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

can someone tell whats wrong in my approach for A 79887649

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

I cannot get my head around div2C / div1A. Can someone explain it using some examples? Pretty please.

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

    Since array t contains all possible lcm of pairs from input, We just need to find the product of all prime numbers that divide atleast n-1 numbers of the input. A simple example would be [5 7 5 5], You can notice that every element in the array t would have 5 as one of its divisors since 7 cannot exist alone.

    Now lets take an example from sample test to see how the algorithm works:

    input= [10 24 40 80] , n=4 ans=1; //initially

    • Since all numbers are divisible by 2, divide all by 2 => [5 12 20 40], ans=1*2=2;
    • Since n-1 numbers are divisible by 2, divide them by 2 => [5 6 10 20], ans=2*2=4;
    • Since n-1 numbers are divisible by 2, divide them by 2 => [5 3 5 10], ans=4*2=8;
    • Since n-1 numbers are divisible by 5, divide them by 5 => [1 3 1 2], ans=8*5=40;
    • Algorithms iterates through rest of the numbers and final answer is 40.

    Code

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

      By f=2 you're checking if there are any two numbers not divisible by i ,but i did reverse I checked if there are n-1 numbers or not which are divisible by i and I got TLE. You just ended up getting lucky with test cases in this contest :P

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

        Not really, It's pretty obvious that if you loop n-1 times inside a loop of 2e5 its gonna be TLE. Notice how i have a break statement if 2 numbers are not divisible by i, The one thing to be noticed is 2e5 can only have a max of 17 prime divisors(2^17=1.3*1e5) so the inner loops only gets traversed around 17*2 times in worst case but for your code it gets traversed every time. It's not a coincidence that my solution got accepted in 62ms :)

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

      Hey, thanks!

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

Thanks for the problems!

By the way, a formal petition to the setters to write cleaner model solutions than this:

I mean, I can probably understand it, but please, you've got plenty of time before the contest. You aren't racing to write the models as fast as possible, and you can spend some of your time making sure the code is readable.

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

For problem Div2 D once checkout my solution 79912071 I have not checked a case when n = 1, I simply wrote if(n==1) cout<<"yes", but my doubt is there should be if(n==1&&arr[0]==k)cout<<"yes";

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

Why is this approach wrong for Div2B? I tried brute force and generated all sequences of divisors and then checked whether the sequence is beautiful or not. I am getting WA on pretest 2: link to submission

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

Editorial should be in little simple language. Can anyone please explain Div 2 Problem C?

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

Having trouble wrapping my head around one line of this problem: 1349A — Orac and LCM. In the proof, the editorial says: "Proof. if there are at most n−2 integers in a that s.t. pk∣ ai, there exists x≠y s.t. pk∤ax and pk∤ay, so pk∤lcm({ax,ay}) and pk ∤ ans."

I can't seem to convince myself why if pk does not divide ax and ay, it must not divide lcm({ax,ay})? Would appreciate any insight, thanks!

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

can anybody please tell me why my solution is wrong.Div2/prob b pretest2 failed. https://codeforces.me/contest/1350/submission/79864654

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

Can someone please check my solution. It's giving wrong ans I'm doing exactly as editorial it a O(n*sqrt(n)) solution https://codeforces.me/contest/1350/submission/79914083

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

My approach for Div1A/Div2C is similar to the Second approach discussed in the editorial, but I am unable to understand the first approach, can anyone help me telling how we arrive at the given observation mathematically?

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

https://codeforces.me/contest/1350/submission/79817740 This solution got accepted for A. Orac and Factors though its Time Complexity is O(k) and k is 10^9 .... How is this possible ????

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

lol am I the only who thought in div 2 B they were talking about values stored at indexes to be divisible instead of indexes

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

I have implemented the solution to Div2E/Div1C here https://codeforces.me/contest/1350/submission/79919196. Why am I getting runtime error and this weird verdict? I have been trying to debug my code but cannot find anything. If someone can please help it will be really great.

Edit: I've got it now, I was accessing q.front() by reference and then popped it. This was causing the RE.

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

Hey guys,

I would like to give me some tips to improve. Specifically, on problem D, during the contest, I observed that if we somehow can form 2 numbers equal to k in row, then we can easily convert the entire sequence to k. In order to do that, we can go to each k and look left or right and see if we can have it as a median. If we can't do it (or no such k exist), the answer is no. Otherwise, obviously, there is a way! Please refer to my submission here for more details on my approach: https://codeforces.me/contest/1350/submission/79882933

Then, I was getting always WAs on test 10 and I was scrambling to find a case where it didn't work, but I couldn't find what's wrong and eventually I missed the problem. After that, I saw a solution and it hit me; if we have 2 consecutive numbers that are greater than k or 2 that have a smaller number in between, we can propagate it until it reaches a k and after that we can use my approach to finish it.

Unfortunately for me, I was unable to see this case and I did not solve the it. I would like your opinion on those 2 stuff:

  1. What is the easiest way to generate test cases that could help on finding the flaws on a speculation like the one I presented above? For me, it's quite difficult to find any (especially on this problem).

  2. On this case, was there any other way to disprove a speculation other than trying to find a counterexample?

Any help appreciated! Thanks!

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

    Use Python to generate many small cases and a brute force solver. Though it might be hard for graph problems. But for problem D, this can be made. I do this when I can't figure out what's wrong and it also helps reduce WA's. It's not that hard to do this because Python has many tools like itertools and easy syntax for many stuff. When you find a small case, you can easily trace what's wrong.

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

As for Div1F2:

0) I assume that

$$$ \displaystyle [z^i] \sum_{k=1}^{n-1} F^k = [z^i] \frac{F}{1-F} - [z^i] \frac{F^{n-i+1}}{1-F}? $$$

(The formula in the editorial misses $$$F$$$ in the numerator in the first term on the right hand side?)

1) What is "Lagrange Inversion"? I've never heard about this, and wikipedia suggests this or this; both of them are said to be called "inversion formulas", but I'd guess the former somehow applies? How to apply it, then? I can't see how to get the equation just below "And from the Lagrange Inversion: (...)" from the one above.

2) How to even think about this solution? To me, it looks like magic or a bunch of random complicated transformations of a power series which suddenly stops at a formula that we can compute using FFT fairly easily. I can even trace the steps (apart from this Lagrange inversion I mentioned before) and verify they're roughly okay. But... I can't picture myself ever finding out I needed to follow exactly these steps, even if I spent a month on the problem -- even after having read the editorial. What should I do if I want to get some understanding on what happens here?

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

Can somebody help me figure out why my code for Div2C/Div1A fails test case 7?

Code

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

BlueSmoke In the editorial of D2E 2nd paragraph why is this the case when every grid is good then colour would never change please explain.

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

Unable to understand Div2-B problem someone please explain.

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

Can anyone please explain why my DFS solution for Div 2 B problem is giving WA?My submission- 79925444.BlueSmoke or DeadlyCritic Can u please help me debug this? I will be grateful. Thank you.

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

The solution for Div 2D(1B) fails for the following testcase:
n = 5, k = 1 and a=2,2,0,0,1
The answer should be no, but the given solution gives yes.
Am I missing something? @BlueSmoke?
[Edit : My bad, the answer should be yes only]

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

    first convert the leftmost 0 to 2 by taking first 3 numbers, then convert the second 0 to 2 too. After 2 conversions you get:-

    22001->22201->22221

    Now start converting the 2's to 1 by taking one at a time:-

    22221->22211->22111->21111->11111

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

The contest is very interesting,thanks for questions setters.I thinks the ideas of solving B problem is very great,I should make more effort in it.

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

Thanks for Codeforces, and I hope Codeforces will be better and better. Come on! (Sorry, I'm Chinese. So my English isn't very good.)

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

can someone explain the time complexity of the seconds solution of DIV2 C ( Orac and LCM problem )

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

I really like the problems <3

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

Anyone please explain div2.D. I didn't get the editorial explanation.

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

For Div1A/Div2C, why are we taking

ans=lcm(gcd(d1),gcd(d2)...gcd(dN))?

I am wondering why ans is not

ans=max(gcd(d1),gcd(d2)...gcd(dN))?

Since our requirement is that the ans should divide N-1 integers of a,

could someone please tell why the 2nd answer is wrong?

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

    Hey sanjay_thiru,

    I hope you understood the observation that is mentioned in the beginning of the editorial .

    Basically you are trying to find the lowest value to divide every distinct set of (n-1) numbers (distinct by index), So each of those values found will appear atleast once in every pair of numbers that we use LCM on.

    So in the LCM of all these pair of numbers , those calculated values will exist.

    And, since you have to find the GCD of all the pairs , it makes sense to take LCM of all the GCD(di), because we want the greatest value that divides all the LCM of pairs.

    Hence the conclusion.

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

Mathforces!!!!!

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

Best problem of math

C was easy use this properties

gcd(lcm(a,b),lcm(a,c),lcm(a,d)) = lcm(a,gcd(b,c,d))

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

I am not able to figure out what's wrong with my solution of Div2D (https://codeforces.me/contest/1350/submission/79941143). Can anyone, please help me in coming up with a small test case where my solution will fail.

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

For Div2B, I tried simple DFS : 79945578.

Although my code successfully passed, I'm struggling to grasp why this approach is okay.

Anyone can calculate and explain time complexity of this solution?

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

whats the problem with my code in div2 B. It gave me tle although i used same approach as in editorial. Only difference is that i used memoization while applying dp link to my submission: https://codeforces.me/contest/1350/submission/79881782

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

Can anyone please check my Div2 C code: https://codeforces.me/contest/1350/submission/79873786

It gave me the memory limit exceeded error. Need help in figuring out the correct answer. Please share the relevant concepts that I didn't use here.

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

In Div1C, why are grid cell's (i, j) termed as "grid"?

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

Can anyone can prove this : $$$gcd$$$ $$$of$$$ $$$sequence$$$ $$$lcm(x , ai)$$$ = $$$lcm(x$$$ , $$$gcd$$$ $$$of$$$ $$$sequence$$$ $$$ai$$$) , $$$i = 1, 2, .. n$$$ and $$$x$$$ $$$is$$$ $$$some$$$ $$$integer$$$

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

video editorial for B and C

https://codeforces.me/blog/entry/77306

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

Thanx, DeadlyCritic for reaching out to each possible comment. Just can't get why my solution is getting TLE which is similar to this one. Can you help?

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

Hi, I've been trying to debug my code for Div2 C, I think my code follows the solution #2 described in the editorial, but somehow I keep getting wrong answer on test 4, can anyone please explain where the mistake is?? Thanks in advance My submission

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

In case anyone is still stuck detail explanation of C and B

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

MikeMirzayanov Hi, I think offical submission 79869658 by chenjy2021 and submission 79869030 by Bazoka13 are almost the same.It may break the rules of contest, which helps them both become Candidate master.

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

    Hello, I'm very angry about what you said. It's a kind of stigma. My idea of question D is as follows: suppose a interval has a number other than k, then if there is a [i] > = K and a [i + 1] > = k|a [i + 2] > = k, we must be able to yes why? If a [i] a [i + 1] satisfies the condition, then it can make its left or right side expand to the number of > = k until it reaches the value of K. at this time, the number adjacent to K is > = K. according to the meaning of the question (2 + 1) / 2, the interval is assimilated to K no matter how

    It's the same way to assimilate a [i] a [i + 2] step by step. He can certainly make [I, I + 2] become a number > = k, because (3 + 1) / 2 = 2 even if a [i + 1] is the smallest in this range, it will not be changed by him. So there are 1.6W participants in this competition. Is there 1.6W talents in each problem solution that can not be judged as cheating? Funny. I believe that everyone who answers the D question correctly uses the same method as me

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

    To sum up, question D is just like the 1 + 1 = 2 you did in primary school. Is there any other solution to 1 + 1 = 2? Is the 1 + 1 = 2 written by primary school students in an examination room cheating? Fuck you

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

Can someone tell me whats wrong in this solution 79969659 This is for div 2 C.. giving wrong answer on test case 9.. but when I copy the testcase 9 and run it ..it gives correct answer..How?

Test case 9

2

199999 200000

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

Let's make Div2D/Div1B a little interesting. If only those subsegments could be transformed whose median is k, how would you approach the problem?

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

Can someone please explain the difference between $$$\displaystyle E_x$$$ and $$$\displaystyle E_{x}^{'}$$$ in Div1D editorial ?

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

Hey, here is my submission of Div1-C https://codeforces.me/problemset/submission/1349/79994169 I used the same logic as in editorial but using DP. It gave WA on 6th testcase and I am not able to figure the error, can anyone help?

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

How do i optimize the memory for Div 2E, I'm getting a MLE on test 8. 80013481 is my solution.

Thanks. UPD — I'm sorry, I changed the submission ID

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

i kept on MLEing for problem C, although I had the right idea the whole time (i think I did solution 2). What can you use to calculate the number of pairs besides stuff like maps and arraylists, which MLE? Is there a way to do it in o(1) space? I literally spent 1h30m trying to implement this goddamn problem and I don't think I've ever been more tilted at a codeforces problem than this onehttps://codeforces.me/contest/1350/submission/80029151

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

Can anyone please explain How exactly to use BFS in Div2E / Div1C ?

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

What is s.t in the editorial for div 1 Problem 2?

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

What was the significance of the "unusual memory limits" for Div 1. C? I solved it without really accommodating for it, what solutions was it intending to block?

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

Sorry for asking this too late , but it will be helpful if someone can explain that what exactly "C" is in the problem div1-D editorial. From what i understood by reading editorial is that it is the expected time for a case where my all items belong to just one person "i" and now i want them to be owned by another person "j". If my interpretation is right then please do tell me how can i calculate this value? Also if this requires some deep knowledge of some concept of probability then please list them so that i can read about them in detail.

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

I'm not sure, that I understand Div1F1 solution correct. Am I right, that you use '>' and '<' signs between $$$a_i$$$ and $$$a_{i+1}$$$ if $$$a_{i+1} \gt a_i$$$ and $$$a_{i+1} \lt a_i$$$ respectively? And what does it mean, that we can combine places next to '<' sign?

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

What does s or t represent in div1 B editorial? BlueSmoke

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

In DIV1 C if we apply BFS on every good cell to find shortest time for all bad cells to become good cell, time complexity will be O((nm)**2) right ? Then how it will be a valid solution ? Or is there anything I'm missing such that BFS can be done better than that ?

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

editorial for div2C / div1A better than that.

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

DIV2 D/DIV1 B was brilliant, I understood the proof but it would be great if you could tell how you landed on the statement in the first place.

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

Easy to understand Tutorial for C intended for beginners.

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

For the problem 1349A - Orac and LCM we can use the fact that gcd( lcm(A,B) , lcm(A,C) )= lcm( A , gcd(B,C) ).

This is my code and I found it much easier than that in editorial. 115996653

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

please explain the meaning of DP stasuses?

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

The problem C can be solved in $$$O(n + \log(max(a))$$$ time and $$$O(1)$$$ memory

We have the observation that

$$$\begin{cases} lcm[a, gcd(b, c)] = gcd(lcm[a, b], lcm[a, c]) \\ gcd(a, lcm[b, c]) = lcm[gcd(a, b), gcd(a, c)] \\ \end{cases}$$$

So if we define $$$g[x] = \underset{[0, x]}{gcd}(a[i])$$$ and $$$g[0] = 0$$$

Then we have $$$res = \underset{x=1..n}{gcd}(lcm(a_x, a_y) \mid y \lt x) = \underset{x=1..n}{gcd}(\ lcm[a_x, gcd(a_1, a_2, \dots, a_y)]\ ) = \underset{x=1..n}{gcd}\left( a_x \times \frac{gcd(a_1, a_2, \dots, a_{y-1})}{gcd(a_1, a_2, \dots, a_y)}\right) = \underset{x=1..n}{gcd}\left(a[x] \times \frac{g[x-1]}{g[x]}\right)$$$

Since the $$$gcd$$$ will be reduced for each $$$a_x$$$ we pass, it would only cost $$$O(\log max(a))$$$ independently

So the total complexity is $$$O(n + \log max(a))$$$ time

For $$$O(1)$$$ space you can solve it onlinely

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

Can anybody help me understand why my code is failing on test 10 for Div2 D ??

Link of submission : https://codeforces.me/contest/1350/submission/193507755

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

For problem A div 1 orac and lcm , I got the solution 1 alone and AC but for solution 2 , how did they calculate its' complexity ?

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

Here is an another approach from Div1 problem A you can see my code it is pretty simple it just use factorization and then we know gcd is the common number which is present in all the element and which has the lowest power.

n = int(input())
a = list(map(int, input().split()))

def f(x, cnt):
    l, f, s = hashMap.get(x, (0, float('inf'), float('inf')))
    l += 1
    if cnt < f:
        s = f
        f = cnt
    else: s = min(s, cnt)
    hashMap[x] = (l, f, s)

hashMap = {}

for i in range(n):
    val, x = a[i], 2
    while x*x <= val:
        valid, cnt = False, 0
        if val%x == 0:
            valid = True
        while val%x == 0:
            cnt += 1
            val = val//x
        if valid: f(x, cnt)
        x += 1
    if val!=1:
        f(val, 1)

gcd = 1
for key in hashMap.keys():
    l, f, s = hashMap[key]
    if l < n-1: continue
    if l == n-1:
        gcd *= pow(key, f)
    else:
        gcd *= pow(key, s)

print(gcd)