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

Автор SpyrosAliv, 6 месяцев назад, По-английски
Comment

Problem A — Souvlaki VS. Kalamaki

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem B — Siga ta Kymata

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem C — Monopati

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem D1 — Diadrash (Easy Version)

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem D2 — Diadrash (Hard Version)

Special thanks to Friedrich for figuring out the better solution.

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem E — Plegma

Solution
Implementation
Rate the Problem
Rate the Difficulty
Разбор задач Codeforces Round 1063 (Div. 2)
  • Проголосовать: нравится
  • +166
  • Проголосовать: не нравится

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

first.

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

B is too hard for div2

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

    B is very easy greedy, if you account for the cases where it is impossible to make certain(upto 4) positions 1 then you can just make the rest of the entire string 1 with maximum 5 operations. Just greedily select

    1) 0 index and min

    2) 0 index and max

    3) min and last index

    4) max and last index

    5) 0 index and last index

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

    I agree. This also discourages participants. Because some may think if B is such hard, then how much hard the others will be!

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

Bad contest

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

B is the worst problem

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

I hate the trend of C being easier than B..

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

If only I have seen C before B :(. I spent a lot of time on B, and still couldn't solved

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

Mistaken order of B and C will eat my huge rating:(

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

Ok, over all Bs difficulty mostly comes from the strange statement. At first, I was sure that $$$\max (p_l, p_r)$$$ referred to the whole range. But once you realize that it is not the case, then the following observations really help:

  • Can the leftmost element be 1? No
  • Can the rightmost element be 1? No
  • Can the minimum element be 1? No
  • Can the maximum element be 1? No

And then you ask yourself, since I have those elements that can never be one, can I use them to create ranges that are able to create everything else? And the answer is yes!

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

    That feel like pure guessing. I got the four observations you listed almost immediately, still couldn't solve it but coming up with false greedy solutions.

    How to be good at this kind of problems?

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

      Uhhh, I think that's kinda the point of codeforces... There are a lot of problems that require knowing how and where to guess.

      I personally find that there are a lot of easy problems that are sometimes surprisingly tricky. I remember like a year ago I found a 1200 rated problem that just killed me: I had NO idea how to solve it in any reasonable way.

      So I think that overall to get better at them... well... just do more problems xd

      Although perhaps it could make sense to actually sort problems in the range 1000 to 1800 by least solved, and perhaps then you can find problems that are surprisingly annoying/weird/etc

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

        Maybe I really should do more CF problems :P

        Although perhaps it could make sense to actually sort problems in the range 1000 to 1800 by least solved, and perhaps then you can find problems that are surprisingly annoying/weird/etc

        I never thought of that, will try it someday. Thanks!

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

      It's not really guessing of you instead consider a certain element and try to make it one, you will notice immediately it's impossible when it's a min or max, then that it can't be on the edges of the array. The argument for why it's impossible to turn these into ones naturally leads you to why it's possible to do that for the others. Finally you notice that there are 5 interesting ranges ( combining edges of the array and min/max ) that turn everything else into one.

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

    Could you please explain your initial approach in simpler words, it is somewhat difficult to understand for a newbie. Would mean a lot

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

      So for me, it was kinda like pattern recognition... I made those four observations and asked myself if, since they can never be painted, maybe they're the only ones that can never be painted and that I can paint all the others in at most 5 operations.

      And so I actually took out my notebook and started drew out the borders, after which I connected them all and got 5 meaningful ranges.

      I'm afraid I can't go much more in-dept than that... I recommend that you focus on lower rated problems for now so as to be able to more easily attempt these kinds of problems >:)

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

    Ahhhh, I forgot that the elements in p are unique

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

B will take me to newbie

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

after seeing the soln b seems awesome; if only i had figured that out in contest ; hopefully i would be able to solve similar problems in future contest

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

ok, thanks for quick editorial.

I got cooked by B

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

Problem B:

What is the meaning of hold at the same time ?

My Interpretation : If any only if for all i , sunch that l<i<r , min(pl,pr)<pi<max(pl,pr) ?

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

Can anyone tell me what's wrong with my solution for C? 348365560

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

E: Let $$$r,c$$$ the input for the second run (both are binary strings with length of $$$n$$$).

  • If $$$r \le c$$$, $$$C=1$$$
  • If $$$r \gt c$$$, $$$C=0$$$

We can construct such input at the first run.

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

    This is indeed a correct alternative solution for problem E

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

    Whats the proof that you can always construct such input at the first run?

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

      Suppose every column and row satisfy $$$r \gt c$$$ and $$$C=1$$$,

      Choose any $$$c$$$ which has at least one 1, consider row $$$1$$$. It should have at least one 1. Then, we got a column with first element is 1. As a result, the first column will be full of 1. No row can be greater than this column.


      Suppose every column and row satisfy $$$r\leq c$$$ and $$$C=0$$$,

      Choose any $$$r$$$ which has at least one 1, consider column $$$1$$$. It should have at least one 1. Then, we got a row with first element is 1. As a result, the first row will be full of 1, and every column is full of 1, and the connectivity is $$$1$$$ now.

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

        it seems like a proof by contrast. but I still don't get it. can you please elaborate on how the connectivity is related to the row and column dictionary order please?

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

          As mentioned above, there're no binary grid that satisfy every $$$r \gt c$$$. And the only $$$2$$$ binary grid that satisfy every $$$r\leq c$$$ is full-0 and full-1, which is either illegal or has $$$1$$$ connectivity.

          So actually row and column dictionary order and the connectivity have almost no connection. The only thing we need to ensure is the corner case of full-1 binary grid.

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

    But what if $$$C=1$$$ and all rows are lexographically greater than all columns (and also $$$C=0$$$ in contrast)?

    Is there a proof that such case cannot exist?

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

      When 1st row and 1st column have both $$$0,1$$$, it's ok.
      When 1st row and 1st column have only one character, we can cut down them.
      Only treating 1st row has no $$$1$$$ is ok (other case can be treated in the same way).
      1st row is $$$00\dots0$$$ and we have some $$$1$$$ in 1st column, so $$$r \lt c$$$ can be constructed.
      some row is $$$1?\dots?$$$ and all column is $$$0?\dots?$$$, so $$$r \gt c$$$ can be constructed.
      Edge case is a grid which have only $$$1$$$, but it's ok because then always $$$r=c$$$.

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

        I wonder the sufficiency of such a construction: e.g. I can make 2 examples demonstrating the same logic:

        101 010 101 which has both 0 and 1 in the 1st row and col and it's not connected.

        110 110 000 which has both 0 and 1 in the 1st row and col and it's connected.

        how is that connectivity decides whether there's such a configuration?

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

          Connectivity is not matter. We can always find $$$r \lt c$$$ or $$$r \gt c$$$ unless the grid has all the same character.

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

            Oh, I see your point. regardless of whether the graph is connected or not. we will have guaranteed that we can choose a row >= a col or a row < a col.

            we just choose such a pair of row and col to deliver such a message denoting whether the graph is connected or not.

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

      That is impossible.

      Fact: If the grid has at least one 1 and one 0, then at least one row is (lexicographically) strictly larger than one column.

      Proof: Let k be the number of leading 0's in the smallest column.

      Case 1: If k = n, this case is trivial since at least one 1 exists in the grid.

      Case 2: n > k >= 1.

      If the numbers of leading zeros of all rows are greater than or equal k, than the first column contains all 0, violating k is the number of 0's in the smallest column.

      Case 3: k = 0.

      In this case, the first entry of all columns are 1 and the first row then contains all 1's, which is larger than the smallest row (since at least one 0 exists).

      Rows and columns are symmetric. So we can also find a column strictly greater than a row.

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

I think I came up with the correct D2, but forgot to submit it imao. Might be one of my worst blunders ever.

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

for every i such that l<i<r and min(pl,pr)<pi<max(pl,pr) hold at the same time, you will set si to 1

Isnt this line so confusing, "for every i" part. the condition doesnt seem to hold true for every l<i<r (min(pl,pr)<pi<max(pl,pr)) in the arr. take this

5 3 4 2 1 5 01100

here non pass 5 1 5 1 4 5 5 4 5 4 5

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

the round except problem B is good

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

For B for me a big hint was that you needed to figure out if it was possible in less than 5 moves. If that 5 could be any number then you could binary search the answer and would get the minimum number of moves, yet the problem specifically said that you do not need to find the minimum number of moves so there was something special about the number 5...

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

    5 is special because you can always do it in at most 5 moves, given that its possible ofcourse, and the figure 5 comes from that fact that u need at most 5 ranges to so.

    For a string s where it is possible to do so,

    the ends and the min/max permutation element would have their corresponding bit

    in the string to be 'O'

    so s if of the form 0 1 0 1 0 1 1 0 0 (min_index) 1 1 0 0 1 1 0 0 (max_index) 1 1 0 0

    then we can always just pick the ranges

    1 to min

    1 to max

    min to max

    min to n

    max to n

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

I used another approach for C. So the idea came from that, for any path from (1, 1) to (2, n), we first go right, then down, then right again. So we can iterate each position i where we go down. And for fixed i, get the minimum value and maximum value on the path (1, 1) -> (1, i) -> (2, i) -> (2, n). This can be achieved by maintaining prefix min/max for the first row and suffix min/max for the second row.

Suppose for one path, the minimum value is L, maximun value is R. Then R, R + 1, ..., 2n is all legal for L. Also, R, R + 1, ... 2n is all legal for L — 1. So we can maintain the smallest R for every L when calculating each path. And after calculating L and R for every path, we can iterate L from 2n to 1, while maintaining the smallest R, and for every L, accumulate 2n — R + 1 to get the final answer. Here is my submission.348331154

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

Eventually reach Candidate Master after reaching Expert for over 500 days. Really really happy. Thanks for the great contest! ヾ(^∀^)ノ

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

loved the difficulty, luckily after 45 mins of thinking, I was able to solve B ^_^

Thank you to you all for making this round possible!

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

I think, the purpose of some Div2B problems is not to be solved.

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

i have a fun solution for E that is i think simpler than the one in the editorial: 348371787. though i was not yet able to prove its correctness. i have to prove that if all rows and all columns contain the same number of ones, then either the grid is disconnected or there are no zeros at all.

upd: the solution is wrong. i apologize. here is a counterexample:

1 1 1 0

1 0 1 1

1 1 0 1

0 1 1 1

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

    The good one that passes the tests, but fails on hacks :D

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

    Before reading this I came up with something similar and I think an extension of this idea works.

    Spoiler

    Concise implementation here: 348401861

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

    sob bro

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

guessed the solution for B in the last minute and it was correct

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

whenever you get stuck on an easy question that requires an interesting point, come up with 10-20 different examples and try to solve it. you will automatically come up with the answer!!

Meanwhile, B,C were great! "C" 's implementation was beautiful :)

UDP: Now i realize i provided a different solution for C :) and it's in O(n)

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

