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

Автор jdurie, история, 23 месяца назад, По-английски
Tutorial is loading...
Solution
Tutorial is loading...
Solution
Tutorial is loading...
Solution
Tutorial is loading...
Solution
Tutorial is loading...
Solution
Tutorial is loading...
Solution
  • Проголосовать: нравится
  • +104
  • Проголосовать: не нравится

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

С sucks

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

Thanks for the fast editorial!

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

Fix picture for C please

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

Statement of Problem A was incomprehensible. These days, I feel that in cf contests it's not the problem that's hard but the way it's written which makes it harder to understand :/ Had to blindly solve it using the given test cases

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

Let $$$f[i][j][k]$$$ be whether there is a path whose end point is $$$(i, j)$$$ and the sum on the path is $$$k$$$.

We can use bitset to calculate this DP with a $$$O\left(\dfrac{nm(n + m)}{64}\right)$$$ complexity.

Submission: 161091846

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

    I am not able to get why is the time complexity divided by 64. Would be great if you could explain it.

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

      It's because of use of the bitset. I am not sure but I think each position contributes only 1 bit to the space complexity and not the space required for storing 64-bit integer (size of long long)

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

      The size of the bitset is roughly $$$\dfrac{(m+n-1)}2$$$. On 32 bit systems, bit operations on bitsets take $$$O(\dfrac{n}{32})$$$, where $$$n$$$ is the size of the bitset. This means each operation takes about $$$O(\dfrac{m+n}{64})$$$. Then, the loop makes it $$$O(\dfrac{nm(n+m)}{64})$$$.

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

    what is this line doing ?

    f[i][j] = (f[i - 1][j] | f[i][j - 1]) << a[i][j];
    
  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Same way with me and my submission is 161081121

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

If the editorial for D doesn't make sense, you can check out this one over here on page 17.

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится -15 Проголосовать: не нравится

[submission:161072909]Why is it wrong?

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

    because k is initialized by a[x][y], that means k equals 0 ( k=a[x][y]; )

    but when all the values in the grid are negative the result will be incorrect.

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

There is a solution that does not require any observation in D2 from D1 — just re-root the tree.|

First, calculate the answer for any root.

If you want to change u to v, push all changes into a stack, recalc dp[u] to what it was before you added v, then recalc v as if it is the root. Then, do it recursively for all children son such that son != u. After you finished, roll back the changes to dp. It takes O(1) to roll back, O(1) to recalc, so it is still O(n)

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

If you are/were getting a WA/RE verdict on problems from this contest, you can get the smallest possible counter example for your submission on cfstress.com. To do that, click on the relevant problem's link below, add your submission ID, and edit the table (or edit compressed parameters) to increase/decrease the constraints.

Divison 2

If you are not able to find a counter example even after changing the parameters, reply to this thread (only till the next 7 days), with links to your submission and ticket(s).

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

    Hello, it generated a wrong testcase for problem C. Ticket We can only have 1 or -1 in the grid, but it showing a testcase with 2.

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

      Hi, the generated testcase is actually correct.

      The input format is the same as the problem, so

      1
      1 2
      -1 1
      

      means that you have one testcase, where the number of rows is 1, number of columns is 2, and the elements are -1 1. (Here, 2 is the dimension of the matrix, not the matrix element).

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

Can anyone tell the answer to the test case:

8
2 1 3 4 3 6 2 8

according to cf stress test it should be joe but according to me winner will be mike as in 2nd iteration 2nd element will be already 0 that was joes pile.

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

    Here the winner is Mike as you said

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

      I am really dumb there was a typo in finding the minimum value in my code and due to that i was not able to get ac on b and wasted a lot of time and i suddenly noticed it now.

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

If anyone was curious, you can solve C with the bitset dp: https://codeforces.com/contest/1695/submission/161121586

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

I have some doubt about the solution to problem A. Consider following case:

1
4 4
0 -14 8 9 
17 -26 20 30 
21 5 -24 -19 
-7 -13 14 -4

Based on the solution, the answer is 12. But if we take a subrectangle with $$$(h, w) = (4, 3)$$$ and upper-left corner placing on $$$(1, 1)$$$, the maximum value inside is 21, which is not the global maximum value(30). So if Joe chooses this subrectangle, Michael will lose.

I think the answer should be 16. Am I missing something?

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

    Michael can instead take a subrectangle with $$$(h,w) = (3,4)$$$. this includes the global maximum wherever the subrectangle is.

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

      Oh, I completely forgot Michael was the one who chooses h, w values... Thanks!

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

I'm not gonna argue about the quality of the problems (there's already much argument going on), however I think the pretests for A was pretty much garbage

  1. 161068768 a solution which scans from -32768 got through pretests. this means that pretests didnt even have a testcase with less than -32768 as minimum

  2. 161081758 a weird solution, and I dont understand how it even went through the pretests

  3. 161078731 what even is this

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

