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

Автор vovuh, история, 6 лет назад, перевод, По-русски

Идеи всех задач принадлежат MikeMirzayanov. Все задачи также приготовил он. Я просто помог с тестированием, вычитыванием и написанием разборов.

1352A - Сумма круглых чисел

Разбор
Решение

1352B - Сумма слагаемых одинаковой четности

Разбор
Решение

1352C - K-е неделящееся на n

Разбор
Решение

1352D - Алиса, Боб и конфеты

Разбор
Решение за O(n)
Решение за O(n^2)

1352E - Особые элементы

Разбор
Решение

1352F - Восстановление 01-строки

Разбор
Решение

1352G - Особая перестановка

Разбор
Решение
Разбор задач Codeforces Round 640 (Div. 4)
  • Проголосовать: нравится
  • +133
  • Проголосовать: не нравится

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

На русском не прочитать разбор D (Unable to parse markup [type=CF_MATHJAX])

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

    Исправлено еще до того, как опубликовали, пакет с полигона еще не подтянулся. Подождите немного.

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

so some of the participants are going to reach 1800+ ratings ? i believe this shouldn't be happening. CHECK THIS OUT

![ ](Capture)

edit : this is what cf predictor is saying.

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

Can anyone explain the binary search solution for problem C?

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

In problem C, how need=(k-1)/(n-1) ?

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

    This can be explained more easily if you understand that before each multiplier of $$$n$$$ there are $$$n-1$$$ integers not divisible by $$$n$$$, so we need to "skip" some number of such blocks. $$$\lfloor\frac{k}{n-1}\rfloor$$$ doesn't match because when $$$k$$$ is divisible by $$$n-1$$$ then we don't need to count the last block.

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

      won't number of such multipliers be k / n ? if n = 3 and k = 8 there are 8 / 3 multipliers of 3

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

        Yeah, but we want the numbers that are NOT divisible by n.

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

          for n=3, k=8

          1,2,4,5,7,8,10,11 k-1/n-1 +k gives Ans=8+3=11

          However, a simple k/n gives Ans=8+2=10

          I guess, there is a more complex logic of using k-1/n-1. Can anyone explain it in a simple way? Stuck at this for quite some time.

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

            okay so idk how simple this is but like n = 3 k = 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

            so k/(n-1) is kinda like accounting for the extra cycle, because you need 1 less N to traverse a cycle (a cycle is 3 numbers, you only need 2 indices in this case to traverse the cycle). then k/(n-1) accounts for that extra N every time it cycles through (if u write it out on paper it makes sense lol)

            and if the cycle perfectly lands (when k%(n-1) ==0) then you gotta subtract one because you overcounted a cycle. for example, in the n= 3 and k = 8 case, if you did this cycle counting normally you'll end up with 12, but because the cycle cleanly divides you gotta subtract 1. at least i think that's how you do it idk it made sense when i wrote it out and went through cases

            and of course catch edge cases k == n and k < n

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

            From 1 to N, there are N-1 numbers not divisible by N. In every block of N numbers, N-1 are not divisible by N. So if we want K numbers, there must be at least $$$\frac{K}{N-1}$$$ blocks.

            Each block with N numbers. Let the number of blocks be B. This will take you to $$$B\times N$$$.

            So, from 1 to $$$BN$$$, you have $$$B\times(N-1)$$$ bad numbers. Count how many more do you need and add that to your current value. If you are already complete, then $$$BN-1$$$ is your $$$K^{th}$$$ Number.

            I hope I'm not making this complex. Code For Reference

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

            I got stuck at this for an hour and ruined my contest. D was definitely easier than C and it is unfair to put it after C.

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

              I think the difficulty is subjective. I couldn't do B for a long time, switched to C, and I felt it was easier. I totally agree that D was easy to understand but the implementation can get a bit complicated. C was thinking based and if you get the trick, it becomes really easy to implement.

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

          "Each multiplier of n shifts our answer by 1. The number of such multipliers is need = k — 1 / n — 1" so he finds numbers such that are divisible by n

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

I attempted to solve F using dp[n1][n2][n3][ends] : answer to the original problem when you have n1,n2,n3 and the resulting string ends in "ends" ("0" or "1"). My Python solution seems to TLE. Is it because this solution is basically O(10^6) and the number of test cases <= O(10^3), overall O(10^9)? or am I doing something silly

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

this round was so good and i had so much fun as a pupil and learnt new things i hope u do more div4 as u can <3

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

Can we do Div4-E with segment trees?

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