adhocforces

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

Loved Problem A, also almost solved B, but was missing out on the indexes, overall loved the problems, although B was a bit difficult, got a lot to learn !

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

After seeing problem B felt like codechef, where questions are tangled around greedy ideas. I don't hate or like problem B but felt like thinking>>>coding.

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

fast editorial!

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

https://mirror.codeforces.com/contest/2163/submission/348377026 Problem C can someone explain why this fails ??

I tried merging the global left and right accordingly (does the order of the max and min, of the down right path affect this ?)

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

in problem B, min(p_l,p_r) is minimum over the range (l, r) or minimum of p_l and p_r ??

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

Can somebody kindly point out what I'm doing wrong here. Appreciate it. sub

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

D1 also has a Nested binary search on answer solution which makes the number of queries = 2*log^2(n) 348380335

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

can some one explain why cant we use merge intervals approach to merge them ?

    vector<vector<int>>v;
    for(int i=0;i<q;i++){
        cin>>x>>y;
        v.push_back({x,y});
    }
    sort(all(v));
 
    vector<pair<int,int>> inv;
    int start = v[0][0] , end = v[0][1];
    for(int i=1;i<q;i++){
        if(v[i][0]>end){
            inv.push_back({start,end});
            start = v[i][0] , end = v[i][1];
        }else{
            end = max(end,v[i][1]);
        }
    }
    inv.push_back({start,end});

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

