We will hold Toyota Programming Contest 2025(AtCoder Beginner Contest 389).
- Contest URL: https://atcoder.jp/contests/abc389
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250118T2100&p1=248
- Duration: 100 minutes
- Writer: nok0, MtSaka, evima
- Tester: physics0523, kyopro_friends
- Rated range: ~ 1999
- The point values: 100-150-300-400-475-525-600
We are looking forward to your participation!
I'm happy to attend it and slove $$$5$$$ problems!
Hoping to do 5 problems
It's my first time to join this contest seriously.Good luck to me
Hoping to get 1200+ rating this time.GL
I just solved 4 problems and gave up. It is too hard for me.
Me too,but it's the best result for me now,i think.
man , i dont know why my c dont is correct , aaaaa
after the contest i post my c here
hope your answer
the logic is correct but need be more faster, i hate tle . ~~~~~ //this is code
include <bits/stdc++.h>
using namespace std;
define f first
define s second
typedef long long ll;
int main(){ int q; cin >> q;
} ~~~~~
Ey you dont have to make a copy of the queue, you can access in O(1) like a vector, just with queue[k-1] that's why u are having TLE
really , how i do that ?
cout << copia[k-1] — global << endl; Just like that, in case you have questions u can check my code :) CODE
after contest someone explain solution for D.
Sorry for my poor English.
Consider line
find the intersection of the lines with the circle and calc the total of the rectangle.
U'd better use Rectangular Coordinates. It can solve it quickly.
By the way, the problem is very similar to abc191_d.
Thanks
After contest, anyone explain approach for D and F, getting stuck in TLE :(
You can go at max r distance from the center in any direction.So, Move across the x-axis from [-r to r] and find the corresponding max y above[0,r]and lowest y below [-r,0] with binary search. 61834784
Can also use the equation of a circle. Fix values of x like 0.5,1.5,.... and just calculate the y . Since its a circle its symmetrical so you can just multiply by 2
What's wrong with this solution ?
I dont get what you are trying to do mate.
I used the equation (x*x+y*y=r*r) for circles, we know r , if we iterate over x from 0.5 we can find the maximum y for which this is valid. I start from the second square , go till the end , multiply this by 2 and then finally add the middle column once.
I'm trying to get the maximum count of squares above the root square. With symmetry , we can get the count for the 4 directions , similar logic for diagonal squares .
Oh ok , well im also doing the same thing i just caluclate apart from the base line as it only occurs once so what i do is calculate from above multipy it by 2 then add. After this i multiply this value by 2 for the whole circle then i manually add the center line which would have occured only once
I loved problem E,gave D an hour and still can't do it,i'm really bad at geometry.
Can you share your approach after the contest?
For D, first I calculated in first quadrant and than on the axes.
for D you could just oeis it
Looking at the number of ACs on Problem D, it was really disappointing that I couldn’t come up with the solution. Can anyone explain the solution to Problem D?
you can binary search for $$$y$$$ for each $$$x$$$
can you share your submission link
https://atcoder.jp/contests/abc389/submissions/61814693
This isn't necessary. After dividing the circle into four equal parts according to the direction of the square's edges, we find that y is monotonically decreasing with respect to x. https://atcoder.jp/contests/abc389/submissions/61805834
did same
had a pretty short solution just iterated on neighboring distance and calculated possible number of square by calculating the xth square which will be last for this horizontal distance
What wrong with this mathematical solution ?
Can anyone point out ?
E was a bit painful
My thought process on $$$F$$$.
"Maybe I can avoid it? Let's try another idea."
"Try again."
Did you solve it using a segment tree or??
I didn't solve it. Not because, ahem-ahem, I don't know segment tree. Certainly.
Lol
Has anyone solved problem E using Lagrange multipliers?
I tried $$$a_i = \lfloor\sqrt{\frac{M}{NP_i}}\rfloor$$$. This gets $$$\sum_{i=1}^{N}a_{i}^{2}P_{i}$$$ close to $$$M$$$, but I wasn't able to figure out how to use the leftover budget caused by the floor function.
Using at most 1 more of each price wont be enough, since the rounding from a large price could allow multiple smaller prices to work (at least this made me fail the second sample). Any ideas would be great
The sequence is on OEIS. https://oeis.org/A373193
(there's also https://oeis.org/A341198 as WA bait)
Solving F by performing binary search on segment tree. Narrowly pass with 800+ms. When calculating the complexity during contest, always worrying about TLE
how e
With Problem E
I change the value of inf in following code from 1e18+1 to 2e18+1 will result in different answer. Why this happend
//this is code using namespace std; int main() { int n; unsigned long long m; scanf("%d%lld", &n, &m); long long s = 0; long long ans = 0; vector a(n + 1); for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); } unsigned long long l = 0, r = m, mid; while (l <= r) { mid = (l + r) / 2; int128_t sum = 0; for (int i = 1; i <= n; ++i) { long long t = (mid + a[i]) / (2 * a[i]); sum += (int128_t)t * t * a[i]; } if (sum <= m) { l = mid + 1; } else { r = mid — 1; } } long long res = m; for (int i = 1; i <= n; ++i) { long long t = (r + a[i]) / (2 * a[i]); ans += t; res -= t * t * a[i]; } ans += res / (r + 1); printf("%lld\n", ans); return 0; } ~~~~~
Can someone explain the logic for E ? How is binary search applicable ?
it's pretty common trick: You need to pack the backpack with some items. And your task is to put the maximum number of items there. So logically, you'll put the cheapest items. So you perform the BS over the price of last item you can put there.
Hey, Can you please look at my solution, i think have done the same thing but i am not getting right answer, If possible please point out my mistake.
I understood most of the solution but I still don't get how dividing the remaining money by l+1 gives the right number of l+1 priced items.
How can we be sure that there are (money_left)/l+1 items available for purchase?
Thanks for showing concern on this, If there would be no i+1 items then binary search would have given i+1 as answer, so this means there are some i+1 items out there and also we can’t purchase all of them if we could then again we won't be having i as our binary search answer, it would be i+1, as we can buy all the products having price<=(i+1). So to do partial purchase rem_budget/(i+1) is i guess good. If you find any fallacy kindly report.
how do you know if your guess is actually correct(?). I wanted a more mathy proof if possible
did pretty poorly, only solved problem A but was really close to solving problem B and C.
I got TLE for problem C
Try to do it with queue and prefix sum.
thanks!
E > F ?
But I still solve E :)
Problem E can be ACed using the Cauchy–Schwarz inequality with real numbers, followed by removing sub-optimal buys using a heap.
https://atcoder.jp/contests/abc389/submissions/61842706
For problem E, why does solution says: "as well as as many items of price x+1 as possible."?
Why do we need to also take those items whose cost is (x + 1)?
We will take those, if there are 5 such items worth (k+1) each, and we have budget left of 2k+3, after buying all items having worth less than or equal to k, we will buy two (k+1) item also in order to maximize our output.
Thanks
Follow-up: If budget allows picking up say all items worth (x + 1), then why shall we not proceed to also pick higher rated items e.g. (x + 2)?
In that case, our binary search would yield us (x+1) not (x), if we can pick all x+1 item, moreover this also implies there will be indeed some items of(x+1) that will be out of our budget, if not our binary search would given us x+1. I hope this explains your query.
Edit: how do we ensure we will have enough k+1 items? For e.g. if we have the remaining sum worth 2k+2, how can we ensure that there will we at least 2 items worth exactly (k+1)
Hi, I solved 5th question, this is my code, can someone point out what is my mistake?
Can someone please find mistake.
it's failing 2nd sample test case, if it is possible to explain how answer is 53 it will be helpful too.
k*k*a[i] is the total price of k products, the price of the kth product should be (2*k-1)*a[i].
I am stuck in same doubt , I dont understand why calculating using sqrt is wrong. for checking how many k satisfy k^2*p[i] <= x .Why is this incorrect
For each i, check how many k_i satisfy (2*k_i-1)*a[i]<=x, and the sum of k_i^2*a[i] should be <= m.
I was trying to bruteforce with a heap , I do understand that the price of each product would be (2*k_i-1)*a[i] but i dont really understand why is the above comment incorrect it doesnt feel trivial/intituitive to me . Can you explain maybe why the search space for total price wouldnt be monotonic or whats the flaw here
It seems that you don't understand the meaning of x here. x is the upper limit of the purchase price of each product. For product i, the purchase quantity k must satisfy (2*k_i-1)*a[i]<=x.
Our goal is to find the largest x so that m is enough to buy all products with a price not exceeding x, and the remaining money can be used to buy products with a price of x+1. This x can be found by binary search x and checking the total price sum(k_i^2*a[i])<=m
I understand x represents cost of each unit of a[i], but i dont understand why we cant binary search on maximum cost we can spend at each index
how to avoid overflow in Problem E, can anybody help me ?
Give clarity on this please.
In problem E. It calculated a price x(using binary search) for which we can by all items with price <=x. Such that total cost is <=M but there will be some remaining money. why is this remaining money used to buy as many items as possible of price x+1. (remaining_money)/(x+1). How we know if item priced x+1 will exist with surety and we can buy as many as possible.
+1
remaining_money is not enough to buy all products with price x+1, otherwise x should be x+1.