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
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;
queue<pair<ll,ll>> snakes; ll global = 0; while(q--){ int tipo; cin >> tipo; if(tipo == 1){ ll l; cin >> l; if(snakes.empty()){ snakes.push({0,l}); }else{ snakes.push({snakes.back().f + snakes.back().s,l}); } }else if(tipo == 3){ int k; cin >> k; queue<pair<ll,ll>> copia = snakes; for(ll i = 1; i < k; i++){ copia.pop(); } cout << copia.front().f - global << endl; }else{ int m = snakes.front().s; snakes.pop(); global += m; } }} ~~~~~
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.
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 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
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?
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
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.
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
Hi, I solved 5th question, this is my code, can someone point out what is my mistake?
Can someone please find mistake.
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
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.