Problem C

This can be done by keeping two sets of de-activated cells, one for each row.

Can somebody please explain what exactly is the author is doing in this line in the solution?

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

I appreciate the efforts you have done to create this contest however I noticed that adhoc became the reigning champion in the past 2 years. A div 2 should never be a speedforces (due to adhoc) contest. ABC should be accesible to pupils and D should be doable to specialists and experts.

I have seen some CMs and Ms failing at problem B/C in the recent few contests. This begs to question the process of reviewing the contests in the making.

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

B -> another approach : we can replace cout << min(mn, mx) << " " << max(mn, mx)** with cout << 1 << " " << n**

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

B harder than C for the third time in a row. First the pinely round next the global round and now this. How come no one felt B was harder during testing.

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

My friend kafamcokkaristi wrote 348316517 a divide and conquer dp optimization for problem C, but we managed to create a case where it seems to take $$$O(N)$$$ distinct values, leading us to believe it runs in $$$O(N^2 \log N)$$$ in the worst case. However, from the assert() statements we added, we observed that this value is actually $$$≤ 5$$$ in the tests. Still, since hacks are disabled in recent contests, we can’t submit a hack; could you please add it manually? SpyrosAliv Proof_by_QED

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

Interesting insight of problem D2. my D1 solution is based on binary search as well but D2 takes it to a new level. Loved the idea of Mex[l, r] = min(Mex[1, r], Mex[l, n])

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

