Kogut_Ivan's blog

By Kogut_Ivan, 13 months ago, translation, In English

We hope you enjoyed the contest! Thank you for participating! This is our first official round on Codeforces, so we would be happy to hear your feedback in the comments and in the mini-survey below.

How did you like the contest?
Which problems did you like (you can choose multiple)?
Which problems did you not like (you can choose multiple)?

2093A - Ideal Generator

Идея: EzikBro

Hint 1
Hint 2
Editorial
Solution

2093B - Expensive Number

Идея: gravitsapa

Hint 1
Hint 2
Hint 3
Editorial
Solution

2093C - Simple Repetition

Идея: pskobx

Hint 1
Hint 2
Hint 3
Editorial
Solution

2093D - Skibidi Table

Идея: fstilus

Hint
Editorial
Solution

2093E - Min Max MEX

Идея: Boodoochai

Hint 1
Hint 2
Editorial
Solution

2093F - Hackers and Neural Networks

Идея: _icy_

Hint 1
Hint 2
Hint 3
Hint 4
Editorial
Solution

2093G - Shorten the Array

Идея: EzikBro

Hint 1
Hint 2
Hint 3
Editorial
Solution
  • Vote: I like it
  • -22
  • Vote: I do not like it

| Write comment?
»
13 months ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

Are we just gonna ignore the hacks on E on n(logn)² solutions?

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Sadly

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    314556699 mine passes

  • »
    »
    13 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it -8 Vote: I do not like it

    But why is it not working as they have mentioned that the sum of n across all test cases does not exceed 2⋅105 . So, n(logn)2 ~ 6⋅107.

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it +8 Vote: I do not like it

      Mine passed with $$$O(n\times log^2(n))$$$, the set solution does not pass due to big constant factor.

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I think you mean $$$6 \cdot 10^7$$$, but note that set's constant factor is extremely huge.

      • »
        »
        »
        »
        13 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Is it the same for std::map as well?

        • »
          »
          »
          »
          »
          13 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          They should be almost identical.

          • »
            »
            »
            »
            »
            »
            13 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            map is probably twice slower

            • »
              »
              »
              »
              »
              »
              »
              13 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              Not really. The slow part of set and map is to manage the elements (which is the element itself for set, and the key for map) and they work the same way for both. The value of map is only an additional element attached to each node of the binary tree, which should take only trivial time.

              • »
                »
                »
                »
                »
                »
                »
                »
                13 months ago, hide # ^ |
                 
                Vote: I like it 0 Vote: I do not like it

                But my submission with std::map receive TLE,with std::set receive AC

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  13 months ago, hide # ^ |
                   
                  Vote: I like it 0 Vote: I do not like it

                  Your AC submission took 1968 ms, which is just 32 ms away from TLE. Execution time is unstable, so the same code can sometimes get just 1968 ms but far exceed 2000 ms, or just take 1800 ms depending on the server's condition.

                  There might be a tiny difference, but it should be really small.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  13 months ago, hide # ^ |
                   
                  Vote: I like it 0 Vote: I do not like it

                  You are right.During the writing of the code I was very confused about O(nlog2n) could AC. After submission I reacted that it would be better to use vector .But when I got Ac,I didn't pay attention to it again,I fst while some of my friend got ac with set,that would be a shame for me.

      • »
        »
        »
        »
        13 months ago, hide # ^ |
         
        Vote: I like it +2 Vote: I do not like it

        Mine passed within 1999ms, lol.

      • »
        »
        »
        »
        13 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Can you share some resources to learn more about set and unordered_set. I want to know how they work internally and understand the terms like "constant factor" and "collisions" like you mentioned.

        • »
          »
          »
          »
          »
          13 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          I don't specifically have good resources, but I can provide you some basic ideas and keywords to search for.

          set is typically (at least in GCC) implemented as Red–black tree. This is needed to ensure that every insertion / deletion / search takes $$$\mathcal{O}(\log{n})$$$ time no matter what operations are performed with any order. However, this effort to guarantee the time complexity involves "tree rotation" which changes the structure of the tree by moving around some nodes, and this means it has to deal with a lot of pointers and many random accesses happen, so these operations are "heavy" — in other words, its constant factor is huge.

          unordered_set is a simple hash table and in GCC it uses remainder of the keys as the index, it is very prone to hash collision without proper adjustment to the hash functions. You many want to read this and this to see how they are attacked.

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    mine passes , i used python sets

