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

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

Sorry for misjudging the difficulty of problem D, but we still hope you enjoyed the problems!

2119A - Add or XOR

Author: CutieSmileHaruka

Hint 1
Hint 2
Tutorial
Implementation

2119B - Line Segments

Author: Lyz09

Hint 1
Hint 2
Tutorial
Implementation 1
Implementation 2

2119C - A Good Problem

Author: lizhous Preparation: Lyz09

Hint 1
Hint 2
Hint 3
Tutorial
Implementation

2119D - Token Removing

Author: CutieSmileHaruka

Hint 1
Tutorial
Implementation

2119E - And Constraint

Author: ma2021tyoi0037

Hint 1
Hint 2
Tutorial
Implementation

2119F - Volcanic Eruptions

Author: lizhous

Hint 1
Hint 2
Hint 3
Tutorial
Implementation
Разбор задач Codeforces Round 1035 (Div. 2)
  • Проголосовать: нравится
  • +76
  • Проголосовать: не нравится

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

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

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

D is interesting and easy to code.

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

ABC were easy

D was just chinese for me. Hope to learn and be better for next contest. Learnt about the reverse the Summation Technique.

Thanks for the problems :)

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

I see that problems so hard, and editorial too

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

Can someone explain the solution to E in simpler words? "preceding bits", "next bit" are context-less. And what is meant by "Numbers not on this step are certainly useless"?

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

Hope you guys can check out the solution explanations I wrote — I've shared some of my thoughts on these problems and approaches to solving them.

My solution of Problem A, D, E, F

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