Hi everyone, I tried solving this problem and my code seems to be failing on some test cases, but I’m not sure where the issue is. Could someone please take a look and let me know what I’m missing or doing incorrectly? Any guidance would be appreciated. Thank you! ~~~~~ //Your code here... void solve(){ int n; cin>>n;

vector<int>a(n),b(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
vector<int>mnleft(n),mxleft(n);
vector<int>mnright(n),mxright(n);
mnleft[0]=a[0];
mxleft[0]=a[0];

int maxi=0,mini=INT_MAX;
for(int i=1;i<n;i++){
    mnleft[i]=min(mnleft[i-1],a[i]);
    mxleft[i]=max(mxleft[i-1],a[i]);
}

mnright[n-1]=b[n-1];
mxright[n-1]=b[n-1];
for(int i=n-2;i>=0;i--){
    mnright[i]=min(mnright[i+1],b[i]);
    mxright[i]=max(mxright[i+1],b[i]);
}

for(int i=0;i<n;i++){
    maxi=max(maxi,min(mnleft[i],mnright[i]));
    mini=min(mini,max(mxright[i],mxleft[i]));
}

cout<<maxi*1ll*((2*n)-mini+1)<<endl;

} ~~~~~

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

    You are counting pairs that are not in solution.

    For example, lets say n = 5 (2n = 10). And you got two mn, mx, one is [2, 6] and the other is [3, 7].

    So all x <= 2 can make pair with y >= 6 and all x <= 3 can make pair with y >= 7.

    But your code is taking x = max(2, 3) = 3 and y = min(6, 7) = 6. Your code counts the pair (3, 6) as a solution. But it is actually not a solution.

    Focus on this fact and maybe you can solve the problem :)

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

      that's valid point, i was mistaken. **** I made some changes here, although it failed-

      .......
      vector<pair<int,int>>vp;
          for(int i=0;i<n;i++){
              // maxi=max(maxi,min(mnleft[i],mnright[i]));
              // mini=min(mini,max(mxright[i],mxleft[i]));
              vp.push_back({min(mnleft[i],mnright[i]),max(mxright[i],mxleft[i])});
          }
          sort(vp.begin(),vp.end());
          int ss=vp.size();
          long long ans=(vp[ss-1].first) * ((2*n)-vp[ss-1].second+1);
          
          
          for(int i=ss-2;i>=0;i--){
              if(vp[i].second<vp[i+1].second)ans+=(vp[i].first*(vp[i+1].second-vp[i].second));
          }
          
          cout<<ans<<endl;
      .........
      
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I don't get why problem C is easier than problem B, man this shit ain't cool.

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

