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

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

Hello, Codeforces!

I am glad to invite everyone to participate in Codeforces Round #837 (Div. 2) , which will be held on Dec/11/2022 18:35 (Moscow time)

Please note the unusual time!

The round will be rated for participants of Division 2 with a rating lower than 2100. Division 1 participants can participate unofficially in the round.

You will be given 6 problems and 2 hours to solve them. This round was prepared by me and 4qqqq.

I'd especially like to thank:

This is my first official round on Codeforces. We are sincerely looking forward to your participation. We hope everyone will enjoy it.

The score distribution : 500 — 1000 — 1750 — 2250 — 2750 — 3500

We wish you good luck and high rating!

UPD1: We know about problem with C task. Now we are trying to fix it.

Editorial.

  • Проголосовать: нравится
  • -547
  • Проголосовать: не нравится

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

waiting for the round.

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

Egyptian Russian alliance. Hope it's gonna be a great round!

But where is "As a tester,...." comments XD

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

WOW .. Egyptian round . Good luck bro

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

As a division 5 participant, I can participate unofficially in the round.

Hope you'll prepare more interesting rounds.

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

 CAN ANYONE RELATE ;)

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

After a long time. Best of luck Everyone.

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

It's a long time for an Egyptian round ..

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

No interactive problems?

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

After a long time, 7 contests in 9 days. Great!

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

finally a contest

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

This is the most anticipated contest for me, keep up _HossamYehia_ :DDD

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

Morocco famous win and now Egyptian contest... African vibes coming

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

I am best

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

The contest will start at 23:35 in China:(

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

If I'm beginning in programming. Should I participate or it will be too difficult for me?

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

Can't wait to see wangzheng2008's performance.

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

I hope this African Round is as good as they are performing in FIFA World Cup with Morocco.

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

Hope to become pharaon this round

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

Codepairses

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

Why does this feel like a Div 1 round or maybe it's just tough for me.

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

E has a strong ROI 2015 in Arkhangelsk problem 6 vibe

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

Bloody Hell. What a pairful round!

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

let me guess, you forced online version of F because $$$O(mlog^2n)$$$ parallel_bs + BIT is faster than $$$O(mlogn)$$$ persistent_tree? :D

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

Why only 1 second limit for problem D? Java barely passes after optimizations & 3 TLEs...

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

    Cuz why not ?

    My solution had a complexity of $$$\mathcal{O}(n^2\log{n})$$$, using LCA and dp.

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

      Because it screws Java users... My solution is O(n^2) and it might fail on system tests.

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

      My n^2 solution for D runs very slowly, can you tell why

      #pragma GCC optimize("unroll-loops")
      #pragma GCC optimize("O3")
      #pragma GCC target("avx2")
      #include <bits/stdc++.h>
      #include <iostream>
      #include <fstream>
      #define ll long long
      #define mod 998244353
      #define mod1 998244353
      #define PI 3.14159265359
      using namespace std;
      vector<vector<int>>adj;
      vector<vector<int>>dp;
      vector<vector<vector<int>>>paths;
      void dfs(int v,int par, int vert, int startv, int&len)
      {
         
          len++;   
          if(len>2)
          {
              paths[len].push_back({startv,vert,par,v});
          }
          for(auto it:adj[v])
          {
              if(it==par)
                  continue;
              dfs(it,v,vert,startv,len);
          }
          len--;
      }
      
      int main()
      {
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);
          cout.tie(NULL);
          cout<<fixed<<setprecision(12);
          cerr<<fixed<<setprecision(5);
          // SieveOfEratosthenes(1000000);
          int t=1;
          cin>>t;   
          int tx = t;
          
          while(t--)
          {
           int n;
           cin>>n;
           adj.clear();
           paths.clear();
           dp.clear();
           adj.resize(n+1);
           dp.resize(n+1,vector<int>(n+1));
           paths.resize(n+1);
           
           string vals;
           cin>>vals;
           
           int i;
           
           int ans = 1;
           for(i=1;i<=n;i++)
           {
              dp[i][i]=1;
           }
           for(i=1;i<=n-1;i++)
           {
              int a,b;
              cin>>a>>b;
              adj[a].push_back(b);
              adj[b].push_back(a);
              if(vals[a-1]==vals[b-1])
              {
                  dp[a][b]=dp[b][a]=2;
                  ans =2;
              }
              else 
              {
                  dp[a][b]=dp[b][a]=1;
              }
           }
           
           for(i=1;i<=n;i++)
           {
              for(auto it:adj[i])
              {
                  int len=1;
                  dfs(it,i,it,i,len);
              }
           }
           int cnt=0;
           for(i=3;i<=n;i++)
           {
              for(auto &it:paths[i])
              {
                  int lef = it[0];
                  int ri = it[3];
                  int l1 = it[1];
                  int r1 = it[2];
                  if(vals[lef-1]==vals[ri-1])
                  {
                      dp[lef][ri]=dp[l1][r1]+2;
                  }
                  dp[lef][ri]=max(dp[lef][ri],dp[lef][r1]);
                  dp[lef][ri]=max(dp[lef][ri],dp[l1][ri]);
                  ans = max(ans,dp[lef][ri]);
              }
           }
           cout<<ans<<"\n";
      
          }
           return 0;
      }
      