Is there any way of using dfs in problem C?i can make a graph for possible path from a cell and apply dfs to check whether the sum is zero or not?

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

    In the worst case(when n,m = 1000), there would be 1998C999(1998 Choose 999) different paths from 1,1 to n,m. (This because we need to make 999 right turns and 999 down turns, so total 1998 turns. Just need to select 999 out of these for a right turn)

    Which would exceed the time limit easily.

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

I have done this contest with a really bad result and I think I need to say something. As a habbit, I always initialize the max = -999999999 and min = 999999999, my brain thinks 999999999 > 1e9 and actually I don't understand why I has not had any problems with this before. As you can easily guess, in this contest, I had problems with A.Subrectangle Guess and B.Circle Game. I should have solved A and B in under 15 minutes; I passed pre-tests of problem A, and I never think it will be terrible for me, until now. If I recieved WA in problem A, I would soon find the mistake(max = -999999999), because the idea is clear, I would not have to check the idea, I could concentrate on the code and find my mistake, I just lost 50 points, and next I would easily solve problem B and have over 1h30m to think promblem C or D1. But no, I recieved WA on test 3 in problem B, and although I could prove my idea is correct, I still spent the whole time to find the mistkae in my idea, until some last mintues, I found the mistake in my code, and I passed B on exactly the last minute, and did not have enough time to submit A. As a result, I did not pass the main test of problem A. Anyway, thank you for this contest, if I don't fail in this contest, maybe I will fail in the contests which are more important to me because of this mistake.

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

The tutorial doesn't have any hints and I don't want to see the solutions directly

Can someone give me some hints for problem E?

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится
    hint1
    hint2
    hint3
»
23 месяца назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

In problem D, you make your queries first and then you get the distance values, altogether... I'm writing this because I somehow missed/overlooked that crucial point while reading the problem. I guess some others may have unknowingly made the same mistake.

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

0-1 BFS also works for C with a deque.

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

Can someone please explain why 161082582 got accepted but 161062638 did not in prob A UPD: got it

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

Hey jdurie!

Feedback as a low-ranking coder:
  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится -11 Проголосовать: не нравится

    I don't agree at all, problem A was very clear and sample test cases for B were just horrible.

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

Problem B sample tests were horrible. It was very easy to get them correct. For example, I submited 8 times before getting AC.

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

nice solutions

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

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

Can someone tell the proof written for Problem C in the editorial in simpler words stating that we can get the sum as 0 if the maximum and minimum path sum ending at (n,m) cover's 0 if the max_sum >= 0 >= min_sum

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

    Basically they are saying that we can change the path that gave minimum sum to the path that gave maximum sum and on each step of changing that , sum will change by 2,0,-2 .

    Since we know that number of cells in any path = n+m-1 (which is even)

    Hence both min_sum and max_sum is also even ,

    and we are changing min_sum to max_sum by +-2 , so we will definitely hit 0 given that 0 is in the range of [min_sum,max_sum]

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

I guess in problem C's solution the condition for no path should be 0>minnm or maxnm<0 and not 0<minnm or maxnm<0. Please fix ig this is a typo.

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

Very understandable and clear editorial. Thank you! :)

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

I have not yet learned much, but i keep seeing dp in the discussions C and D. Can anyone explain what is dp ?

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

Can anyone explain the solution for E? Don't really understand why the order of dfs matters.

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

    I would explain it in a slightly different way, which is similar to the editorial's solution.

    For any dominoes $$$(a,\,b)$$$ we have, add an edge between node $$$a$$$ and $$$b$$$. Merging the two solutions, we found out that these dominoes form cycles. Therefore we may think about finding the Eulerian Cycle of the graph obtained by two copies of the dominoes. If we successfully found it, the solution is the odd edges and the even ones of the Eulerian Cycles. However, these cycles we found may not guarantee that two dominoes from the different copies have different parity. It can be solved by letting the same dominoes from the different copies be adjacent in the adjacent lists and all the adjacent lists have the same order of edges. Note this is the same we do in the editorial's solution. For each cycle, if the length is $$$2$$$ then there must be no solution, otherwise, we arrange them in a $$$2 \times \frac{\text{length}}{2}$$$ grid. It is always possible since each connected component contains an even number of edges.

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

The proof part of problem C is brilliant and that's what made the problem a bit hard in my opinion.

I was unsure before submitting my solution and got gently surprised when it got accepted.

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

Come on, I didn't even try to implement O(n^3) solution, since I thought it would be too slow. Turns out that it is under 1s even in java..

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

Why not just set $$$\sum n\times m \leq 10^7$$$ or else everyone will pass with $$$O(\dfrac{nm(n+m)}{w})$$$???

see this : https://codeforces.com/contest/1695/submission/161085118

I thought of this kind of way to solve in square time complexity, but i still decided to write the code above. However, you can just make the constraints much bigger, and maybe there will be most people coding the tutorial's solution.

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

    I don't think this solution should be hacked. At least it showed an important way to improve the time complexity($$$O(\frac{1}{\omega})$$$). In my point of view, various solutions are also important and inspiring.

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