Is it possible to minimize the number of operations in B?

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

B was really hard to interpret...

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

Nice solution for E1 : Assume We want to check either m can be MEX or not what should I do ?

-> first we find the smallest right index where MEX(a[1]...a[right]) >=m . Similarly find the largest left index where MEX(a[left] .. a[right]) >=m . Now check either this range belongs to any given range or not. And yes this is the answer . Use nested binary search .

Total query 2*log(n)*log(n) Solution Link : https://mirror.codeforces.com/contest/2163/submission/348367619

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

Feels like the D2 idea is kinda being overlooked... The fact that the MEX of a segment equals the min of the MEX of two other segments seems useful (hopefully)

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

its alright if b was harder then expected. i really enjoyed the problem although i was not able to solve it.

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

Something's wrong with my solution for C and I can't find it. Could someone help? I've read and understand the editorial but part of me is curious as to what my solution misses.

For context, it uses a prefix mins and maxes on the top row and suffix mins and maxes on the bottom row to determine good boundaries and pushes them to a vector. The vector is then sorted and queried for the lower_bound for each i from 1 to 2n. The value 2n — endpoint + 1 is then accumulated and outputted.

I'm still trying to figure out what it is.

https://mirror.codeforces.com/contest/2163/submission/348351621

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

Sorry if it's obvious, but for D1, how do we guarantee the number of queries is at most $$$300$$$? This is the single issue I haven't resolved with the same solution during the contest.

EDIT: My bad I misread the problem... See below. Thanks fugazi_zeitgeist.

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

It's weird. problem B that I find a correct solution quickly (by guessing), but even top-200 can't solve it.

It's too polarized?!!?

Though I even can't solve A and 0 problem in the end, when contest running :(

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

It seems that B is much harder than C

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

Problem B:

why taking the whole range wont give the answer? cause if s is 1 for min and max the answer would be no and for every other number the answer would be possible. ~~~~~ // this is code

string s;

cin>>s;
f(i,0,n){
    if(s[i]=='1'){
        if(v[i]==1 || v[i]==n || i==0 || i==n-1){
            cout<<-1<<endl;
            return;
        }
    }
}
cout<<1<<endl;
cout<<1<<" "<<n<<endl;

~~~~~

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

    you misunderstood the satement as me. we cant take the whole range cause max(pl,pr) and min(pl,pr) doesnt hold for the whole range of [l,r] but only for the two numbers pl and pr.

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

Can anyone figure out that what's wrong in my approach for Problem B as I am getting wrong answer Contestant claims an answer does not exist, when it does exist. (test case 117):-

#B. Siga ta Kymata
import sys
input = sys.stdin.readline

