lunchbox's blog

By lunchbox, 11 months ago, In English

This post contains the editorials for all tasks contained in the AtCoder DP Contest, since there is no official editorial. This is written by nwatx and me.

A — Frog 1

Analysis
Code

B — Frog 2

Analysis
Code

C — Vacation

Analysis
Code

D — Knapsack 1

Analysis
Code

E — Knapsack 2

Analysis
Code

F — LCS

Analysis
Code

G — Longest Path

Analysis
Code

H — Grid 1

Analysis
Code

I — Coins

Analysis
Code

J — Sushi

Analysis
Code

K — Stones

Analysis
Code

L — Deque

Analysis
Code

M — Candies

Analysis
Code

N — Slimes

Analysis
Code

O — Matching

Analysis
Code

P — Independent Set

Analysis
Code

Q — Flowers

Analysis
Code

R — Walk

Analysis
Code

S — Digit Sum

Analysis
Code

T — Permutation

Analysis
Code

U — Grouping

Analysis
Code

V — Subtrees

Analysis

W — Intervals

Analysis
Code

X — Towers

Analysis
Code

Y — Grids 2

Analysis
Code

Z — Frog 3

Analysis
Code
 
 
 
 
  • Vote: I like it
  • +242
  • Vote: I do not like it

»
11 months ago, # |
  Vote: I like it +3 Vote: I do not like it

LUNCHBOX OFZ

»
11 months ago, # |
  Vote: I like it +16 Vote: I do not like it

LUNCHBOFZ

»
11 months ago, # |
Rev. 2   Vote: I like it +20 Vote: I do not like it

Someone finally wrote one!

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

Thanks a lot! It will be really helpful :)

»
11 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Good Job,,, I was waiting for this from ages. Thanks a lot ... OFZ

»
11 months ago, # |
  Vote: I like it +13 Vote: I do not like it

​I’m telling you, lunchbox is as cracked as he is jacked. Saw him the other day benching 696lbs while winning IOI. I asked him what he was doing and he said "better than you" and walked out with a explosion.

»
11 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Thank you very much. I was solving these problems for past 2-3 days but couldn't find editorial. What a nice timing.

»
11 months ago, # |
  Vote: I like it +3 Vote: I do not like it

For the problem T-Permutation, I came up with the following idea: We first create n-1 edges directed from small numbered index to large numbered index. i.e. if we have $$$i^{th}$$$ sign as $$$<$$$ then we create an edge from $$$i$$$ to $$$i+1$$$. Now, the answer is the number of topological orderings for this graph. But I am stuck here. Can anybody help me how can I find the answer? Thanks in advance.

»
11 months ago, # |
  Vote: I like it +14 Vote: I do not like it

I can't find the Editorial for N — Slimes anywhere in this post... Am I missing something?

»
11 months ago, # |
  Vote: I like it +3 Vote: I do not like it

This is one of the best list which covers all varients of Dp and gradient starting from absolute beginners. Very nicely written Analysis and Code! Thanks a lot:)

»
10 months ago, # |
Rev. 10   Vote: I like it +10 Vote: I do not like it

For task U(Grouping), you can reduce finding cost[mask] from $$$O(2^n \cdot n^2)$$$ to $$$O(2^n\cdot n)$$$ by doing like this.

Spoiler
»
10 months ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

I think in the analysis of W-Intervals the range is supposed to be [0,l-1] not [0,a-1]. lunchbox

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

sed

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

Time complexity for K is wrong.

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

Can someone explain problem L more clearly? Why is the transitions like that, and why in the analysis dp[i][i] = 0 but in the code dp[i][i] = a[i]?

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

    Errichto explained it well on his stream about that contest.

    In case you didn't saw that

    The transition formula , can be rephrased in that way.

    "Pick up the left bound , the opponent will pick up the best value on interval dp[L + 1][R]. The difference between your turn and opponents' next turn will be your answer for that interval.

    Pick up the right bound , the opponents will pick up the best value on interval dp[L][R — 1]. The difference betwene your turn and opponents' next turn will be your answer for that interval.

    Find max between these two choices."

    Can't explain why dp[i][i] = 0 in analysis , while in the actual implementation dp[i][i] = a[i].

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

I am not able to understand problem E editorial, Can anyone please explain it more ? Editorials are awesome thanks for editorial It helped me a lot, but anyone please explain E editorial

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

In problem J, in the memo function, why are we adding n to the expected value ?

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

    It's a bit late but (n-x-y-z)/(x+y+z) is the contribution of the expected value of wasted choices because (n-x-y-z) is the number of empty plates and we know that E[wasted]=(x+y+z)/N(E[wasted]+1). Now after that they need to add another (x+y+z)/(x+y+z) AKA 1 because that is the "price" of transitioning from the smaller states. So they just put the two together into (n-x-y-z+x+y+z)/(x+y+z) ==> n/(x+y+z)

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

in the Q question, you can use lis instead of segment tree. https://atcoder.jp/contests/dp/submissions/28292226

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

Sorry for necroposting, but since I found Problem J (Sushi)'s solution a bit confusing, am posting my approach here.
E(x) = Σ(pi*xi)
So for each 3d DP state (one, two, three), we can divide the event-space into 4 mutually exclusive groups: P(1 being selected), P(2 being selected), P(3 being selected), and P(none of these being selected). Since an infinite number of steps are required for the last group, it's probability approaches 0 and so can be ignored.
Now, the xi of each of these 3 states can be calculated as a sum of 'Number of steps taken to finally select a dish belonging to this group' and the expectation of the state that will be reached as a result of selecting an element belonging to this group.
Now here too, the number of steps taken can be infinite, and so we can use a suitable epsilon to limit our processing to only the first few states as the value added becomes negligible after a while.

My Submission
»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Thank you very much

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

Hey, could anyone here tell me why a greedy approach to N — Slimes might fail? What I'm doing is maintaining a multiset of all the slimes. At each iteration take out the two least weighted slimes, increment my total cost by their sum, erase the two slimes, and insert the sum of their weights into the set. This passes 50% of the test cases but fails the rest, any clue?

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

Thanx for ur all great efforts ^w^

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

I had to do a double take at this code from Problem U. What does it do?

for (int k = j; k; k = (k - 1) & j)
»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Actually the time complexity for problem K — Stones is O(N * K)

Any way thanks for the awesome editorial, that helps a lot <3