Vovuh's blog

By Vovuh, history, 6 months ago, In English,

1157A - Reachable Numbers

Idea: BledDest

Tutorial
Solution

1157B - Long Number

Idea: BledDest

Tutorial
Solution

1157C1 - Increasing Subsequence (easy version)

Idea: MikeMirzayanov

Tutorial
Solution

1157C2 - Increasing Subsequence (hard version)

Idea: MikeMirzayanov

Tutorial
Solution

1157D - N Problems During K Days

Idea: MikeMirzayanov

Tutorial
Solution

1157E - Minimum Array

Idea: Vovuh

Tutorial
Solution

1157F - Maximum Balanced Circle

Idea: MikeMirzayanov

Tutorial
Solution

1157G - Inverse of Rows and Columns

Idea: Vovuh

This is the comment about the quadratic solution. Thank you so much for mentioning this fact, STommydx!

Tutorial
Solution
 
 
 
 
  • Vote: I like it
  • +34
  • Vote: I do not like it

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

The editorial for Problem G looks like a little the editorial of Problem F

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

    Thank you for mentioning, I just forgot to fix this place :)

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

it was a greedy contest :D Good round by the way

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

My solution problem D after contest(sad): 1)Find minimum first element with binary search 2) let's get maximum suffix, when we can add 1 for all numbers on segment, do it, while exist this is segment 3) end O(nLogn), and write easy

https://codeforces.com/contest/1157/submission/53393728

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

In problem "A" we don't need to store reachable numbers ,As soon as we hit a number less than 10 we add 9 to our counter and stop

Nice problems btw
»
6 months ago, # |
  Vote: I like it +8 Vote: I do not like it

1157D — N Problems During K Days can be solved simply by putting $$$1,2,\dots,k$$$ initially and then trying to put $$$(n-(k*(k+1)/2))/k$$$ elements in each, and then from reverse order adding as many elements in each position as possible, without considering special cases separately.

You can go through my submission for clear understanding.

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

In problem number B, why we are not checking the digits which comes after the first digit which become less after replacing.

for example 
if a = 13373
and f[] = {1, 2, 5, 4, 6, 6, 3, 1, 9};
then the correct answer is 15573 but why not 15575;
  • »
    »
    6 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The problem mentions a contiguous subsegment and the operation can be performed at most once.

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

Anyone help me in finding the cause of TLE in Problem D in my solution.

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

    "erase" for vector works in linear time of size of the whole vector

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

      And what about erase in multiset?

      Is there any way that I can still use vector and solve the problem. I know that using multiset will make it very easy but still as a matter of knowing.

      BTW, Thanks for the reply buddy !!

      • »
        »
        »
        »
        6 months ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        You can’t use vector.erase for this problem. unless you want to code yourself a multiset libary for vectors, multiset is the only way to solve the problem in AC time, which erases elements from the container at log(n) time.

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

This problem also has a solution like D:

https://www.codechef.com/SNCK1B19/problems/MAXPRODU

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

please help me...y its showing error in test case 15 always!!!

https://codeforces.com/contest/1157/submission/53440011

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

    make it a habit to write long codes, your is too short to get accepted

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

Does anyone have a solution for problem E which does not involve STL structures, specifically without using multiset,set,map or multimap ?

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

Help me out in finding TLE in my Solution for Problem C

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

In problem E, why "lower_bound(m.begin(), m.end(), val)" gives TLE 53488500 and "m.lower_bound(val)" got Accepted 53488794 ?

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

Problem D: "Then if nn != k — 1 or k = 1 then this answer is correct."

Any explanation for this ?

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

For problem 1157c1, what if the input is

7 7 4 5 6 3 2 1

The solution code out puts 5 RRRRL But if I discard 7 and take the subsequence [4 5 6 3 2 1],it's possible to get a strictly increasing subsequence of size 6, right?

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

When is the next div3?

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

What's wrong with my solution for problem B? https://codeforces.com/contest/1157/submission/53566680 I am getting wrong answer on test case 7

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

    Try for
    5
    43111
    9 2 3 5 1 1 1 1 1
    Answer should be : 53999, get it?

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

I solved D in a different way. Mine

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

I'm kind of late, but problem D can be easily (more or less) solved by binary searching the first element, and then binary searching every other element as well, from left to right, so that the minimum possible sum is <= n and the maximum possible sum is >= n. My submission

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

Nice Problem Set.

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

For the D problem, I just initialized array to 1,2,...,K then added (S — (K * (K + 1)) / 2) / N to every element in the array, and then just distributed (S — (K * (K + 1)) / 2) % N from the behind appropriately. Just wondering why there were so less submissions for this problem?

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

How to solve problem Minimum Array using segment trees??

  • »
    »
    6 months ago, # ^ |
    Rev. 5   Vote: I like it 0 Vote: I do not like it

    I solved with segment tree, so I will try to explain my solution:

    First we need to sort B array, to be able to find some index j for each $$$A_i$$$ such that $$$A_i + B_l \lt n$$$ for all $$$l \lt j$$$, and $$$A_i + B_r \ge n$$$ for all $$$r \ge j$$$. We'll have only one index j for each $$$A_i$$$, because $$$max(A) + max(B) < 2n$$$.

    After that we can divide B array in two parts and find the best among these greedly, using segment tree here to get minimum, and then updating the used element to not be taken more than once.

    Submission

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

can anyone please tell why my recursive solution for c2 gives tle ? I think my solution too has the same time complexity as the editorial's .

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

Guys can someone help me understand why http://codeforces.com/contest/1157/submission/53985650 gives wrong results on test case 9

»
2 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
Your code here...

//why it doesn't work for problem B

include<bits/stdc++.h>

using namespace std; int main() { char x[10]; int n,i,f=0,t1,t2; string p; cin >> n; cin >> p; for(i=1;i<=9;i++) cin >> x[i]; for(i=0;i<p.size();i++) { t1=p[i]-'0'; t2=x[t1]-'0'; // cout << t1 << " " << t2 << endl; if(t2>t1) { p[i]=x[t1]; f=1; } else if(f==1) { break; }

} cout << p << endl;

}

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

/*what's going on the problem C2 it give the right answer for test case 1 in online compiler but in the cf compiler shows wrong answer.I submitted this code in gnu c++17 */ https://codeforces.com/contest/1157/submission/61860615