»
13 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

For problem F, can someone rewrite the problem statement in a simpler way?

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    You can perform two kinds of operations. Operation 2, i.e, replace any index (1 to n) with a blank is a definite operation, the hackers can choose the index to turn into a blank. However, for operation 1, you can only choose a neural network (1 to m), and any random BLANK index converts to its corresponding string.

    So, we first remove the randomness by choosing the vector with most commonality (comm) with target. So, we definitely have the correct elements in comm positions, if we choose the neural network n times, and definitely the wrong elements in n-com positions. Now, we use 2 operations per (n-com) positions to convert to blank, and then fill it with a string of our choice. Remember, its only random if there are multiple blanks.

»
13 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

D. In the fourth possible position, isn’t it y > 2^(n-1) instead of <?

»
13 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

bro on E, I did an n*log(n) solution and it got TLE, like tf??? 314610668, (in the contest it pased but in system testing it got TLE on test 32)

  • »
    »
    13 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it +16 Vote: I do not like it

    don't use unordered_map, it can be hack to $$$O(n)$$$

    also if you use map you will get TLE on test 16(guess why I know it!), in this problem you should use an array and only process the number which <= n

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I first tried using ordered set during virtal contest for tracking missing numbers, which was supposed to take an O(n log n) check, for overall time O(n*(log n)^2), but then I used bool array like the editorial, but only reached test 26.

      • »
        »
        »
        »
        13 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it +5 Vote: I do not like it

        As I know, $$$O(n\log^2n)$$$ algorithm can't pass this problem because map/set is VERY SLOW

        UPD: I check your code and found your rollback of array done is incorrect, you should only rollback the numbers you used(you can use a vector to storage the numbers that you used)

        • »
          »
          »
          »
          »
          13 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          Now, I tried the bool array like the editorial, passed only a LITTLE more tests, but still FAILED on test 26.

          • »
            »
            »
            »
            »
            »
            13 months ago, hide # ^ |
             
            Vote: I like it +1 Vote: I do not like it

            vector<bool> done(n+1, false);

            done[min(n+1, a[i])] = true;

            out of bounds

            • »
              »
              »
              »
              »
              »
              »
              13 months ago, hide # ^ |
               
              Vote: I like it +1 Vote: I do not like it

              also, never use vector<bool>. This may lead to some unexpected errors like:

              vector<bool> arr;
              // do something
              for (bool &x : arr) // compile error
              
            • »
              »
              »
              »
              »
              »
              »
              13 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              See the solution that failed test 26 which also uses a bool array. Can you give me a little modified version of my code that gets AC pls. One solution is still getting tested, but I pray that it gets through test 26 at least, if not AC.

              • »
                »
                »
                »
                »
                »
                »
                »
                13 months ago, hide # ^ |
                 
                Vote: I like it 0 Vote: I do not like it

                seems the newest version is right(I am not sure)

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  13 months ago, hide # ^ |
                   
                  Vote: I like it 0 Vote: I do not like it

                  AC. OMG! I'm so excited. Thank YOU SO MUCH for your efforts to help ME solve this HUGE persistent ISSUE. I love you.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  13 months ago, hide # ^ |
                   
                  Vote: I like it +9 Vote: I do not like it

                  You are too welcome :)

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  13 months ago, hide # ^ |
                  Rev. 2  
                  Vote: I like it +3 Vote: I do not like it

                  We'll give a huge shoutout to SYCu for the efforts of getting through huge roadblocks, analyzing every single line, and requesting changes to help me get AC. Real appreciation, helpful and good. So MANY TLE's later, YOU DID NOT GIVE UP! It took TWELVE submissions, just for ONE, SINGLE, problem.

        • »
          »
          »
          »
          »
          13 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          Nah, my code passed with O(N * (log(N) ^ 2)) time complexity

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      i think if we use unordered map and only process for numbers less than n it will still work though i am not certain about how collisions work in unordered map

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      While practicing on Codeforces, I usually prefer set/map over unordered_set/unordered_map, since they tend to perform better when there are many duplicates. But in this contest's E, although my solution got accepted during the contest, it got TLE on test 67 during system testing, possibly due to extra cases added during hacks. Surprisingly, after replacing set with unordered_set, it passed. I'm confused because I thought set/map handled duplicates better, so I'm not sure why unordered_set worked here. Could you help me please!

      • »
        »
        »
        »
        13 months ago, hide # ^ |
         
        Vote: I like it +6 Vote: I do not like it

        Unordered set/map is faster than ordered because of being unsorted. The reason they get TLE is due to collisions in hash value. This happens on very specific prime numbers. Since the constraints of the problem were low, it was very hard to produce such collisions. This is why unordered passed. A suggestion is that whenever you use unordered map/set, use a custom hash to avoid collisions

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Using unordered_map can make you TLE. While you can access in O(1), the rehash when collapse cost O(n)

  • »
    »
    13 months ago, hide # ^ |
    Rev. 5  
    Vote: I like it +4 Vote: I do not like it

    Careful $$$O(n\log^2n)$$$ implemetation is about 10x slower that vector but passes easily: 314616665. It doesn't matter ordered or unordered set, because inserted elements are fixed 0..x and cannot be crafted to break hash. Proof in cpp: 314732121

  • »
    »
    11 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    yes, the complexity may increase in some test cases in maps and sets , so what we can do here is , we can keep a check alternatively

    if(mid>2e5+1) return 0; (because any how no more than 2e5 elements can be there so we can eliminate large test cases(passed for me

»
13 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

I think the editorial is not in English.Anyone facing the same issue?

»
13 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can anyone help me out why my solution failed on E, isnt the time complexity is $$$O(n (\log n)^2)$$$ why would it fail? link

Also the editorial is not in english, please do the needful. Kogut_Ivan

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    https://en.cppreference.com/w/cpp/container/set/clear : Linear in the size of the container, i.e., the number of elements.

    So worst case complexity is when $$$k=\sqrt n$$$, $$$O(n^{3/2}\log n)$$$

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      thanks, much appreciated.

      • »
        »
        »
        »
        13 months ago, hide # ^ |
        Rev. 3  
        Vote: I like it +1 Vote: I do not like it

        Strange that it fails on test with k=1, but without clear its ok: 314738392. And unordered set is noticeably faster 314738680

        • »
          »
          »
          »
          »
          13 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          I don't know what to say. After 1h30min, I was close to a +100 delta. But F felt overwhelming due to the problem statement, and I couldn't solve G despite giving it my all. Now, having FSTed E, I just feel sad. I'll look into it, thanks a lot for your time and effort, it really means a lot.

          This was one of the best Div3 experiences I've had, even though the outcome wasn't in my favor.

»
13 months ago, hide # |
Rev. 5  
Vote: I like it 0 Vote: I do not like it

Can you please rejudge my solution for E, as some people's code is rejudged again after getting TLE initially, so please rejudge mine as I was at 500 rank before testing. Plsss!!!!

Example: https://ibb.co/jvZTtsT8 (Accepted) https://ibb.co/v44cYddP (TLE)

»
13 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Strange round, difficult D but easy enough E. Still thanks for the tasks and the new experience

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What is wrong in this submission ??

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone try uphacking my E? It passes in 1999ms

»
13 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Does E have any $$$O(N)$$$ solutions ? I thought about some greedy picking but the case

$$$n = 10$$$, $$$k = 3$$$

$$$a = 1, 0, 0, 1, 1, 1, 0, 0, 0, 2$$$

is a good counterexample.

»
13 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

Should we overlook the innovative approaches applied to E within n(log n)² solutions? These techniques merit a closer examination for their potential to optimize performance and address complex computational challenges effectively.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Just disappointed with the E verdict even after writing the solution for O(n log^2 n) time complexity.

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    As a rule of thumb, if you can optimize better always do, if you can use a visited array or a frequency array over set/map, always do.

»
13 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

Bad Problem Statement for F

»
13 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

For problem E, anyone who gets TLE because of using the unordered map could try using a custom hash. This code comes from here.

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

»
13 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

Are you sure you didn't reverse D-E-F?

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D. what number will be in the cell at the x-th row and y-th column;

x-th row and y-th column? blasphemy.

»
13 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

swap D and F please i started from F and then did E then moved to D and was flabbergasted and left the contest (because i was hungry also).

»
13 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can someone help me with my submission 314773349 for D ?

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hi, can anyone explain me why my code get TLE. Its $$$O(nlog(n))$$$ 314779695 not even $$$nlog^2$$$

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for G you can also do two pointers on a Trie

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Could you explain your approach?

    • »
      »
      »
      13 months ago, hide # ^ |
      Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      hopefully this explanation isn't so horrible:

      denote a set $$$S$$$, notice that $$$\max(a \circ b)$$$ for two elements $$$a, b \in S$$$ is increasing when we add elements to $$$S$$$ and decreasing when we remove elements.

      also given a set $$$S$$$ you can use a Trie to find an element $$$x \in S$$$ such that $$$a \circ x$$$ is maximized for a given $$$a$$$.

      this enables you to do two pointers, you move the right pointer if the greedy algorithm stated above returns $$$x$$$ such that $$$s_r \circ x \lt k$$$ and insert $$$s_r$$$ into to the Trie, else we remove $$$s_l$$$ and move the left pointer, the complexity sums up to $$$O(n \lg max(a_i))$$$ or $$$O(32 \cdot n)$$$

      not my code: 314691768

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

getting TLE in test case 4 in problem D with this recursive solution....can anyone help me


#include <bits/stdc++.h> using namespace std; long long solveCoords(int n, long long start,int row, int col, int& i, int& j,int len){ if(n==1){ if(row==i && col==j) return start; else if(row+1==i && col+1==j) return start+1; else if(row+1==i && col==j) return start+2; else return start+3; } long long total = len*len; long long subTotal = total/4; int x = len/2 -1; int y = len/2 -1; if(i<=row+x && j<=col+y) return solveCoords(n-1,start,row,col,i,j,len/2); x = len/2; y = len/2; if(i>=row+x && j>=col+y) return solveCoords(n-1,start+subTotal,row+x,col+y,i,j,len/2); x = len/2; y = len/2-1; if(i>=row+x && j<=col+y) return solveCoords(n-1,start+2*subTotal,row+x,col,i,j,len/2); x = len/2-1; y = len/2; if(i<=row+x && j>=col+y) return solveCoords(n-1,start + 3*subTotal,row,col+y,i,j,len/2); return -1; } pair<int,int> solveNum(int n, long long start, int row, int col, long long& d,int len){ if(n==1){ if(d==start) return {row,col}; else if(d==start+1) return {row+1,col+1}; else if(d==start+2) return {row+1,col}; else if(d==start+3) return {row,col+1}; } long long total = len*len; long long subTotal = total/4; if(d < start + subTotal) return solveNum(n-1, start, row, col, d, len/2); // Q0 else if(d < start + 2*subTotal) return solveNum(n-1, start + subTotal, row + len/2, col + len/2, d, len/2); // Q1 else if(d < start + 3*subTotal) return solveNum(n-1, start + 2*subTotal, row + len/2, col, d, len/2); // Q2 else return solveNum(n-1, start + 3*subTotal, row, col + len/2, d, len/2); // Q3 } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin>>t; for(int i=0;i<t;i++){ int n,q; cin>>n>>q; int len = 1<<n; for(int j=0;j<q;j++){ string s; cin>>s; if(s[0]=='-'){ int x,y; cin>>x>>y; int i = x-1; int j = y-1; cout<<solveCoords(n,1,0,0,i,j,len)<<endl; } else{ long long num=0; cin>>num; auto it = solveNum(n,1,0,0,num,len); cout<<it.first+1<<" "<<it.second+1<<endl; } } } }
  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    I looked into your code. The main issue was in how you calculated the quadrants—your offset logic wasn’t dividing the matrix correctly, which led to unnecessary recursive calls. Heres the fixed solution : 314840363.

    P.S. Try to use long long for every variable where large values are expected. Otherwise, always make sure to check whether a sum or product could exceed the int limit. Even if your logic was correct, you would have still received a penalty for calculating total = len * len, since len was an int.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

There's yet another "solution" for G: 314828750.

Why
»
13 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

This happened because SO many solutions used an unordered_map or unordered_set and they are very good targets to hack because normally they take $$$O(1)$$$ but in the hash collisions, they can take $$$O(n)$$$. So many people tried to hack these solutions and got successful, so AC solutions during the contest get TLE's when retested after hacks, even when your solution was not targetted. This is extremely disappointing for so many contestants who passed the pretests but after the hacking phase, boom! So many TLE's you can't imagine. I'm not lying, just go to HACKS then Successful hack. You will so many TLE hacks on just problem E. I first tried using normal set during a virtual contest for safety with bin-search 314714290, which was supposed to take $$$O(nlog^2n)$$$ and that is around $$$7 \times 10^7$$$ operations and pass, but I got TLE sadly. Then, I tried bool array like the editorial and after some time, I finally cracked it in $$$O(n log n)$$$ time in just 140 ms 314722830. I think you guys should use unordered maps or sets when and only when you are very sure about the hash collisions (even if pretests pass) and also, for safety, have a normal map or set solution, which are very unlikely to get hacked, unless the $$$log n$$$ factor is really bothering.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D is a great problem to learn recursion better.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I am having trouble finding the case of TLE in my code for problem G. Could anyone help me out?

314875046

Code
  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    I sorted the issue. Got to know that using objects(pointers) instead of flatenning the trie was the issue. Here's the corrected code if anyone wishes to see:

    Code
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My O(n lg n) solution is failing, is it due to my CP template?

»
13 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

Editorial for question C says "It is also possible to precompute prime numbers" but since the X was up to 10^9, precomputing and storing 10^9 values isn't possible, so how can that be done?

  • »
    »
    13 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    Maybe "precompute" is not the best word. They mean to manually check the repunit numbers (i.e. $$$1, 11,\ldots, 111111111$$$) and hardcode the solution.

    Fun fact, after $$$11$$$, the next repunit prime has 19 ones: https://oeis.org/A004023

  • »
    »
    13 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    You dont need to use Sieve of Eratosthenes, see here Sieve of Eratosthenes is used to find all the primes in a certain range but in this question you dont need all the primes in a range instead what you need is simply to find a certain number is prime or not

    for that you can iterate all the divisors till square root of the number and check if there is a divisor other than 1 and the number itself

    Here you can check this code

    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return true;
        }
    }
    return false;
    

    here lets say your number is n so i am just checking if a number greater than 1 can devide n.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I really liked the contest, solved five problems by myself in the contest time, and after that learned new ideas and solved the rest of the problems by peeking into the video tutorial (learned about a trie in G and that you can use the binary search method to find the value in question in E). So for me the contest was very educational.