Could someone make an editorial for the editorial of D please? What is the meaning behind mentioned segments? What are the $$$l_i$$$ and $$$r_i$$$ stands for?..

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

    This is how I understand it:

    For each valid sequence $$$a$$$ of length $$$n$$$, $$$f(a)$$$ is the number of arrays $$$p_0 \gt p_1 \gt ... \gt p_{k-1} \gt 0$$$ for all $$$k \in \{0,1,...,n\}$$$ such that $$$p_0,...,p_{k-1}$$$ is an order of removing tokens based on sequence $$$a$$$.

    We wouldn't compute our answer directly as:

    $$$\sum_{\text{valid seq a}}f(a)$$$

    over all $$$(n+1)!$$$ array. What we do is denote $$$g(p)$$$ as the number of valid sequences $$$a$$$ that possess $$$p$$$ as an order of removing tokens, then compute:

    $$$\sum_{p}g(p)$$$

    over all $$$p$$$. Turns out $$$g(p) = \prod_{i=0}^{k-1}p_i(n-p_i + 1 - i)$$$ as in the editorial. Proof is shown below.

    For each array $$$p_0 \gt p_1 \gt ... \gt p_{k-1} \gt 0$$$, we'll consider any valid sequence $$$a$$$ that owns $$$p$$$ as an order of token removal. Suppose $$$a_{x_0}, a_{x_1}, ... a_{x_{k-1}}$$$ corresponds to such $$$p$$$, in other words on the $$$x_j$$$ turn, we remove token $$$p_j$$$. ($$$x_0,...x_{k-1}$$$ are all indices where $$$a \gt 0$$$)

    Consider $$$p_0$$$, based on the problem statement, $$$p_0 \in [a_{x_0}, x_0]$$$. With this inequality, we conclude that there are $$$p_0(n - p_0 + 1)$$$ ways to choose value and position for $$$a_{x_0}$$$ accordingly. With the same argument you can obtain $$$g(p) = \prod_{i=0}^{k-1}p_i(n-p_i + 1 - i)$$$. The operator "$$$-i$$$" is due to the fact that we have already chosen $$$i$$$ positions $$$x_0,...x_{i-1}$$$ beforehand.

    I assume what the author meant was that $$$l_i, r_i$$$ are the number of ways to choose value and index for $$$a_{x_i}$$$ respectively.

    Finally for the dp part. For a fixed $$$n$$$, our answer is sum of:

    $$$h(k) = \sum_{\text{p of length k}}g(p)$$$

    over all $k \in \{ 0,1,...,n \}$. The definition of $$$f[i][j]$$$ array is:

    "Value of function $$$h$$$, evaluated over arrays $$$p$$$ of length $$$i-j$$$, whose last element $$$p_{i-j-1} \geq n-i+1$$$".

    Now $$$f[i][j]$$$ is computed by considering two distinct cases of $$$p[i-j-1]$$$, if it's equal to $$$n-i+1$$$ then by substituting in, we obtain $$$(n-i+1)(j+1)f[i-1][j]$$$ ($$$i-1$$$ because then the lowerbound of $$$p[i-j-2]$$$ is $$$n-i+2$$$). For the latter case, $$$p[i-j-1] \geq n-i+2$$$ so we obtain $$$f[i-1][j-1]$$$.

    So $$$f[n][j]$$$ would be our answer computed on arrays $$$p$$$ of length $$$n-j$$$, whose last element has lowerbound of 1 (a.k.a $$$h[n-j]$$$). Taking the sum for $$$j$$$ from $$$0$$$ to $$$n$$$ would give us the answer.

    I thought to myself why didn't the author simply choose $$$i$$$ as the length of array $$$p$$$ and $$$j$$$ as the lowerbound for $$$p_{i-1}$$$ but turns out that recurrence would ask us to compute $$$f[i][j]$$$ via $$$f[i-1][j+1]$$$ and $$$f[i][j+1]$$$ which is very annoying.

    Edit: Nah not annoying at all, even easier :> 327921559

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

    This is how i understand it: (after the Umnik video) You can convert it to a take not take dp and since a token can only be picked from positions greater than equal to where it resides it gives us the idea that we can start iterating from the back.

    let dp[i][j] be the number of ways to pick j tokens from [i,n] tokens; now for the transitions if we dont choose the ith token then dp[i][j] is just dp[i+1][j] else we choose the ith token now there are (n+1-i) positions who could have chosen the ith token (remember that a particular token can only be picked up by a larger or equal position) and out of these (n+1-i), j-1 have already been used so that leaves (n+2-(i+j)) positions on the right that can choose this token.

    Now this is where l[i] comes in because there can be multiple different arrays that pick the tokens in the same order and we have to count all of them!

    for a position to be able to pick token i the value at that position should less than equal to i (remember the range [a[k],k] so there are i options for this left boundary thus for the take transition we get : dp[i][j] += dp[i+1][j-1]*(i)*(n+2-(i+j)).

    hope it's clear : 327920799

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

    I am not even sure if this is just language gap.

    Hint doesn't help at all.

    They assume too much of stuff as obvious, easy to catch and simply skip over it. It really hurts my two brain cells.

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

Why can't i output l when k <= 2 in C?

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

I think the gap between problem C and problem D difficulties was way big.

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

Can anyone help me with B?

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

Hi, could someone explain the other solutions to Problem D? I noticed different approaches, and some of the code looks quite interesting. I'd love to understand the reasoning behind them.

Such as following solution

	vector<num> dp(N+1, 0);
	dp[0] = 1;
	for(int x = N; x >= 1; x--){
		vector<num> ndp = dp;
		for(int i = 0; i < N; i++) ndp[i+1] += dp[i];
		dp = ndp;
		for(int i = 1; i <= N; i++){
			ndp[i-1] += ndp[i] * num(i) * num(x);
		}
		dp = ndp;
	}
	cout << dp[0] << '\n';
»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Did anyone solve B by managing rings that are covered as we add a's gradually? For example, if a=[5,3,...] after step 2 we know that every point with distance [5-3, 5+3] is covered, simply by looking at how circle centered at distance 5 and radius 3 is moving around the circle with distance 5.

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

One mindless solution to Problem A is to apply Dijkstra's algorithm, whose complexity is acceptable.

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

~~~~~~~~~~~~~~~~

include

using namespace std;

define ll long long

int main() { int t; cin >> t; while(t--){

ll n, l, r, k , ans;  
cin >> n >> l >> r >> k;
bool found = 0;

if(n == 2){
  cout << -1 << "\n";
}else if(n % 2 == 1){
  cout << l << "\n";
}else{ // n even
  if(k <= n - 2){
     cout << l << "\n";
  }else{

    for(ll i = l + 1; i <= r; i++ ){
      if((i & l) == 0){
          ans = i;
         found = true;
         break;
      }

    }

    if(found){
      cout << ans << "\n";

    }else{
      cout << -1 << "\n" ;
    }
  }


}

}

}

~~~~~~~~~~~~~~~~~~~~~~ Why is this code wrong on test 3997? How can I know this test case?

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

    Learn to paste code in expandable section or share solution in [submission:2342341243]

    And you didn't specify which problem is this.

    Anyway, two problems with your code:

    else{ // n even
      if(k <= n - 2){
         cout << l << "\n";
      }else{
    

    1 if n is even you first need to check whether a solution exist or not. this step comes after that.

     for(ll i = l + 1; i <= r; i++ ){
          if((i & l) == 0){
              ans = i;
             found = true;
             break;
          }
    
        }
    

    2 this is slow imagine l = 1000000000000000000000000000001 i.e. $$$(2^{30} + 1)$$$

    your for loop will run $$$2^{30}$$$ times i.e. about 1 billion operations.

    better way to do so is for (i = 1; i < l; i * = 2)

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

For Problem C, can somebody explain why the tactic that a1 exor a2 exor .... an-2 = l doesn't work then why aren't we checking the same thing for l+1,l+2, ... r?

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

Can somebody explain why does $$$s_1 \leq \frac{S - m}{2} + \frac{\max(a_i)}{2} \leq m + s_2$$$ hold in B?

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

C was a good problem! I was able to guess the solution instantly but proving was satisfying.

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

That shows why i love Codeforces. It has a difficult thinking but easy coding. Thanks..

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

Есть ли у задачи B более простое решение? Или можно ли упростить авторское решение?

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

    На точке Q проводится окружность с радиусом r, равным наибольшему элементу массива a, и проверяется, может ли точка P коснуться этой окружности. В зависимости от расстояния d между точками P и Q (d ≥ r или d < r), знак выражения меняется.

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

For 2119D - Token Removing, here's my solution summary with visual explanation https://www.youtube.com/live/O0qbgoDUj0g?t=1962s

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

Really liked problem D and F.

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

can someone tell that in D why does counting the number of sequences work?because we were asked for number of ways right?

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

I see A B C D all four problems are interesting and challenging as well and qsn D takes more than four hours to understand the eaxactly the solution after attempting.

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

In problem F, one can compensate for the inability to make a few observations by bashing with an ugly centroid decomposition

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

The definition of $$$f(i, j)$$$ in the editorial of D is very weird to me. Isn't it more intuitive to define $$$i$$$ as the length of the token sequence and $$$j$$$ as the lower bound of the last token index? I get that the author's solution is perfectly valid, but it is weird to me that $$$i-j$$$ represents the length of the token sequence.