chokudai's blog

By chokudai, history, 4 years ago,

We will hold AtCoder Beginner Contest 145.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

• +28

| Write comment?
 » 4 years ago, # |   0 How To Solve 'E'?
•  » » 4 years ago, # ^ |   +1 It's a standard knapsack problem, the only difference being that the order you want to eat the food in is increasing by A (you want the longest food you'll eat to be at the end)
•  » » » 4 years ago, # ^ | ← Rev. 2 →   0 I still didn't get , why sorting with respect to time gives AC. Can you please,explain?
•  » » » » 4 years ago, # ^ |   0 Because you want to eat a couple, and then the last one you eat can go over. Since it can go over and is not bounded by T, then the BEST one to go over is the largest one from the subset you selected. Formally if you have a subset of times A1, A2, A3 ... Ak, you can eat them iff, you have a subset of k-1 that is <= (T-1). Now you see that you want to remove the maximum one from the subset. Sorting it and doing a knapsack will guarantee that the last one is the added is the maximum one in the subset
•  » » 4 years ago, # ^ |   0 Let $dp[i][j]$ be maximal happiness you can achieve taking some of first i dishes during j minutes. Let $backdp[i][j]$ be maximal happiness you can achieve taking some of last dishes (with indices from i to n) during j minutes. Now let's go through the dish that we will eat last ($i$) and time we spent on eating first $i - 1$ dishes ($t'$). Try to update answer as $min(answer, dp[i - 1][t'] + backdp[i + 1][(t - 1) - t'] + b[i]$. It's easy to calc $dp$ : $dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - a[i]] + b[i]$ (if such exist)$)$. Same with $backdp$.
 » 4 years ago, # |   0 How to Solve D ?
•  » » 4 years ago, # ^ |   +1 If you print the matrix you notice that every third diagonal is part of pascals triangle (so just implement combinations and get the right row and column in the triangle)
•  » » » 4 years ago, # ^ |   0 Can you please detail more the idea and solution ?? Thanks
•  » » » » 4 years ago, # ^ |   0 To get to x, y from 0, 0 we have to do some (i + 1, j + 2) and some (i + 2, j + 1) moves. So, let's iterate how many times we will do (i + 1, j + 2) moves and check whether if moves left can be done with some number of (i + 2, j + 1). If the total number of moves is N, and we did K (i + 1, j + 2) type moves, number of ways to do it will be $C_{N}^{K}$
•  » » » 4 years ago, # ^ |   0 But how to implement combinations.I think it can't work when using mod.This worries me so much.
•  » » » » 4 years ago, # ^ | ← Rev. 2 →   +9 You can calculate factorials modulo n, store them in fact[x]; And then inverse of factorials modulo N. (since MOD is prime, invFact[n] = POW(fact[n], MOD-2))And since comb(a,b) = fact[a] / (fact[b] * fact[a-b]) modulo this meansfact[a] * invfact[a] * invfact[a-b].Edit: Tutorial that explains https://www.geeksforgeeks.org/compute-ncr-p-set-3-using-fermat-little-theorem/
•  » » » » » 4 years ago, # ^ |   0 Thanx
•  » » » » » 4 years ago, # ^ |   0 You also can use Extended Euclidean to find modular inverse. I prefer it more than fermat.link: You only need to read equations, so don't worry about language.
•  » » » 4 years ago, # ^ |   +1 Matrix
 » 4 years ago, # | ← Rev. 2 →   +13 DPcoder rip rating
 » 4 years ago, # |   0 what's the dp at F? plase
•  » » 4 years ago, # ^ | ← Rev. 2 →   +6 best[i][j][k] -> best cost if you only consider the first i columns, the i-th column has value j and you've done k changes already. (j is really big, but you notice that there's no use in changing in something that's not already in the input, or 0). (Note, since you only look 1 in the past with i, you can only store 0/1 for it) The big observation to make this fit in time is that if the previous one has height X, then if you change the current one, you don't want to make it shorter, since that won't decrease the cost, but might increase it in the future.
 » 4 years ago, # |   0 What is the after contest test case added for problem E All you can eat? My solution fails for it and passes the rest.