def solver():
    t = int(input().strip())
    out_lines = []
    for _ in range(t):
        n = int(input().strip())
        prr =list(map(int, input().split()))
        st=str(input().strip())
        
        if st.count('1')==0:
            out_lines.append(str(0))
            continue
        
        min_val = min(prr)
        max_val = max(prr)
        min_idx = prr.index(min_val)
        max_idx = prr.index(max_val)

        if st[min_idx] == '1' or st[max_idx] == '1':
            out_lines.append(str(-1))
            continue
        
        is_leftover_one = False
        for i in range(n):
            if (i<min(min_idx,max_idx) and st[i] == '1') or (i>max(max_idx,min_idx) and st[i]=='1'):
                is_leftover_one = True
                break
        
        if is_leftover_one:
            out_lines.append(str(-1))
            continue
        
        idx1_1based = min_idx + 1
        idx2_1based = max_idx + 1

        sorted_indices = sorted([idx1_1based, idx2_1based])
        
        out_lines.append(str(1))
        out_lines.append(f"{sorted_indices[0]} {sorted_indices[1]}")
        
    sys.stdout.write("\n".join(filter(None, out_lines)))

if __name__ == "__main__":
    solver()
»
6 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

B's Description was misleading for me.Was solving some different problem for sometime.

Then, for every i such that l < i < r and min(p_l, p_r) < p_i < max(p_l, p_r) hold at the same time, you will set s_i to 1.

hold at the same time? Didn't tell what holds at the same time.

One direct way to interpret this is -> if this conditions holds for all i at the same time then set s[i] to 1.

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

Why my code wrong #8(problem C)? Who can tell me why, thanks.

#include<bits/stdc++.h>
#define int long long
using namespace std;
int read(){
	int cnt = 0, sign = 1;
	char c = getchar();
	while(!isdigit(c)){
		if(c == '-')	sign = -1;
		c = getchar();
	}
	while(isdigit(c)){
		cnt = (cnt << 1) + (cnt << 3) + (c ^ 48);
		c = getchar();
	}
	return cnt * sign;
}//quick read
const int N = 2e5 + 10;
const int inf = 2e18;
int a[N], bfmx1[N], bfmn1[N];//before max1, before min1
int b[N], afmx2[N], afmn2[N];//after max2, after min2
int minn[N], maxn[N], M[N], mn[N];
void solve(){
	int n = read();
	int size = 2 * n;
	bfmx1[0] = -inf;
	bfmn1[0] = inf;
	for(int i = 1; i <= n; i++){
		a[i] = read();
		bfmx1[i] = max(bfmx1[i - 1], a[i]);
		bfmn1[i] = min(bfmn1[i - 1], a[i]);
	}
	afmx2[n + 1] = -inf;
	afmn2[n + 1] = inf;
	for(int i = 1; i <= n; i++){
		b[i] = read();
	}
	for(int i = n; i >= 1; i--){
		afmx2[i] = max(afmx2[i + 1], b[i]);
		afmn2[i] = min(afmn2[i + 1], b[i]);
	}
	for(int i = 1; i <= n; i++){
		minn[i] = min(bfmn1[i], afmn2[i]);
		maxn[i] = max(bfmx1[i], afmx2[i]);
	}
	for(int i = 1; i <= size; i++){
		M[i] = inf;
	}
	for(int i = 1; i <= n; i++){
		int m = minn[i];
		M[m] = min(M[m], maxn[i]);
	}
	mn[size + 1] = inf;
	int k = inf;
	for(int i = size; i >= 1; i--){
		k = min(k, M[i]);
		mn[i] = k;
	}
	int fs = 0;
	for(int i = 1; i <= size; i++){
		if(mn[i] > size){
			fs += (size - i + 1);
		}else{
			int cnt = mn[i] - i;
			if(cnt > 0)	fs += cnt;
		}
	}
	int total = (size * (size + 1)) / 2;
	printf("%lld\n", total - fs);
}
signed main(){
	int T = read();
	while(T--){
		solve();
	}
	return 0;
}
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I solved (actually not) problem B and minimized the operations. Let i, j be the indices of the first and last units in x, then we can find mn1, mx1, mn2, mx2 in the range from 0 to i — 1 and from j + 1 to n — 1. Let's take the indices (mn1, mx2) and (mn2, mx1). After these operations, if s != x (if x[k] = 0, then we will not touch s[k]), then we output -1, otherwise these two operations. Unfortunately, I can't look at the tests, this solution gave WA 2 system test on test case 455. I really wonder why it doesn't work.

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

