We will hold AtCoder Beginner Contest 153.

- Contest URL: https://atcoder.jp/contests/abc153
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20200126T2100&p1=248
- Duration: 100 minutes
- Number of Tasks: 6
- Writer: kyopro_friends
- Rated range: ~ 1999

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

We are looking forward to your participation!

What's wrong?

No problem now

Who know how to do E?

The contest hasn't finished, I suppose.

When ppl take advantage of an easy contest.

Question E and question F can be done if you think about them.Come on！！！

does E need backtracking ?

No comment during the game.

Correct soln is —

Soln of Ehere

XD

I like this kind of "to simple contest", allways makes me feel like a champion!

How to solve Question E?? Thanks in Advance

Making a 2d dp would solve the problem. It's just like the standard minchange problem.

just simple Knapsack my submission

Let's say the monster current health is H. You can try any of the nth spell( can cast multiple times), the magic points increased would be B[i] and the remaining health would be H-A[i]. Overall complexity would be O(H*N) .

If I cast nth spell 4 times then the magic points increased would be 4*B[i] and remaining health would be H-(4*A[i]).

Yes

You can use dp[health] as minimum spells required to decrease health to 0.

Now as health has max limit of 10^4 and N spells as 10^3. You can iterate over each health from 0 to H and update your answer for dp[health].

i.e the recurrence is :

dp[health] = Summation_of_i_from_(0 to n)min(dp[health — a[i]) + b[i], dp[health]).

i.e you check by including all spells and get the best one.

Then, the answer is just dp[H].

Submission

If you're using python, O(H*N) (10^7) might be too much. Especially if you use a top-down memoized solution.

Turns out you can prune some of recursive calls if you sort the spells by highest attack per mana cost and break early when the min stops decreasing.

I can't prove that this is correct but it AC'd during the contest. Is it actually correct and if so can someone provide a proof?

Python code: https://pastebin.com/rTLWJXba

Screencast + brief explanation

how to solve F? anyone please.

Editorial By MrGary

Acin>>h>>a; cout<<(h+a-1)/a<<endl;

Bif (∑ai)>=h the answer is "Yes"

else "No"

CJust greedy.

use the

Special Moveonly on the k monsters who have the biggestHi.and the answer is the sum of the rest monsters'

HiDconsider a tree like this:

now you can see that the answer is the number of the vertex of the tree

Edp[j] means that if the health of the monster is j , the minimum cost .(if the health is <0 , j=0)

consider the i-th spell :use dp[j] to update others.

dp[max(0,j-a[i])]=min(dp[max(0,j-a[i])],dp[j]+b[i])

Answer is dp[0]

Total

O(H*N)FFirst sort all the monsters according to

Xi.Clearly , to kill the left most monster(the first monster) we must use the bombs (h[i]+A-1)/A times .In order to attack more monsters ,we must let the left end point of the array be x1 .

Then consider the second ,third ...

But when considering the i-th monster,we must know how how many attacks he has faced before.And update its health.

To do this we need make some marks(Where a bomb array end).When meeting a mark the previous attacks will minus this.

We can use Binary_Search to make the marks

Total in O(nlogn)!