But I'm writing this post to express my unpopular among these comments opinion about problems D and F. For me these problems were exactly what I've always liked about the contests in the past — when the problem can be solved just by coming up with an idea and clear coding instead of pasting one of the miriad data structures or reusing ideas from a similar problem that you've seen before. I like it when you don't need to have such specific knowledge in order to solve a problem.

So I personally would like to see more problems like D and F, even though I can see that a lot of people had trouble with them for some reason.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why is my solution of F with persistent trie TLE 314962660? but if I use another binary search method, it got ac 314958098. it seems that, for any test case, the two kinds of binary search call query function the same times? it's weird, can anyone tell me why my first binary seach is bad.

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why am i getting TLE on test case 26 for problem E . while the logic of my code is similar to that of editorial. Anyone help please .

my submission : 315084707

any suggestions please.

»
13 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

If you’re getting WA2 (291st numbers differ) on problem G, the bug is probably in how you pick the maximum index. You need to take the maximum over all indexes for cases where k′ᵢ = 0 and xor′ᵢ = 1.

Test case from the statement:
»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone help me with this code..i am getting WA again and again 320445368

»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In C, if number is even then it always not a prime expect.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is my solution for B :

Your code here...
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;    

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> v;
        int count=0 , rest = 0;
        while(n!=0)
        {
            int digit = n % 10;
            v.push_back(digit);
            n /= 10;   
        }
        sort(v.begin(), v.end());
        for(int i=0;i<v.size();i++)
        {
            if(v[i] == 0)
            {
                count++;
            }
                rest = v.size() - count;

        }
        rest--;
        int res = count + rest;
        cout << res << endl;
        
    }
    return 0;
}

