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

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

We will hold Toyota Programming Contest 2024#3 (AtCoder Beginner Contest 344).

We are looking forward to your participation!

  • Проголосовать: нравится
  • +42
  • Проголосовать: не нравится

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

Good luck to everyone:)

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

Hope G be as friendly as previous rounds.

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

Good luck to everyone!

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

[Deleted]

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

why T.size() — sz gives some random large value wasted 1hr debugging this

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

    Because sz can be larger than T.size(), and since T.size() is an unsigned int it will overflow when doing the subtraction.

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

      oh thanks! didn't know about this.

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

        It is strange though. Looking better at your code both the numbers are integers, so it should give you an integer and not unsigned. Idk if what I told you above is right.

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

          Sorry the code I attached is correct ac code which I submitted after debugging

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

Same idea problem to E, D. Berserk Monsters

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

Any hint for problem 'E — Insert or Erase' would be appreciated.

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

Can anyone help me with my submission of Problem E:-

My logic is maintaining 2 maps, one for storing the next element and one for storing the previous element.

It's failing on 2 test cases :- random_12.txt and random_21.txt

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

I feel a little confused about the editorial of problem F. The dp state is dp[i][j][pmax] = pair<number of action, current earned money>. I think the editorial means that, for the same pmax, there can only be one single optimal pair of <number of action, current earned money>.

But, we can reach cell (i,j) from different ways, and I think it is possible that, there are two ways, so that, we have the same pmax, but different <(number of action)_1, (current earned money)_1>, and <(number of action)_2, (current earned money)_2>, where (number of action)_1 is less than (number of action)_2, while (current earned money)_1 is "very very"" less than (current earned money)_2.