I was confused by the statement of B. I thought min(pl,pr) and max(pl,pr) holds for every pi which l<=i<=r ,and we just have to cout<<1<<" "<<n<<endl and all number except p1,p1,pmn,pmx could be counted.

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

Well.First, I need to thank the creator of this contest, because I have gained 172 ratings in this Div2.
But, I also need to say: What the f*** is Problem B?????

I think this sentence is bad: " $$$\min(p_l,p_r) \lt p_i \lt \max(p_l,p_r)$$$ "

It gave me -6 in B.

And I found it after CONTEST ENDING!!!!!

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

Could anyone tell me why my approach is wrong in question C https://mirror.codeforces.com/contest/2163/submission/348420021

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

    It recounts a set of indices. For example, it's possible that for one index, valid set of indices are (1, 3), (1, 4), (1, 5) and then for next index, another valid set of indices are (1, 3), (1, 4), (2, 3), (2, 4). According to your code, it will take the maximum of the minimum as the left index (2 in this case) and minimum of the maximum as the right index (3 in this case) and then form all the combinations which also includes (2, 5) which is not there originally. I also made this mistake many times in this question

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

      thanks

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

      How is it possible that $$$(2, 3)$$$ is a valid combination but $$$(2, 5)$$$ is not?

      If $$$(a, b)$$$ is valid then $$$(a - i, b + j)$$$ is valid for any $$$i, j$$$ such that $$$(a - i \ge 1) \land (b + j \le 2 * n)$$$. Isn't it true?

      In other words, we have $$$a$$$ ways to choose the first index and $$$2 * n - b + 1$$$ ways to choose the second index. But solutions using this idea do not work for some reason.

      UPD: I think I have found a counterexample:

      $$$ \begin{bmatrix} 3 & 1 & 6 \newline 5 & 4 & 2 \end{bmatrix} $$$

      If anyone's wondering why their solution fails, it might be insightful to test it against this test case.

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

Please help! What's wrong in my solution for D1? solution

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

Can someone please help me figure out what is the error in my code of problem C?

[problem:C]

[code] import java.util.*; public class Demo1 {

static void solve(Scanner sc){
    int n=sc.nextInt();
    int [][]arr=new int [2][n];
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            arr[i][j]=sc.nextInt();
        }
    }
    int []mint=new int [n];
    int []minb=new int [n];
    int []maxt=new int [n];
    int []maxb=new int [n];
    int min=Integer.MAX_VALUE;
    int max=Integer.MIN_VALUE;
    for(int i=0;i<n;i++){
        min=Math.min(arr[0][i],min);
        mint[i]=min;
        max=Math.max(max,arr[0][i]);
        maxt[i]=max;
    }
    min=Integer.MAX_VALUE;
    max=Integer.MIN_VALUE;
    for(int i=n-1;i>=0;i--){
        min=Math.min(arr[1][i],min);
        minb[i]=min;
        max=Math.max(max,arr[1][i]);
        maxb[i]=max;
    }
    int temp=2*n;
    int []ans=new int [2*n+1];
    int res=0;
    Arrays.fill(ans,Integer.MAX_VALUE);
    for(int i=0;i<n-1;i++){
        int mini=Math.min(mint[i],minb[i]);
        int maxi=Math.max(maxt[i],maxb[i]);
        ans[mini]=Math.min(ans[mini],maxi);
    }
    int curr=Integer.MAX_VALUE;
    for(int i=(2*n);i>0;i--){
        curr=Math.min(curr,ans[i]);
        if(curr!=Integer.MAX_VALUE){
            res+=(temp-curr+1);
        }
    }
    System.out.println(res);
}

public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int t=sc.nextInt();
    while(t-->0){
        solve(sc);
    }
}

} [/code]

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