Can somebody explain where am i doing it wrong ?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

E submission my solution is based on counts of a and b . and after seeing others submission i feel i think too question oriented not in a general way.

how to improve that???

»
5 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

Why is my solution got wrong for problem G, I have taken all the case

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

ll cal(vector<ll> & ai, ll las, ll k){
	ll ans = ai.size() + 1;
	map<ll, ll> cnt;
	for(ll i = 0; i < ai.size(); i++){
		ll x = (ai[i] >> las) & 1;
		ll st = 1;
		if(x){
			for(ll j = las - 1; j >= 0; j--){
				ll x1 = (k >> j) & 1;
				ll ta = (ai[i] >> j) & 1;
				if(x1){
					st = ((st << 1) | (1 ^ ta));
				}
				else{
					ll tem = ((st << 1) | (1 ^ ta));
					if(cnt[tem])ans = min(ans, i - cnt[tem] + 2);
					st = ((st << 1) | ta);
				}
			}
			if(cnt[st])ans = min(ans, i - cnt[st] + 2);
		}
		else{
			for(ll j = las - 1; j >= 0; j--){
			    ll ta = (ai[i] >> j) & 1;
			    st = (st << 1) | ta;
			    cnt[st] = i + 1;
			}
		}
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	ll t;
	cin >> t;
	while(t--){
		ll n, k;
		cin >> n >> k;
		vector<ll> ai(n);
		for(auto & i: ai)cin >> i;
		if(k == 0){
			cout << 1 << endl;
			continue;
		}
		ll las = 32;
		ll ans = n + 1;
		for(ll i = 32; i >= 0; i--){
			if((k >> i) & 1){
				las = i;
				break;
			}
			vector<ll> lef, rig;
			for(ll j = 0; j < n; j++){
				ll x = (ai[j] >> i) & 1;
				if(x)lef.push_back(j);
				else rig.push_back(j);
			}
			for(ll j : lef){
				ll idx = upper_bound(rig.begin(), rig.end(), j) - rig.begin() - 1;
				if(idx >= 0){
					ans = min(ans, abs(rig[idx] - j) + 1);
				}
				idx = lower_bound(rig.begin(), rig.end(), j) - rig.begin();
				if(idx != rig.size()){
					ans = min(ans, abs(rig[idx] - j) + 1);
				}
			}
		}
		ans = min(ans, cal(ai, las, k));
		reverse(ai.begin(), ai.end());
		ans = min(ans, cal(ai, las, k));
		if(ans == n + 1)ans = -1;
		cout << ans << endl;
	}
	return 0;
}