For problem D1 Div2, in the editorial, can anyone explain the benefit of having this condition: we can assume that either v or some vertex not in the subtree of v has already been queried while calculating the answer.

Also D2 Div2, why is this statement true: The way we compute values in the DFS ensures that at least degree[root]−1≥2 subtrees of the root will have at least one query.

  • »
    »
    6 месяцев назад, # ^ |
    Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится
    • It looks like question is based on pigeonhole principle Atleast D2 is based on pigeonhole D1 also very similar but I am not quite confident about it
»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

I think Problem A has a subtle detail and would like to share it here.

We are not choosing a minimum area such that any rectangle >= that area covers the maxval.

Instead, we are choosing a minimum pair (h, w) such that any h*w rectangle covers the maxval, and by saying "minimum pair" I mean the pairs are ordered by the areas that they form.

Those two are different! For example, consider the following case.

1  2  3  4  5
6  7  8  9  10
11 12 99 14 15
16 17 18 19 20
21 22 23 24 25

If we follow the standard answer we get the pair (h, w) = (3, 3) such that any 3*3 rectangle covers 99. But it is not "a minimum area such that any area >= 9 covers 99", for example you can consider the following area.

1  2  3  4  5
6  7  8  9  10

It has an area 10 >= 9 but does not cover 99.

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

Though my rating dropped after the contest, I think it's a pretty good round.

Because it made me realize my poor ability in dp on tree :)

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

    That's a good example of positive mindset. I see a lotta people perform bad and start trolling the authors, problems or Codeforces itself.

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

Why the timelimit of E is 8s?

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

Hey everyone! Can someone please explain the solution for problem C? I do not see how does this proof in the editorial conclude there exists a zero path. Thanks in advance!

Statement from editorial I am confused about:

Therefore, because both minnm and maxnm are even, and minnm≤0≤maxnm, at some point in this sequence of operations, the sum of the path must be zero.
»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

got an FST on div2 A :(

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

In D2, how does querying any vertex with degree >= 3 will ensure the answer to be minimum. Why don't we need to do it for all vertices with degree >= 3?

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

    The $$$ans[v]$$$ can be understood as "the answer of an subtree with root $$$v$$$ if there are at least one query vertex not in this subtree." The condition that the degree of top most vertex $$$\ge 3$$$ is to guarantee for all the subtree, there are a least one query point not in it.

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

The Solution Given for "C", does this kind of algo have some name(belong some where like div & conq etc) or just plain problem solving

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

    Intermediate Value Theorem

    Other IMVT problem: https://www.codechef.com/problems/B01T

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

      Thanks bhai!

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

      I thought the intermediate value theorem was for continuous valued functions only? This is why I'm still not convinced with the proof for C. How can we say that just because

      $$$min_{nm} < 0 \text{ and } max_{nm} > 0 \Rightarrow \exists \text{ a path } p \text{ such that } \Sigma p = 0?$$$

      Can we prove that for every value between min and max there exists a path whose sum equals that value?

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

        The conditions which you're assuming is not sufficient. You are missing the change at every steps. Change at every step is 2, -2, 0. Previously it was negative even number and later positive even number and everytime there is a change of 2, -2, 0. So you'll get 0 for sure.

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

        The idea is that suppose you already have a path to achieve the max sum, and a path to achieve a minimum sum; the claim is that any sum (of the same parity) in between the max and min are achievable.

        Now, why should this hold true? The intuition here is that because paths only go right and down, you can convert the two paths between each other by a multiple operations of flipping a "turn" (i.e. if a turn goes right then down, make it go down then right). In particular, we note that each time we flip a turn, it can change the sum by at most absolute value 2. This happens when we step on a -1 instead of a 1 (or vice versa) as a result of flipping. (Note that a single flipping operation changes exactly one cell on the path.)

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

did anyone know why D2 only dfs a vertex more than two sub is ok, but not dfs all vertex which has more than two sub. i think the answer didn't say clearly

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

Problem C was a good one.

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

For problem D, what is the smallest k(the worst situation in any possible hidden-X with an optimal strategy) if we are able to use online query, instead of quering all the node at once?
Are they the same?
If not the same,what is the best optimal strategy?

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

    Let's try the following reasoning — root the tree at u — that is our first ask. For every ask concerning two sons, we can answer no as long as there are some other possibilities. This is very similar to our offline dp — we cannot toss out more than all sons by one query. So I think that the answer is the same.

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

For Problem-D2, why is it that performing our greedy DFS for any of the nodes with degree greater than 3 works?

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

Problem D is a known concept in graph theory called Metric dimension: https://en.wikipedia.org/wiki/Metric_dimension_(graph_theory)#Trees

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

D has appeared in previous competitions: https://atcoder.jp/contests/apc001/tasks/apc001_e

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

can anyone help me with memoising C

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

HOW TO SOLVE C USING BFS

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

Nice proof of Problem C

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

Can I get all the test samples for question C? Thanks.