All of my submissions. ( https://atcoder.jp/contests/abc153/submissions?f.User=Gary)

You give others a link of "my submissions" and will turn to our own submissions!

When you are too excited to post editorials #me

？

This would be the link to all your submissions: https://atcoder.jp/contests/abc153/submissions?f.User=Gary

Your submission link will direct everyone's personal submission. Can you provide the link differently?

Fixed now.

can you tell me what is wrong in my solution. https://atcoder.jp/contests/abc153/submissions/9768886

Might be that priority queue gives you the largest element by default

Oh got it, i wrote the comparator wrong. Thnx

can you elaborate on how to implement the binary search part

F can be solved in O(N) solution

The standard library sorting algorithm is O(N log N), not O(N).

yeah because of sorting, but no need for binary search

Ah, I see. I thought you were saying you found a solution that is O(N) overall

thanks I got it now

Can you explain how it works?

Surprised to see an easy F. Also my E passed, but I am using $$$H*10^4$$$ operations, which means $$$10^8$$$ operations in worst case. Was this intended to pass?

https://atcoder.jp/contests/abc153/submissions/9758669

H = 10^4 N = 10^3 not 10^4 so O(10^7).

No I am ignoring N. I am doing 10^4 operations compulsorily for each H. Though yeah, I think O(H*N) was the intended complexity.

i know that at most we can do 4 * 10^7 iteration and the problem time is 2s so 10^8 / 2 * (4 * 10 ^ 7) = 1.25s so it should pass.

That's 1.25 times the amount of time within which the solution the should pass and not 1.25 seconds.

I don't get that.

No, that's not how it works. My $$$O(H*10^4)$$$ solution finished off in 118 ms.

https://atcoder.jp/contests/abc153/submissions/9758669

You can easily do 10^8 very SIMPLE operations (which is applicable in this case) in 1 second, in C++ on almost any platform. Multiplication, Division and Modulus are heavy operations, may not work. But mine is simple comparison. Sometimes even 10^9 operations can pass in 1 second.

Aha i got that thanks for this information.

Can anyone explained more details how to solve problem E ? thanks in advance !

U can use a single dp state. let dp[i] be the minimum cost required to make i tend to zero. so ur answer is dp[h].

Now let there be an intermediate state j and i be the presesnt start then

https://atcoder.jp/contests/abc153/submissions/9765139

u can refer to my solution it's easy to understand

I couldn't solve E for 87 minutes and it was because I was so impatient, trying out greedy solutions that I assumed would work and not waiting or thinking long enough before I implemented.

I didn't solve E too,and first I think it is greedy,after I looked the other's code,it is dp? :)

Yeah same thing happened with me as well.

here is my submission for the problem E , you can see my code for understanding.)

Problem F:Can someone please find what's wrong in this code? I have used two pointer to solve it.What's wrong in this solution of F?

link

line 38 and 41 use 'd' instead of 'a'

Thanks :)

As a monster, I feel violated by this round.

Submission

Can someone please explain why this times out even after using memoization?

You have $$$O(NH)$$$ states. For each state you do $$$O(H)$$$ calculations, so the overall complexity is $$$O(NH^2)$$$, which is not feasible for the given constraints.

You can calculate the answer for each state in $$$O(1)$$$, so the overall complexity will be $$$O(NH)$$$. Replace the while loop with:

`solve(h, i + 1, n)`

indicates that we decide not to use spell`i`

.`solve(h - a[i], i, n) + b[i]`

indicates that we use spell`i`

. Note, that we don't advance to the next spell yet, because we may want to use spell`i`

several times, and this allows us to avoid using the while loop.Sidenote: It is actually possible to "squeeze" your solution. Notice, that if all`a[i]`

were different, thetotal complexitywould improve from $$$O(NH^2)$$$ to $$$O(H^2\log H)$$$, by the Harmonic series argument (see this or this). And for this problem it is possible to make all`a[i]`

different, because for each unique`a[i]`

we are only interested in the smallest cost`b[i]`

. See this submission, which barely fits in the 2s TL with a couple of optimizations.Edit: I just realized that the complexity of the second solution is probably $$$O(H^2\log H)$$$ rather than $$$O(NH\ log H)$$$.

Thanks

Why does this solution to problem F fail?

I reckon that there is no problem with the main part...

Link

Maybe it's the sqrt decomposition part? I copied it from a template...

(The complexity is $$$O(n\sqrt{n}\log n )$$$, should be able to pass...)

In your binary search you don't seem to be using

`mid`

variable. Maybe the check's supposed to be`m[mid].x <= atkrange`

?Fixed, it failed one more case.

HOw to solve the question F ???