How to solve problem G using DFS (Depth First Search) ? I tried by joining numbers whose absolute difference satisfies the given condition and then traversing. How can I modify to make it work.?

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

Could someone try to hack 79593227? It does O(n * n * log(n)), which should be cut by the strict time limit but I couldn't hack it.

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

Can anyone explain the tutorial of the B problem in a much simpler way?

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

    essentially, odd numbers can only be made with odd numbers, and an odd amount of numbers at that.

    even numbers can be made with any amount of even numbers and an even amount of odd numbers.

    then you set all the numbers to 1 or 2 (depending on if you want the array to be even or odd based on those rules) and then the last number is the amount that ur left with after subtracting all of the 1s and 2s

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

I think my solution to G is a bit interesting. For all quadruples of natural numbers till the floor(n/4)th tuple can be arranged in order : 2 4 1 3, eg. 2 4 1 3 6 8 5 7 10 12.... and for the last incomplete tuple, it is easy enough to insert them in between elements of the last complete tuple.

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

can anyone tell me, how to solve G using bfs/dfs?

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

    The vertex set can be represented as the set of all numbers from 1 to n. The adjacent numbers for a node 'x' would be {x-4,x-3,x-2,x+2,x+3,x+4} provided they are in between 1 and n inclusive. Now you can perform DFS. The answer would be the DFS which satisfies the given condition in the problem. (NOTE: Edited: It will not be the DFS which visits all vertices...since the graph formed is connected, each DFS will visit all vertices) Even if you do a DFS from each number, the complexity would be O(n^2) (this include the time for checking the validity of the current DFS), which I guess would pass the problem constraints.

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

      i tried it earlier but its not working.

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

          Saw your code, inside the dfs() for a given node, you are try all possible relevant nodes to jump. I saw that you are only pushing nodes into your path array. Why ain't you popping the elements off, if you don't find the relevant path? Also, why in your main function are you checking val<2 && val>4, ain't you pushing the relevant nodes into you path array. You yourself first built the graph with reachable nodes, why is that condition checking even necessary?

          Kindly Help.

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

            I am not trying all possible nodes to jump. Take for example, N = 4, if you draw the graph the edges will be 1-3, 1-4, 2-4. If I start a DFS from node 1, the path array will contain elements in the following order {1,3,4,2}, which is not a valid answer. The correct answer would be the DFS that starts from node 2, {2,4,1,3}. A DFS generates a Spanning Tree, not a path. The path array is just storing the sequence in which the depth first traversal occurs and it may or may not be a path. In order to check whether it is a valid path (both in terms of the definition of being a path and the given condition of the problem), by just checking the given condition of the problem, I would be able to arrive at the solution.

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

              Wouldn't the if(val<2 || val>4) always hold false because you built the graph in way that only relevant nodes are traversed and after the dfs() call is over, you are again checking the same thing. Shouldn't you rather be checking if the lenght of path array is n or not. Because if it is n, then we always know that the path will be relevant(again because that's how you built the graph array and we will never be able to traverse irrelevant nodes(that do not hold the condition given in the question)). If you agree with me, then I still do not understand why without checking the path length that your solution is passing plus why that rechecking of (val<2 || val>4) condition when that's how your dfs function will traverse the nodes? Kindly explain.

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

                Please refer to my previous reply. In the example I have given, both have a length of n, but only DFS from node 2 is a valid answer. Refer to this link for better understanding.

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

                  You didn't get me, you stored nodes in the adjacency list such that they atleast differ by 2 and atmost by 4, then why are you doing checking it again after the dfs call. The dfs traversal will take care of jumping only to the relevant nodes. You said that the path array may contain {1,3,2,4} can you tell me how did you path store 2 after 3, when you don't have 2 in the adjacency list for 3?

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

    Check it out! 79806425

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

In the tutorial of problem D it is mentioned that we could solve the problem in O(n^2) but isn't the required complexity O(n) ? Correct me if i am wrong.

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

The solution of G in tutorial is very good but how to come up with this solution? I mean the intuition for the tutorial solution.

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

    I played with small permutations, trying to find a working block small enough so I could replicate it, and built the big N-elements answer. For me, it turned out to be a block of the first 4 numbers:

    2 4 1 3

    For N = 4 this is good. So as I said, I tried to make it work like a "brick" to build the answer, making chains of this block. So, if you have N = 8, you can "link" two of these structures:

    2 4 1 3 — 6 8 5 7

    And so on. Then I worked out on the case when N = 5 (more generally, when N%4 = 1), and I noticed that simply adding n to the sequence is ok.

    For N = 6, or N%4 = 2, you have to pop the last element (3) of your sequence, and mix the remaining two elements:

    2 4 1 5 3 6

    And lastly for N = 7 or N%4 = 3, an extra step, also removing the last element and mixing the remaining three elements:

    2 4 1 5 7 3 6

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

Am I the only one who solved problem G by graph?

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

    Can you explain your approach

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

      Make a graph of N nodes numbered 1 to N. Then for each node i add bidirectional edges between node i and i+2,i+3,i+4. After that Run dfs from each node separately, and check only for the straight path going from the node to any leaf node, if that path covers all N nodes then answer is the node of the path in the same order, otherwise if don't get any such path at the end, then answer doesn't exist.

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

        I saw in your code that in your dfs(), you have used break statement. If we don't get a relevant path by traversing from the given node then don't you think that then we should try for another node rather than giving yup our hopes that we won't find the right path if the very first node is unvisited. Moreover, in that case the path vector (in your code-v) will be not remain global but rather be passed in the function(in non-reference way)

        Kindly correct me, as to why your code used break?

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

    I just saw your solution for G, where you visit a node if it's not visited and then break out of the loop. What if you start from Node 1, then visit Node 3 and find out that permutation starting from 1->3 is not possible but permutation starting from 1->4 is possible ? You are not visiting node 4 from 1 as you have a break statement.

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

is this contest unrated?

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

Can anyone explain in Problem E why am I getting TLE when i am using map to count the frequency and find them 79611958 and it accepts the solution when i m using unordered map 79613165 i think in both cases overall time complexity is O(n*n). vovuh?

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

Can anyone explain the case when n1 = 0 for problem F. Weren't we supposed to output a SINGLE string??????? I assumed that n1 = 0 would implicitly mean that either n2 = 0 || n0 = 0. Wasn't that supposed to be the case?????????

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

can anyone explain how case n0=1 , n1=0 , n2=1 will be handled in question F ??

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

Is there a way of doing E using sliding windows that doesn't cause TLE? or particularly any other way of doing E, I don't like editorials' solution for E, and was thinking if there is some other way.

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

    I got accepted with two pointers (which you can relate to sliding window). My approach was going through each element of the array and finding a subsegment with a sum equal to the element, as long as the difference between the two indices $$$l$$$ and $$$r$$$ is higher than 1. Two pointers has a complexity of $$$O(2n)$$$...so you can simplfy it to $$$O(n)$$$, and doing it for each element gives a complexity of $$$O(n^2)$$$.

    Here's my submission: 79549243

    Just to be sure, I also used printf and scanf instead of cin, cout and FAST I/O, as it can be even faster with large inputs. Also note that I could have also saved the result for previous numbers to make it faster when there are repetitions, but in the worst case scenario where that wouldn't happen, it wouldn't be of much help.

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

    use this function for each elements of array ,increment ans by 1 if this function return true,take care of the function it return true for subarray of length one also but in our case it should be at least two. overall time complexity O(n*n),space complexity O(n). my sol

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

did not receive a rating even after solving a question in the contest div.4

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
    ll two,one,zero;
    cin>>zero>>one>>two;
    string ans = "";
    bool started=false;
    char prev;
    while(two--){
        if(!started){
            started = true;
            ans += "11";
            prev = '1';
        }else{
            ans += "1";
        }
    }
    
    while(one--){
        if(!started){
            started = true;
            ans += "10";
            prev = '0';
        }else{
            if(prev=='0'){
                ans += "1";
                prev = '1';
            }else{
                ans += "0";
                prev = '0';
            }
        }

    }

    while(zero--){
        if(!started){
            started = true;
            ans += "00";
            prev = '0';
        }else{
            if(prev=='1'){
                ans += "00";
                prev = '0';
            }else{
                ans += '0';
            }
        }
    }
    cout<<ans<<"\n";

Can someone please explain me why this submission is WA. This is the link of my submission It went wrong on testcase 111, I do not understand why?

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

Can someone help me out, in problem A my code is working fine with testcase1 in Hackerrank editor and my terminal but it is giving different output when I submit it in CForces. Submission: https://codeforces.me/contest/1352/submission/79486521

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

I have used a hashmap in problem E but still TLE.Can anyone explain why i cant get it Accepted with this solution(https://codeforces.me/contest/1352/submission/79563004).I use java,can this be a factor as it is slower than c++.

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

Consider case n1=0 separately and print the sting of n0+1 zeros or n2+1 ones correspondingly.

won't this make a 01 appear in the string while there should be no such pair in the string?

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

    (I kind of misunderstood what you said, so I'm rewriting my comment.)

    That sentence means how to handle cases like 3 0 0 or 0 0 4.

    For 3 0 0 you need 0000, and for 0 0 4 you should output 11111.

    Testcases such as 3 0 3 will not appear at all, since there must exist "01" or "10" somewhere so there is no solution for this case. The problem statement says that impossible testcases will not be given.

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

nice problems for rating<=1400....i learned a lot (mainly difference b/w sets and arrays)

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

Скажите пожалуйста почему в задаче C количество множителея не равно [n/k]?

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

Can anyone tell me the problem with my Codeforces Round 640 (Div. 4) Ques B. Here is my code:

include<bits/stdc++.h>

using namespace std; int main(){ int t; cin>>t; while(t-->0){ int n,k; cin>>n>>k; if(k==1){ cout<<"YES"<<endl; cout<<n; } else if(n==k){ cout<<"YES"<<endl; for(int i=1;i<=k;i++) cout<<'1'<<' '; } else{ if(n%2==0){ if(k<=n/2){ cout<<"YES"<<endl; for(int i=1;i<k;i++) cout<<'2'<<' '; int number = n — (k-1)*2; cout<<number; } else cout<<"NO"; } else{ if(k%2==0) cout<<"NO"; else if(k>n) cout<<"NO"; else{ cout<<"YES"<<endl; for(int i=1;i<k;i++) cout<<'1'<<' '; int number = n — (k-1)*1; cout<<number; } } } cout<<endl; } return 0; }

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

    In your submission of that code, the judge says it failed in case 54 of the 2nd test, as you didn't give an answer to it, although it exists. Luckily that line of the test case is shown, and it seems that fails with 6 4. And as you can see, you can represent it with numbers 1 1 1 3.

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

Anyone still struggling about writing a good comment?

I do :(

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

My solution for 1352E had O(n^2) time and got TLE. Approach is quite similar to the one described in editorial. Perhaps the time limits are too strict

https://codeforces.me/contest/1352/submission/79526875__

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

Can anyone tell me if there is any mathematical intuition behind the derivation of formula ⌊k−1/n−1⌋ in .1352C - K-th Not Divisible by n

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

    for every n integers , there are n-1 integers before it which are not divisible by n; say n=4, then there are n-1=3 integers 1,2,3 which are not divisible by 4.

    so for after every n-1 positions,there is multiple of n . So our ans is shifted by 1; then for k postions, your ans is shifted by k/(n-1);

    but if k is divisble by n-1 , we dont need to count the final shift.

    So we can check for only k-1 pos , i.e shift= k-1 / (n-1)

    shift=(k-1)/(n-1); ans= k + shift ; print ans;

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const int N = 8010;
int a[N];
int cal[N];
bool is[N];
int sum[N];
int main()
{
	int t;
	cin >> t;
	while(t --)
	{
		memset(is, 0 , sizeof is);
		memset(cal, 0, sizeof cal);
		memset(sum, 0, sizeof sum);
		int n;
		scanf("%d", &n);
		for(int i = 1; i <= n; i ++)
			scanf("%d", &a[i]);	
		for(int i = 1; i <= n - 1; i ++)
		{
			sum[i] = a[i] + a[i + 1];	
			is[sum[i]] = 1;   //here
		}
		for(int i = 3; i <= n; i ++)
		{
			for(int j = 1; j <= n - i + 1; j ++)
			{
				if(sum[j] != -1) sum[j] += a[i + j - 1];
				if(sum[j] > n) sum[j] = -1;
				else is[sum[j]] = 1;
			}
		}
		int ans = 0;
		for(int i = 1; i <= n; i ++)
		{
			if(is[a[i]])
			{
				ans ++;
//				cout << i << ' ';
			}
		}
		cout << ans << endl;
	}
	return 0;
}

why this code is accepted? where i mark "here",sum is out of bounds.

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

    problem E

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

    Arrays in C or c++ are allocated in contiguous memory. Let your array size is 6 and you store 8 elements in the array. Then the two extra elements may or may not be stored in the array. It depends on your memory location. If the two extra elements stored lie in another's memory location (i.e. stored in those locations where memory is already allocated) then the compiler will show some error, but if those additional elements get some unallocated memory or free memory then there will be no problem while running the program.

    In your case, the additional elements are getting free unallocated memory in the memory allocation (i.e. program's virtual memory), so your program is not showing any error. It varies compiler to compiler.

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

I feel div4B harder than 1329B - Dreamoon Likes Sequences, which is div1B. Div4B was too dirty kind of problem.

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

I am getting WA on test case 2 of problem E Can someone help me know which test case can it go wrong? Link : https://codeforces.me/contest/1352/submission/79717403

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

say please, why the solution of C isn't k+[k/n]?

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

Скажите пожалуйста, почему решение C не равно k+[k/n]?

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

In problem E. Special Elements, if I compute a prefix array and run two loops to take out sum and use hashing as used above to count the special elements, why does it gives TLE?

When this also takes O(n^2) and the above mentioned solution also takes O(n^2) ?

My Solution : https://codeforces.me/contest/1352/submission/79552941

Does it shows TLE even if memory limit exceeds ? If not then what does the judgement says ?

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

For Problem F .. The constrain (0≤n0,n1,n2≤100; n0+n1+n2>0 ) .

But n2 must be n2>=1 . if n0 = 1 n1 = 0 n2 = 2 output is = 00 . Why? and How !!!!!!!

if n2==0 there will no such solution that can satisfy the condition.

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

Can Anybody tell me the logic behind why l<=r and not l<r in alice,bob and candies sum??

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

    Because either of them will eat the candy at the index l=r. If you use l<r then 1 candy will remain uneaten.

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

      BhavyaBhatt Suppose if Alice has eaten that candy , and According to the loop's Condition(l<=r) bob can eat the candy but he shouldn't be eating that candy because Alice has already eaten it.

      Am I right?

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

        l is the index of leftmost uneaten candy and r is the index of rightmost uneaten candy. so when l=r happens, that means all candies from index 0 to index l-1 are eaten by alice and all candies from index r+1 to n-1 are eaten by bob. so candy at index l=r will be uneaten so in the loop we should proceed. Now if alice's turn is to eat candy then l++ will be done and all candies are eaten (l>r happens) and similarly if bob's turn is to eat candy then r-- will be done and again all candies are eaten (l>r happens).

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

          Thank you for the reply BhavyaBhatt.I know the concept you are talking about , but Suppose Alice ate the candy at l=r then we should have not let bob eat that already eaten candy , because if bob also eats the candy then output will be wrong because it will be counted!

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

For F(Binary string construction), if n0=1, n1=0, n2=1, the editorial solution, gives output 00. Some other codes gives output 0011, which is incorrect. What should be the correct answer since no valid string is possible for this case.

Update- Missed the statement " It is guaranteed that a solution exists."

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

Can someone explain why am I getting TLE in question D, I know its an easy problem but I checked my while loops and none of them are recurring, idk why my code suddenly stops any bad practices you see,Thanks My Solution

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

Problem 1352F Can someone please explain why am I getting TLE in this solution

This is my submission

Since maximum number of elements inside the string will be always less than 500 and number of independent test case is 1000 so we can solve the question in O(t*n) time right?? But why I am getting TLE here?

»
4 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
my Approach for G :
start from x=2-(n%2);
x x+2 x+4 x+6 x+8 .. .. .. ..  n (n-3) (n-1) n-5 n-7 n-9 n-13 n-15
notice that we swapped the two values after n 

mysubmission

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

In problem C, why is $$$need = ⌊(k-1)÷(n-1)⌋$$$, and not $$$need = ⌊k÷n⌋$$$?

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

Shittiest constraints ever for problem E.

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

1352C - K-е неделящееся на n

The key observation is that in every block of n consecutive integers, exactly one number is divisible by n, and the remaining n — 1 numbers are valid.

Instead of calculating the kth number which is not divisible by the number n manully(that may give tle as k can go upto 1e9), we think in terms of blocks.

Every block of size n contributes n — 1 valid numbers, and that means for n — 1 valid numbers, we skipped exactly one multiple of n .

To reach the kth valid number, we must add the number of skipped valid blocks before k, in k such that we can reach the answer.

OR we can apply binary search also(easy approach but takes a little more time than other method ).

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

Why D questions O(n) solution also get 171ms but someone's solution can get 46ms. I'm confused

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

386984602 accidently solved this G question , first tried with possibility approch, but then it got accepted, thought of it why its happening and then later optimized it- 386986823 , the logic is , i ll check if we can form valid array by starting with i th element out of all n (1, 2, 3.. n) , and the way i was making array was — checking first valid element at current index which is not used till now. if all valid elements for current index (that is last index value — 4 to last index value — 2 and last index value + 2 to last index value + 4) is not possible to put in (either cause of going out of n or being lessor than 0 or is already in set) then it means its not possible to make valid array for current starting element, will then try for all other starting elements possibilities.