In other words, one of the way has more actions, but very very much earned money, and how to determine which one is better? If it can not be determined, then the number of states may be much more larger than O(N^4)

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

    You are confusing DP states with DP values. You are also confusing current earned money with the left over money. I've added more intuition for this DP solution on CF Step

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

    I have the same doubt I do not see how we can simply choose the less number of actions over more number of actions when we have money left under consideration too.

    What is the guarantee that this local optimization reflects globally as well.

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

      We are not, we actually evaluate both possibilities. As I discussed in my previous comment, if you have to spend 5 actions to go to the right cell with $$$p[i][j + 1] = 10$$$, and spend 10 actions to go to the down cell with $$$p[i + 1[j] = 300$$$, we do not discard the downward path, we actually consider both possibilities.

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

    I think this is the same confusion I had when I was doing the VC. I worked on a proof to understand why I had this misconception.

    Take a scenario where you are moving to cell (i, j) from previous cells (i, j — 1) and (i — 1, j) with the same pmax value. And suppose the pmax doesn't change at cell (i, j). These represent dp state transitions from (i, j — 1, pmax), (i — 1, j, pmax) -> (i, j, pmax).

    Suppose you have the following possible values for state (i, j, pmax), (a, x), where a = number of actions taken, x = leftover money. Now consider two competing values for the state (i, j, pmax) => (a, 0), (a + 1, pmax — 1). Note that the x is constrained because you only take what you need so leftover will always be x mod(pmax). If there is ever going to be a case where you'd take a value with more action because it has more leftover money this would certainly be it.

    • Consider if you transition to another adjacent cell (right or down) from both these values. Let's say the cost to transition is c.

    1) (a, 0) so to transition from the value (a, 0), you will need to spend some action on accumulating c money. so you will do it need this many more actions m = ceil(c / pmax), and you will be left with some left over money from the remainder of c divided by pmax. so (a, 0) -> (a + m + 1, c mod(pmax))

    example, cost = 10, pmax = 4, m = 3, and (a, 0) -> (a + 3 + 1, 2)

    2) (a + 1, pmax — 1) You will not have to spend as much action right, cause you had more leftover money. But you will still need m = ceil((c — pmax — 1) / pmax), and that will just reduce your number of actions to achieve the cost c by 1. So it just balances out, you spend 1 less action cancels the fact it was 1 more action. The extra money did not really help.

    example, cost = 10, pmax = 4, m = 2, because 10 — 3 = 7, and (a + 1, 3) -> (a + 1 + 2 + 1, 1). This is worse then the value above (a + 4, 2) vs (a + 4, 1).

    In general, I get a sense that you can only reduce number of actions by 1 by having more left over money. So it will at best be a tie in number of actions, but it will never lead to an output with fewer actions. And that is the reason you can take values with fewer actions regardless of money situation.

    I assumed pmax was constant in these transitions. But I believe if you plug in an increasing pmax in the same proof it follows for that as well. This only works because pmax is weakly increasing I realized when I went over this.

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

    Your question is given a dp state = $$$(i, j, pmax)$$$, how to compare two values of (min moves, money earned), say $$$(a, b)$$$ and $$$(a', b')$$$. We can indeed compare them lexicographically, i.e. if $$$a < a'$$$ or $$$(a = a'$$$ and $$$b > b')$$$ set dp(state) = $$$(a, b)$$$.

    So why is this optimal? Because when money is needed to make the transition it is as if we can use $$$pmax$$$ not just $$$p[i][j]$$$. This implies that there is no need to bring large money surpluses, you can always use $$$pmax$$$ if needed at a later move, so trade 1 action for $$$pmax$$$ money just enough to make the transition.

    Because, you use just enough actions to make the transition, the current money in the dp value is such that $$$b < pmax$$$ (if it were not the case we could do $$$a -= 1$$$, $$$b -= pmax$$$). So this actually implies that you can lexicographically compare the dp values has I stated before.

    Your scenario of having $$$a < a'$$$ and $$$b «< b'$$$ does not occur, as from state $$$(a, b)$$$ you can reach $$$(a + 1, b + pmax)$$$ and as argued $$$b + pmax > b'$$$.

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

      Thank you so much for your kind reply! I think your arguments really make sense, and I will try to think over this again.

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

    Hello I have put some thoughts after reading the replies in this comment section (Very helpful replies and I am very grateful to them)

    This is my proof.

    Claim:- The leftover money at any point in time is < pmax. This is the max over all P(i, j) from 1,1 till i, j

    Proof:- Let's assume leftover money is x and assume that we are updating dp for i + 1, j. The same can be done i, j + 1.

    So, if we directly took modulo with Pmax we would have (R(i, j) $$$-$$$ x) mod Pmax as the remainder. let's name it REM. Now we would have Pmax $$$-$$$ REM leftover money, always < Pmax.
    or
    x >= R(i, j) then trivially x $$$-$$$ R(i, j) < Pmax.

    The claim is proven. Suppose we had two (action, money leftover) pairs for i + 1, j. Let's take the worst possible case.

    A, 0
    A + 1, Pmax $$$-$$$ 1.

    We can see that with just 1 operation we can go from A, 0 to A + 1, Pmax. So taking the lower action count pair is always optimal.

    I have only made a more verbose comment over existing replies. It's just a more wordy version of the proof people already mentioned. Thanks once again!

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

      Nice proof! Also thank you so much for your great work. I think now I can convince myself that the solution in the editorial is completely correct. Thank you for your kind help!

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

Can we solve G with half-plane mo's algorithm? It's not well known I think and I'm unsure how to implement it. I suppose its time complexity is $$$\mathcal O(n\sqrt m)$$$.

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

Can you anyone help me understand why my dp code for D is returning -2147483648 for every input

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

    dp[k — 1] + 1 is overflowing intilize dp with some max value say 1e5 and the change last condition (== INT_MAX) to (> n) after doing this 53 / 58 test pass link

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

      Thanks for the reply, that was a silly error on my part. Is it solvable using 1D DP ?

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

        yes

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

          The idea seems almost similar to mine. Can you tell what does ndp do in your code ? Removing ndp passes all the testcases except one.Submission

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

            if you don't use ndp you have to make dp array of size n * T_size. if you just use 1D dp then the condition of taking atmost 1 string from the bag is not fulfilled

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

Given a collection of strings and a string t. Find the minimum string taken from the collection and join it to form the t.

Note: Collection has a finite number of strings i.e. each string can be taken once.

HOW TO SOLVE THIS EFFICIENTLY.

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

Problem D WA on a single test. Could anybody please help me find where the solution fails.

Thanks.

https://atcoder.jp/contests/abc344/submissions/51103999

UPDATE: Got it!

https://atcoder.jp/contests/abc344/submissions/51107878

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

Damn,everytime i participate in ABC i get to learn some new stuff and for this one i got to know about linked list using maps.Really interesting