I have read the solution to Problem C and nifeshe's code, and found that our initial ideas were the same, but our approaches to solving the problem were quite different.Using my not-so-smart brain, I've summarized that my code is mainly based on the premise that the grid has only two rows. If the number of rows in the grid increases, the time complexity will grow exponentially. This is an area where I need to work hard to improve.But I still want to share my solution because I came up with it during the competition, even though there were some issues at the time that prevented it from passing. 348463330

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

I think Problem B is simple; the difficulty lies in understanding the problem statement and the proof. It's relatively easy to guess it's related to the fifth power.

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

Can someone help me? I don't know what's wrong with my solution for C. I have WA on 2nd test on 615th test case.

My submission:

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

It would be great if you could add hints and then solution.

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

Can someone tell what's the mistake in this code for Problem C? 348500673

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

Hello Codeforces team,

I want to confess that the coincidence in my solution for problem 2163C with user ekagra444/ happened because of my own actions.

During the contest, we were giving the round in a lab setup. I accessed a common system to view another participant’s code, which was a clear violation of the Codeforces rules. I completely understand that what I did was wrong.

I take full responsibility for this mistake and sincerely apologize for my actions. I assure that this will never happen again. I’ve learned from this experience and will strictly follow fair play rules in all future contests.

Please consider this as my honest confession.

Thank you for maintaining integrity in the platform.

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

can there be a solution for B such that we only use one operation. my solution is as follows but i cannot find what's wrong. we can take the range in which '1' extends and then find possible , l and r out of that range. ex :- 6 1 3 2 4 6 5 001100 // array is 1 — indexed

range in which '1'expands is (3, 4) so we search for min and max element in range (1, 2) && (5, 6).

as in this example "l" can be 1 and "r" can be "6";

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

funny thing is I thought I could do atmost 300 queries lol in $$$D1$$$ ,my solution does 210 queries at max there could be a medium version of this problem I think

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

    same me first i had think then after working 3 hours and then again 1 hour i didn't read that but then my frnd told me that hey u can do n/2 think like that then i did logn queries for finding 0 and remove multiple queries have same l or r and what the final pairs i have i sort them based on the difference between them and just print in this order 1,n-1,2,n-2 ... upto n/2 — logn

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

Nested Binary Search on Answers solution of C. Time complexity is n(log2(n)^2)

348540251

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

is there a more rigorous proof for After cleaning out those ranges, we are left with at most n ranges ??

I get the intuition that it's true but I couldn't make sure that that's actually the case.

My thinking is that

  1. If we assume that there's no overlapping segment, then $$$|q|$$$ would be at most $$$n$$$ by having $$$[1,1],[2,2],[3,3],...,[n,n]$$$

  2. If we assume that there's overlapping segment, then $$$|q|$$$ would be at most $$$n-1$$$ by having $$$[1,2],[2,3],...,[n-1,n]$$$.

But I still couldn't ensure my mind enough that clearing those segment will result in no-nesting $$$q$$$ with having $$$|q| \lt = n$$$

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

For problem B:

First,we begin by mapping each element $$$p_i$$$ to a point $$$(i,p_i)$$$ on the plane. The given operation is then equivalent to setting the value $$$s_i$$$ to 1 for every point $$$(i,p_i)$$$ that lies within a specified rectangle.

Second,though painting we can know there is only four useful points: $$$(1,p_1),(n,p_n),(mn,p_{mn}),(mx,p_{mx})$$$.Then you will find the solution immediately.

349532383

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

O(n) solution for C ->353668810

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

D is amazing!

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

good for D

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

Can anybody explain the check function in problem C solution? Like is the straight line through first row or the second row not count? That is what it seems like to me..

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

D was amazing

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

Problem C can also be solved with binary search as you can loop through each number from 1 to 2N (letting the left bound be the current number) and greedily finding the lowest endpoint you can match it with since you know that every endpoint greater than that is sufficient as well.

Submission: 361215529

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