»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve B?

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

    I will try my best to explain what I did, So a few observations first, The permutation is 1,2,3,4....n 1) Number of subsequences starting from 'i' are n-i+1.

    2) If we have a pair (1,2) that means that it includes all pairs (1,2),(1,3),(1,4)...(1,n) are included in it (because if we take any pair they will have (1,2) always). So if we have 2 inputs given as (1,2) and (1,4) so we can ignore (1,4) and take only (1,2) in consideration for calculation.

    3) Now take a case like this we have only (2,3) as the pair, So when we consider subsequences starting from 1, They are: {[1],[1,2],[1,2,3],[1,2,3,4]}. Now as we have (2,3) as a pair we have to stop before 3. So we have to consider the effects of the number after 1 to get its stopping point.(once read code comments to be more clear)

    4) if we only consider the pair (1,4), lets say n is 5. so the possible subsequences are 1,{1,2}, {1,2,3} == 4-1 {or b-a for a pair (a,b)}

    Code With comments

    Spoiler

    Sorry If I complicated in explaining something.

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

    Some observations:

    • If $$$[a, b]$$$ is a good subsegment, then all subsegments of $$$[a, b]$$$ are also good subsegments.
    • If the non-friend list contains a pair $$$(a, b)$$$, then any good subsegment that contains $$$a$$$ will not contain $$$b$$$.
    • If $$$[a + 1, b]$$$ is not a good subsegment, then $$$[a, b]$$$ is not a good subsegment.
    • If $$$[a + 1, b]$$$ is a good subsegment, and $$$a$$$ is friends with all $$$x$$$ satisfying $$$a \lt x \leq b$$$, then $$$[a, b]$$$ is also a good subsegment.
    • If the largest good subsegment that begins with $$$a$$$ is $$$[a, b]$$$, then there are exactly $$$b - a + 1$$$ good subsegments that begin with $$$a$$$ (all prefixes of $$$[a, b]$$$).

    Individually, these observations should be obvious, but this leads to the following solution:

    • First, for each person $$$i$$$, find the earliest person after $$$i$$$ who is not friends with $$$i$$$, i.e., find the number $$$j$$$ such that $$$i$$$ is friends with everyone in the interval $$$(i, j)$$$ but $$$i$$$ is not friends with $$$j$$$.
      • We can prepare this by simply maintaining a 1D vector nextstranger, such that when we read a non-friend pair $$$a, b$$$ with $$$a \lt b$$$, we set nextstranger[a] = min (next_stranger[a], b).
    • Suppose we know that the largest good subsegment that begins with $$$a + 1$$$ is $$$[a + 1, b]$$$. If $$$a$$$ is friends with everybody in the range $$$(a, b)$$$, then the largest good subsegment that begins with $$$a$$$ is $$$[a, b]$$$ (cannot extend to $$$b + 1$$$ because there must be somebody within that that doesn't know $$$b + 1$$$). But if there is at least one person that $$$a$$$ is not friends with in the range $$$[a + 1, b]$$$, then the largest good subsegment that begins with $$$a$$$ is $$$[a, nextstranger[a] - 1]$$$, since $$$a$$$ knows everyone afterwards up until nextstranger[a].
      • In other words, the largest good subsegment that begins with $$$a$$$ is $$$[a, \min (b, nextstranger[a] - 1)]$$$.
    • If we now iterate $$$i$$$ from $$$n$$$ to $$$1$$$ (descending order), we can now find the largest good subsegment that begins with $$$i$$$. The base-case is when $$$i = n$$$, where the largest good subsegment is obviously $$$[n, n]$$$.

    My submission: 184766262

    I used non to refer to nextstranger and cut to represent the person right after the longest good subsegment ends, i.e., for a given value of $$$i$$$, cut becomes the minimum of nextstranger[i] and the previous cut (i.e. the cutoff point for the largest good subsegment that begins at $$$i + 1$$$).

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

      can you please explain the variable cut? I couldn't understand it clearly.

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

        When considering the largest good subsegment that begins with $$$a$$$, the variable cut represents the cutoff point, i.e., the largest good subsegment that begins with $$$a$$$ is $$$[a, cut - 1]$$$ and it has length $$$(cut - a)$$$.

        How do we calculate the current value of $$$cut$$$? Let $$$cut'$$$ represent the cutoff point for the largest good subsegment that begins with $$$a + 1$$$, i.e. the subsegment is $$$[a + 1, cut' - 1]$$$. Now, if $$$a$$$ knows everybody in the range $$$[a + 1, cut' - 1]$$$, then $$$cut = cut'$$$. But if not, then we should set $$$cut$$$ to be the first person in this range that $$$a$$$ does not know (which we already calculated as $$$non[a]$$$). We can cover both of these cases by simply setting $$$cut = \min (cut', non[a])$$$.

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

Worst contest of my life, i hate it :( T_T

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

Really upset about problem C. I had a beautiful Python/PyPy solution but it kept timing out on pretest 3 :/

import math

for _ in range(int(input())):
    input()
    a = list(map(int, input().split()))

    # https://cs.stackexchange.com/questions/93030/
    if math.lcm(*a) == math.prod(a):
        print("NO")
    else:
        print("YES")
»
4 года назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

How was the round? I personally found it a bit hard.

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

Is there eratosphen's sieve solution of C?

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

Why am i getting TLE. What's the time complexity of my code. Please tell.

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

    If $$$n$$$ is a large prime or a product of two primes $$$p, q$$$ such that $$$|p-q|$$$ is small, your factorization algorithm degenerates into $$$O(\sqrt{n})$$$ which is unable to pass.

    I am so dumb that I have to nuke it with the Pollard Rho algorithm after failing 7 times, sigh~. Look my submission 184795924 when available.

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

Tfw you nuke C with Pollard's rho algorithm and Miller-Rabin because you're too stupid to solve it normally. :cry:

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

    Not sure of system tests though but the basic solution passed.

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

I feel in B, i'm trying to solve B in div1.

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

You need to fix your contest i guess? :)

https://codeforces.me/contest/1771/submission/184796886

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

Problem B was stolen from 652C - Foe Pairs

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

Probably the worst contest I've ever seen.

Glanced at all problems and know how to solve them in one minute with no any interesting points.

C: know how to factorize large numbers with pollard or things?

D: very obvious and classical dp from one dimension to tree. though I dont know what's wrong with my code.

E: standard dp -- crafting the largest H C F O I D ....

F: also very standard online ds problem. I didnt get time to solve it bcz of D.

Also A and B is very terrible. It's not beginner friendly and it introduces some tricky cases to let many newbies to fail.

I can't remember the last contest with such bad quality was — I assume it should be on 2015 or before. Anyway I did not AK this contest but I got a very bad impression on the whole problemset. That's it.

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

Not bad for today! Thanks _HossamYehia_!!

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

How to do C? :(

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

Contests like these always bring my little bit hope left down, i just don't know what to say.. feeling so sad right now

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

Why this solution (184800271) for C gives WA???

I am generating all prime numbers up to $$$\sqrt{10^9}$$$ because if $$$xy=z$$$ then $$$min(x,y)\leq{\sqrt{z}}$$$.

Then I am looking for two multiples of every prime number generated.

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

If only F were 512MB instead of 256MB. I'm depressed... My solution using sqrt decomposition.

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

    can u explain ur sqrt decomposition logic ?

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

    I managed to write a solution using sqrt decomposition that passes, but just barely. I had to implement range paint using a vEB tree instead of DSU (which turned out to have a better constant factor than making the log log n faster than the inverse_ackermann n for this problem).

    Explanation of the solution: Divide the array into B blocks. Then process each block individually like this: Look at each value that occurs in the array, but not in the block. Assume the left bound of some query is inside the block, and the right bound is outside the block. Then if the answer is a value that isn't in the block, it must occur an odd number of times outside the block. And which is the smallest of these for a given right bound does not depend on the left bound, since the left bound is inside the block, and the block doesn't contain the value. So by range-"painting" values you can compute the answer for every right bound, assuming the left bound is inside the block and that the answer is not a value inside the block. Range painting can be done in O(n log log n) with good constant factor using a vEB tree.

    Then to answer a query, you can look only at the block corresponding to the left bound of the query. Brute force count how many occurrences there are in the range of each value that appears in the block. There are n / B values in the block, so this can be done in O(n / B * log n) time by binary searching in arrays of positions of occurrences.

    Then take the minimum of this answer and the pre-computed answer for the right bound in the block.

    Total running time is O(qn / B * log n + Bn log log n). Code: 184822603

    Had to steal some fast IO from nor and vEB tree from mango lassi and nor to make it pass.

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

It was hard :D

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

Entire contest I was searching for some efficient solution of C, at last tried brute force and it worked. Do the brute force really for C or am I gonna get FST?

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

Weird round. D was easier than C ;_;

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

It's midnight in most of Asia and I'm regretting my sleep.

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

problem a is just same as https://codeforces.me/contest/459/problem/B but with *2

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

When approaching problem A, if the maximum and minimum values were different, i multiplied the number of maximum and the number of minimum and multiplied by 2, and if the same, i gave n * (n — 1). Why is A wrong? https://codeforces.me/contest/1771/submission/184799055

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

C is way too standard, but its hard to optimise your solution

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

For A if the smallest number != largest number the number of occurrence of the smallest element * the number of occurrence of the largest element * 2 ;

else if all elements are same nC2 . why won't this work .

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

I feel that constraints on problem C should have been either tighter or looser because solutions using Sieve and then factorizing each number using a list of primes and storing number of occurrences of each factor are barely passing and even failing for a few submissions depending on how the code has been written, which isn't fair to everyone

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

please tell the idea of C .. I thought sieve will simply give TLE so gave up that idea ...

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

C easy than A

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

Porblem C explain ... Basically How to find prime factors of a number<=1e9 in log(n)?? help....

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

How to do D ꒦ິ^꒦ິ

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

https://codeforces.me/contest/1771/submission/184787882

Anyone knows why is this wrong at pretest 3? Idea: Check all routes from one leaf to another. I could understand this getting TLE'd, but not WA

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

Constraints on C in fact very tough. It is easy to notice that there is $$$P=3500+-$$$ primes up to $$$\sqrt{10^9}$$$. But I think a bunch of people thought that $$$O(n*P)$$$ would get tle. moreover, we have some sets or hashtables that also affect the time complexity. Also, $$$O(n*P)$$$ theoretically should get tle

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

Oh, in problem D, my solution works for $$$n^2\cdot26$$$, I thought it would pass, The asymptotics match, after all.

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

For D, I tried finding the longest palindromic subsequence for each leaf-to-leaf path.

Is this approach wrong, and if so could someone please explain why :3

My submission: https://codeforces.me/contest/1771/submission/184793847

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

What is the intended solution to C?

Is it the $$$O(n \cdot \pi(\sqrt{a_i}))$$$ solution? (where $$$\pi(x)$$$ is the number of primes less than $$$x$$$) I was hesitant to submit it for some time since ~4e8 ops in 3s felt risky.

Also, I don't know if I'm just being dumb, but in E why can't we just try all horizontal parts in $$$O(n \cdot m^2)$$$ and for each check the longest possible vertical segment in O(1)?

By "check the longest possible vertical segment in O(1)" I mean:

  • Store first bad above / below each point.
  • Store first and second medium above / below each point.
  • Use the above two to compute how far we can extend each part (top left, bottom left, top right, bottom right).
  • If we haven't used the medium in the horizontal segment, try it in all 4 parts (using second med above / below) and take the max of all.
»
4 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Never felt so frustrated... Thank you! :|

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

As a participant, C and D were complete garbage

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

hey can someone tell me why this gives tle:

https://codeforces.me/contest/1771/submission/184791207 i know its o(n * sqrt(N))) where N = 1e9 but what is the diffrent between this and the prime factorization approach since its also suppose to be the same complexity

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

An unpleasant contest, a lot of newcomers fell for int in A, solutions on the verge of TL in C and D. When I was taught to do contests, they said it was not good to catch a constant or log, because there would be those who wrote a sloppy correct solution, but would not be able to pass it.

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

What is wrong with my A task submission ?

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

Hi!! can anyone tell where can i find the editorial??

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

what is wrong with this problem B submission 184799218

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

I'm unable to find out why this code fails for pretest 3 for A. please help me

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n, a=1, b=1;
        cin>>n;
        int x[n];
        for(int j=0;j<n;j++){
            cin>>x[j];
        }
        sort(x,x+n);
        for(int i=0;i<n;i++){
            if(x[i]==x[i+1])a++;
            else break;
        }
        for(int i=n-1;i>0;i--){
            if(x[i]==x[i-1])b++;
            else break;
        }
        if(a==n || b==n)cout<<n*(n-1)<<"\n";
        else cout<<a*b*2<<"\n";
    }
    return 0;
}
»
4 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится +1 Проголосовать: не нравится

EDIT: I'm sorry, this idea won't work, since it should trigger integer overflow. It passed pretests though, but will likely FST. This is what I wrote, if anyone is interested (but it is not supposed to pass):

C does not need a sieve or anything more complicated than Euclid's GCD algorithm.

All you need to do is maintain a running LCM. Initially, the running LCM is just the first element of the array. Check the GCD of the running LCM and the next value. If the GCD is not 1, then there must be an overlapping factor between this next value and one of the earlier values (doesn't matter which), so the output is YES. Otherwise, update the running LCM (by multiplying the current running LCM with this next element that we just found to be coprime to it) and move on. If we read the entire array, and the GCD was always 1, then the output is NO.

My submission: 184790195

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

My solution for A has fallen in the system test because i forgot to print a new line in in the case when all array is equal , i hope you can skip this mistake as it is a presentation error and it is also not included in the pretests , i was about to get back to specialist and i hope you MikeMirzayanov can consider it correct.

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

Fuck so close to solving D. It’s just going level by level and do DP.

no idea how to solve C.

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

    You just need to know that there are O(sqrt(M) / log(M)) primes from 1 to M. Then You can just check, if there are 2 numbers that both divide a prime below sqrt(10^9) ~= 35000. Also you should divide each number on all primes below sqrt(10^9). Then you'll have either 1 or a big prime. Then check if there are 2 primes.

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

What is idea for D, i know solution dp n^2 for 1d array with size n and that solution must be between 2 leaves in tree but thats it.

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

Pretests were comparable to a steaming pile of shite

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

Wow!! what this pretests. Screenshot-2022-12-11-201844

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

.

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

WTF was C?

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

I FSTed C 184739561 on test 16. I typoed and only factorized out 2 and 3. This passes 15 tests...

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

184778086 is not correct

184778210 also

184766650 also

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

Problem F is a specialization of 1479D - Странный источник минералов. (Technically, that problem doesn't ask for the minimum value but most solutions for that problem will find the minimum anyway.)

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

    In Odd Mineral Resource the queries are not online so parallel binary search + sweepline fenwick tree can be used, but in problem F a persistent segment tree is required. The two problems are still really similarly though

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

Weak pretest.

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

:)

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

I'm just much surprised that how my solution for problem C got accepted in system testing (It shows that main tests are really weak), can anyone hack it? 184797036

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

Can this idea work or is just way too slow even with a better implementation? (Problem C):

https://codeforces.me/contest/1771/submission/184805467

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

Very weak pretests for $$$C$$$.

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

What is wrong with my solution of A? It fails on 24th test. 184739221

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

Got TL on F in system tests. Replaced map with unordered_map, got at least 10x speed-up on test 30: before that I was getting TL on test 30, but with unordered_map it works under 150 ms. It was log(N) per query anyway, and I was still using std::map O(N) times, but changing coordinate compression container to unordered_map somehow miraculously sped up the program. Just wondering, is it okay that such a small change caused that much performance loss?

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

how to solve F?

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

    Main idea is that if you take xor of numbers, numbers that will appear even number of times will cancel out from xor. To find smallest odd appearing number you can just binary search for minimal i that xor of numbers less or equal than i is > 0, with segment tree. To answer queries in a segment, you can use persistent segment tree. There are also cases when xor of numbers is zero (like 1, 2, 3) but there are numbers that appear odd number of times, but it can be fixed with just mapping numbers to random 64bit numbers, and the probability of xor being zero will be very low (don't know how to prove it).

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

      wow that's why there was mt19937 in accepted codes. thank you

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

      Here is the proof of probability of two randomly chosen subset's xor being equal is very low.
      please let me know if anything is incorrect..
      Say there are k basis elements out of n elements in the array..
      claim: Then the probability of xor of two different subset being equal is ~ $$$1/2^k$$$..
      (note that k can be atmost 64)

      Assume that, for first 64 numbers of array, we map them all to two powers(eg 1,2,4,8,....)...resulting in first 64 number being linearly independent to each other(ie: any of them cant be represented as xor subset of other)... and all further numbers(i>64) can always be represented as linear combination of first 64 numbers(ie: as some xor subset)...

      Directly to the proof: There are total $$$2^n$$$ subsets possible..
      Thus N = $$$2^n*(2^n-1)$$$ pairs of subset..
      Let Z be number of pairs of subsets with equal xor..
      claim: Z = $$$2^n*(2^{n-k}-1)$$$
      proof:
      1. There are $$$2^k$$$ unique xor values out of $$$2^n$$$ subsets xors.
      2. In that, each unique value is repeated exactly $$$2^{n-k}$$$ times..
      refer: https://stackoverflow.com/a/72195021/15971867

      \begin{Bmatrix} x_1 & x_1 & x_1 & \cdots & x_1 \cr x_2 & x_2 & x_2 & \cdots & x_2 \cr x_3 & x_3 & x_3 & \cdots & x_3 \cr \vdots & \ddots & \ddots & \ddots & \vdots \cr x_{2^k} & x_{2^k} & x_{2^k} & \cdots & x_{2^k} \cr \end{Bmatrix}

      Thus number of ways in choosing pair of subset such that their xor are equal, is number of ways choosing two different subset along same row in above matrix...
      (note that here each xi is the subset(xor-ed).)

      There are $$$2^{n-k}$$$ elements in each row..
      thus there are $$$2^{n-k}*(2^{n-k}-1)$$$ such pairs in each row, and there are $$$2^k$$$ rows, hence $$$2^k*2^{n-k}*(2^{n-k}-1)$$$ pairs total..

      So, probability of choosing pair of subset with equal xor value is
      P = Z/N = $$$\frac{2^n*(2^{n-k}-1)}{2^n*(2^n-1)}$$$
      ~= $$$2^{-k}$$$
      which is very low for k = 50..

      Note that, it seems even if we take all numbers as random from the beginning, still it works..
      So, for upto n<=64, if we choose n random numbers, then there are high chance that all of them being independent..(I dont know to prove this.)

      upd: I have proved it here that If you generate some n random numbers, then atleast first 50 of them will be linearly independent of each other.. (atleast first m, with probability 2^m/2^64 in general.)

      Here is the modified jiangly's solution with first 64 numbers as two powers and remaining are just filled with unused natural numbers starting from $$$2^{25}+1$$$. (i=64 to n are then shuffled to avoid hacking) ref:https://codeforces.me/contest/1771/submission/184878249

      note: it is better to choose random number instead of continuous numbers, cause if you dont shuffle them, then xor of all numbers between 4k1+1(or 3) to 4k2+1(or 3) for any k1<k2 will be equal..
      Also even if you shuffle, the code is prone to hacking... for example, By looking at above accepted code, it is known that there exist {$$$2^{25}$$$,$$$1$$$,$$$2^{25+1}$$$} in the array, hence for n = 65, by just choosing all 65C3 combinations in each query, one can exploit this triplet.

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

Hi! We know about problem with C task. Now we are trying to fix it.

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

Not a good contest, The time limits are absurd. The problems are weird. I literally had my heart in my mouth while systests. I think either solution should pass with ok margin or tle in pretests. Staying on the border with dumb luck passing or failing solutions doesn't make much sense.

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

The rating for Codeforces Round #837 (Div. 2) will be rolled back until the end of the investigation of the incident with problem C.

What was the incident? Was there a problem with the tests or something?

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

Can anybody help me find out what's wrong in my solution to question A.Thanks in advance

https://codeforces.me/contest/1771/submission/184726214

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

Auto comment: topic has been updated by _HossamYehia_ (previous revision, new revision, compare).

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

Bruh

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

For me, this round was very unusual and tricky. The problems were challenging and hard, but the contest was good. Solved B and F, but not A, C, D or E. <3

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

Problem B is exact copy of this problem: https://codeforces.me/contest/652/problem/C

Make this contest unrated.

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

    Well, a lot of easy problems look same. There are not many ideas for div2A and div2B. And ofc the idea of problem B is well known. And if we made every round, where problem A or problem B is not 100% unique, unrated, there would be no rated contests

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

Put the damn editirial slready , pls

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

Dont know why people hating b imo b was very easy here is my submission link https://codeforces.me/contest/1771/submission/184805442

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

Have the ratings been finalised or still solutions are being rejudged?

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

problem D was easier than B in my opinion , i regret i didn't read it during the contest and kept trying to solve B

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

"I'd especially like to thank: MikeMirzayanov , for the amazing Codeforces and Polygon platforms."

Tbey are such amazing platforms that they even remind you (pretty adamantly) to tests the inputs for inconsistencies

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

i

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

Worst generator for C

By the way, it's harder to write the generator than to come up with this test. I think 256KB limit for the hack is sometimes tight.

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

I switched long long to int in problem C and it passed. :/

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

Can anyone help me with this or this submission where I got TLE for O(max(n,m)) complexity in problem B?

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

In problem C, I submitted the same code in pypy3 and pypy3 64bit but the code gave TLE in pypy3 64bit and AC in pypy3 .
- Is this a problem with pypy64 bit ? why this difference happened?

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

Unfortunately, it was found that the validator in the problem C allowed the case n = 1. We found all the participants whose result was affected by this issue (146 in total), for them the round will be unrated. For other participants, the round remains rated.

We apologize for this incident. :'(

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

I'm a little frustrated with problem A. I was stuck on this problem for over an hour. In the condition of the problem, 1<=n<=10^5, but the problem fails when n is an int number.

Some submission in during contest — https://codeforces.me/contest/1771/submission/184727850

Fixed (int to long long) — https://codeforces.me/contest/1771/submission/184836287

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

So C needs a precise execution time estimation (provided that we don't use advanced number theory algorithms).

Some discussions on Codeforces about the number of operations C++ can do per second:

Blog 1

Blog 2

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

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

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

how to solve problem c?

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

    just check, if there minimum 2 even numbers in the array. If so, then yes. Because a pair of even number has at least one common divisor which is 2.

    Otherwise you have check with prime factorization using sieve.

    Just store the primes factors of every element of the array in a map.

    Every time, before storing a factor, just check whether this factor stored before or not.

    If not found, then print No at the end.

    If needed you can check my solution : 184772682

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

      According to your explanation, wouldn't the time complexity be like n x |{Primes}|? What if n numbers are all large prime numbers? Could you elaborate on the time complexity aspect?

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

        Ok, it's a nice observation. But I think it will overcome this TL.

        If you search, you will get the large number that less then equal (1e9) is 999999937 (If I am not wrong). So if I want to store prime factors of this number, I need the primes which are less than equal sqrt(999999937) = 31622. There are only 3402 primes which are less than equal 31622 which I stored before using sieve.

        Now, if I want to store prime factors of a large number which is a large prime that less than equal 1e9, I need only 3402 times operations, according to my code.

        So, I need around (3402 * 1e5) operations. which will pass in 1s ig.

        I think, I answered your question. What do you think?

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

MikeMirzayanov, _HossamYehia_ My submission for yesterday's C problem got skipped due to an unknown reason and the contest got unrated for me. I don't think this is plagiarism but a glitch from your end. Kindly check and take suitable action.

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

Hi, For problem C, can't we apply the all possible pair using Merge Sort algorithm (an Nlog(N) approach), and subsequently finding the gcd of the pair formed during merge operation only? Handling the primary cases initially? `

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

why my rating is not updating? everyone's rating updated!!

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

are ratings updated yet?? It is showing me N/A. And why there is an * sign before my username in the standings??

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

Tutorial?

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

why am I unrated? it's weird.

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

Why there are so many downvotes?

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

Problem C should be renamed to Hossam and the Speed of Light. Anyone also agrees ?

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

I got TLE .But I don't know why ? Can anyone help me? Problem_C link:https://ide.geeksforgeeks.org/404239a0-839d-4ad7-93a1-d6e125512ec6

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

First rated contest, didnt suceed the first question ... i am software engineer, should i kill myself ?

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

    You definitely shouldn't. All of the problems in this contest were way too difficult for beginners (e.g. A had very annoying edge cases). You should just practice more and hope for better luck next time!

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

Can anyone explain how to solve problem F using persistent segment tree?

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

hard but not enough

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

Can a solution for problem C, based on factorising a number (upto 1E9) using pollard-rho be hacked? If yes kindly hack this solution. 184846090

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

This problem C got me thinking: why can't we factorize $$$n$$$ in $$$\sqrt[\leftroot{-2}\uproot{2}3]{n}$$$? My solution failed, so I must be wrong somewhere: 184828349

My idea was that we can iterate over all possible divisors of $$$n$$$ from $$$2$$$ to $$$10^3 + 5$$$. $$$n$$$ has $$$10^9$$$ ceiling so the largest divisor $$$p$$$ that we might have missed out on is less than $$$10^6$$$. Now, if $$$p$$$ is not a prime, then it means it has a divisor less or equal to $$$\sqrt{p}$$$, which is less than $$$1e3$$$, so we must have covered it before, while iterating over small divisors of $$$n$$$. Which means that $$$p$$$ is a prime and we successfully factorized $$$n$$$.

I tried running stress tests but it's very hard to generate a counter-example apparently, so I would appreciate some help here

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

Please don't downvote just because the pretests were weak. This round was very good, I really enjoyed thinking about D. Thanks to the problem setters.

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

When will the editorial get released??

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

Editorial?

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

will #837 be the first contest without editorial?

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

Can somebody give me an unofficial editorial? At least for the first 5 problems...

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

Editorial is quite late so anyone please help me how to solve problem D.

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

Can Somebody explain me the solution to problem d, using LCA and dp ! please help!

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

waiting for the editoral.....

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

Thanks for the fast editorial

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

Since the editorial is not out yet, I would like to provide hints for the problems and reviews which I have solved in contest:

A. Hossam and Combinatorics: Nice simple problem.

Hint 1:
Hint 2:

B. Hossam and Friends: Quite hard for it's place (or maybe I messed it up), but nice problem.

Hint 1:
Hint 2:

C. Hossam and Trainees: Nice problem, but I feel it a bit standard one.

Hint 1:
Hint 2:
Hint 3:

D. Hossam and (sub-)palindromic tree: Nice problem, I had fun solving it.

Hint 1:
Hint 2:
Hint 3:
Hint 4:

Kindly forgive me for any grammatical errors. Feel free to comment if you find anything wrong. Thanks!

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

Where is the editorial?