We will hold AtCoder Beginner Contest 418.
- Contest URL: https://atcoder.jp/contests/abc418
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250809T2100&p1=248
- Duration: 100 minutes
- Writer: Nyaan, sheyasutaka
- Tester: toam, yuto1115
- Rated range: ~ 1999
- The point values: 100-200-350-425-475-550-650
We are looking forward to your participation!








I hope I can reach 800 in this contest.
let's gooo
rp++
Noticed that Problem C & D's scores are abnormal, also noticed that Problem E's score is just 50 points higher than D, so I think the contest will be a harder's one than before, and if I'm poor at D, I'll give it up and go to solve the E quickly.
Yes
rp+=inf
Please let me solve 3 problems,I am just a pupil;
The first three problems are easy enough for a pupil to solve.
And a genius(?) pupil (like me?) can solve more.
Fun fact: 418 is a joke http status code, which indicates that this server is a teapot and cannot provide coffee.
Does anyone has any idea on how to solve C?Mine's Binary Search only got 5 out of 11.Waiting for solutions.
Don't ask for solutions or help during the contest,please.
obviously don't discuss in contest, but since contest is over now,
I solved like this I can choose any x between b to sigma Ai
Now if b > max_element(A) then I cannot have b object of same flavor so cout<<-1<<'\n'; now case 2 If b<max_element(A) then I have to select at least n bags then as the opponent can choose all the different bags to give you to choose.
Now even if I select n bags I have now n different flavours so I need b-1 flavour of the same type from any of the choosen n flavours . How can I gurantee that I will end having atleast b-1 flavours of same type from rest ??
now each value of array has been decreased by 1
5 1 4 1 8 4 9 5 sort() --? 1 4 4 8 9 look for this test case after first operation my array looks something like this 0 3 3 7 9
now I have to make b-1 that is 4 so I have to take all the values before which is less than 4 in the new array .
So I have to take 0 +3 + 3 = 6
and also I have to take all the elements b-2 times which is at a index after the index of element >=b-1 and also I have to take b-1 time the same element to make it b why so because the opponent can take up to b-2 times any object as we have already used 1 of each in 1st operation so he cannot use b-1 times so he has to use b-2 times in order to maximize the x
.
Let the index of our use be i (the first number which is greater than equal to b-1)
then I need in short extra of
pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .
so In short I need
n+pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .where i>0 else i-1<0 so remove this
but If I dont want to change my array I can simply do
n+pref_sum[i-1]-i+(b-2)*(n-1-i)+(b-1).
why so ??
Figure it out youll understand better.
?I used binary search and got 100 points.
where Will I get the solutions?
After the contest,there will be "editorial" button on the problem statement page.Click it to go to the editorial.
Sometimes,in 20 minutes after the contest ends,there will be only Japanese editorials.Click the "Japanese Editorial" button to change.
will I get in english?
E is a weaker version of LeetCode 3625 as the latter doesn't ensure every three points are not colinear.
Problem E is similar to LeetCode 3625. Count Number of Trapezoids II, which appeared in the weekly contest three weeks ago.
The time limit is very bad in E.
true i had to use unordered map
same :(, spent so long debugging only to try that as a last ditch effort and it somehow worked.
My AC code without unordered_map: submissions:68368917 Is there any difference from your approach?
I used map during the contest and got AC *27,TLE *1.And I almost got mad during the contest.
In addition,my method have to put a
pair<long long,long long>and apair<pair<long long,long long>,long long>in theunordered_map,but when I do this,I have to write the hash function by myself.It's so awful.The difficulty of E just worth these things above.So I dislike it very much.It makes me got -17 delta.
I solve E with map. code
You're really lucky. Your maximum running time is 3990ms, which is only 10ms below the time limit.
I meet same problem at first.
So, I used discretization + binary search to reduce the constant factors and solve it.
I learned a lesson: don’t assume you’re just doing an ABC contest and neglect the constant factors.
realll
Yep, but I passed with map and fraction (a struct implemented by myself, used to do some calculations based on fractions).
The same
How to solve F?
ddp
So close yet so far on $$$E$$$ :(
Challenging. :)
How F and G?
Problem G is very similar to https://qoj.ac/problem/12010. It does a great job of popularizing the Myhill–Nerode theorem. However, its downside is that it’s a bit too “brainless,” as contestants can simply copy a template they’ve written before to pass. I only spent ten minutes on it.
edit: Here is another blog about Myhill–Nerode theorem(in Chinese): https://oi-wiki.org/misc/fsm/#myhillnerode-%E5%AE%9A%E7%90%86
E is just Count Number of Trapezoids II, but with the tough edge cases omitted due to the easier constraints.
My thoughts could not take me to final solution, All I observed is calculating slopes and count.
For a given slope count ct we could make C(ct,2) lines. Then stuck at removing parallelograms.Could you guide what to do next?
There can be two approaches:
These are the correct approaches esh_war2. The first one is relatively easier to implement.
Hey uttaran can we just connect over linkedin ?https://www.linkedin.com/in/eshwarr/
Accepted.
when will the final ratings update
ahhhhhh only 1 min to submit my AC code of E!!!! my solution
I am facing issue in understanding your code mainly in these steps
sum*(sum-1) no /2 here
we subtract (i.second)*(i.second-1)/2 (/2 here)
at the end ans/2
Could you explain how the extra counted parallelograms are getting subtracted.
if we just do sum*(sum-1)/2 at each step we will have extra parallelograms that I understood.
You can simply understand this as a whole concept. mp is about the mapping of edge directions, while mpp is the mapping of lengths for edges in the same direction. For each set of edges in every direction, it is always a trapezoid. And when calculating these quantities, parallelograms will be calculated twice. So let's think differently: calculate everything twice (sum*sum-1), and for all combinations of edges with equal lengths, they are only calculated once ((i.second)*(i.second-1)/2). They will definitely be calculated again in the other direction. So in the end, all combinations of four edges containing parallel edges will be calculated twice.
yeah I have understood that 4*p are included at first , then we are removing 2*p (here p represent count of parallelograms). Thanks
ABC are harder than CF div2 these days...
Screencast with commentary
lol :) lots of white iranian cheater guys ending in some suspicious numbers...
Is there an original question for this competition?(这场比赛有原题吗)
G trash casework solution: (Good means a string which can be reduced to "1")
0000: Only good is "1"
0001: Only good is all '1's
0010: Good if "1" or starts with 10 or (starts with "11" and has at least 3 1s)
0011: Good if starts with '1'
0100: Good if "1" or ends in "01" or (ends in "11" and has at least 3 1s)
0101: Good if ends in '1'
0110: Good if odd number of '1's
0111: Good if at least one '1'
1000: Bad if "0" or "01" or "10" or "11" or "000" or "101" or "111"
1001: Good if even number of '0's
1010: Bad if "0" or "01" or "11"
1011: Bad if "0" or "01111..."
1100: Bad if "0" or "10" or "11"
1101: Bad if "0" or "...111110"
1110: Bad if "0" or "11" or "101"
1111: Only bad is "0"
Many of the operations there are associative, and for some of them, you can obtain any number that you want if they have a small enough number of terms, you really have to do pattern matching for the remaining ones, that is, 2, 4, 11, 13.
Enumerating all theses cases during contest. (orz)
Here is my solution for C
I solved like this I can choose any x between b to sigma Ai
Now if b > max_element(A) then I cannot have b object of same flavor so cout<<-1<<'\n'; now case 2 If b<max_element(A) then I have to select at least n bags then as the opponent can choose all the different bags to give you to choose.
Now even if I select n bags I have now n different flavours so I need b-1 flavour of the same type from any of the choosen n flavours . How can I gurantee that I will end having atleast b-1 flavours of same type from rest ??
now each value of array has been decreased by 1
5 1 4 1 8 4 9 5 sort() --? 1 4 4 8 9 look for this test case after first operation my array looks something like this 0 3 3 7 9
now I have to make b-1 that is 4 so I have to take all the values before which is less than 4 in the new array .
So I have to take 0 +3 + 3 = 6
and also I have to take all the elements b-2 times which is at a index after the index of element >=b-1 and also I have to take b-1 time the same element to make it b why so because the opponent can take up to b-2 times any object as we have already used 1 of each in 1st operation so he cannot use b-1 times so he has to use b-2 times in order to maximize the x
.
Let the index of our use be i (the first number which is greater than equal to b-1)
then I need in short extra of
pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .
so In short I need
n+pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .where i>0 else i-1<0 so remove this
but If I dont want to change my array I can simply do
n+pref_sum[i-1]-i+(b-2)*(n-1-i)+(b-1).
why so ??
Figure it out youll understand better.
Did anyone faced similar situations in E?
I searched "trapezoid" in baidu, a Chinese search engine, and the first result was called "不规则四边形", which means "a flat shape with four straight sides, none of which are parallel", and I couldn't understand the example or its explanation, which also didn't explain what a trapezoid was...
I only understood it after seeing its further results called "a flat shape with four straight sides, one pair of opposite sides being parallel and the other pair not parallel". What's more, the online translation websites in China also gave me the first result I mentioned, so many other participants might be puzzled.
This is the issue of Baidu and your English.
Thanks, that hurts a lot (TAT)
Nowadays don't use Baidu as search engines.
You're right... i googled and the most of the results are correct...
but i also found this:
this might explain baidu's weird results.
You must be knowing about 'trapezoid' from basic geometry class. If you forgot that and don't look at the wikipedia page, unfortunately, it's on you.
bro, English is not my first language, so you really can't expect one to remember what a "trapezoid" is while learning "梯形" in Chinese.. I also mentioned above that
, so I wonder why no one else faced the same problem...
Actually, people faced the same problem. Even Um_nik mentioned it in his contest stream video.
Apologies, I thought you have read geometry in English. This is why I always prefer to study CS or Math concepts in English. But I understand that it might create a confusion. In my country, the definition is what the question asked for.
I think the E is easier than D.
D was really guessable and E had an annoyingly tight time limit, so I'd personally disagree.
how is it guessable ?
It's just if the count of zeroes is even. While I did a mini-proof in my head, it's not too difficult to guess that by looking at a couple of small examples and maybe quickly writing a bruteforce to check if it works on samples (which I also did).
ok next time will try to look for patterns by writing some test cases.
+1
In problem E I wanted to group edges by their slopes but I did not know how since slope take the form of x / y is there a trick for this ?
Create an object Slope which has two properties x and y.
That's good solution, thanks
Welcome.
Any clue why as to this submission to E gives TLE?
submission
dont use map use unordered_map with a hash for pair<int,int> , the extra logn factor got by using map is causing this issue.
Who can help me solve Problem C?I got 6 WA.I think my logic is correct. First Try Second
try using long long instead of int
I use ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); and then changed long long, That's work.Thank you for your advice.
How long before the English Editorial?
For question 2 considering the third given test case how can someone think they are only asking for character 't' and not for any other character?
From the conditions of filling rate.
800+. Alhamdulliah
How do ya'll deal with debugging when you can't see test cases? Even after the contest I couldn't figure out how (if possible at all) to view them. I'm fairly new to AtCoder so I could be missing something.
How to solve problem F — We're teapots ?
What i understood till now :
nlength array without constraints isrcoffee in n length such that any two cups has atleast one tea is(n-r+1) C rThis is the toughest problem I have seen till date. Either the implementation of this is crazy tough or I am missing something.
can anyone share the soln for E, like how to make sure that u dont take the same of set of 4 pts for a trapezium again, in case of a ||gm.
for ||gm sum of coordinates opposite vertices are equal.
x1 + x3 = x2 + x4
y1 + y3 = y2 + y4
thanks, gotcha
why this approach for D not works? first count all contiguous ones as they always lead to 1 so add all substring of that n*(n+1)/2 second count all contiguous zero which are even , they always lead to so add for 6 even zeros we have to add (6-1)+(6-3)+(6-5) we can make this AP series at last we have to add those transitions where one also present and then next we have even zeroes like 111000011 so this whole also results to 1 , calculation of all substring may be complex for this case ,
any other appraoch
This is a good solution to problem D by hitoare, can anyone explain it please :
Explanation
thanks, i solved it in the same way you mentioned. but i want to understand the solution of hitoare, to be exact the word "odd", look at this line :
odd pairity of positions of '0's.
watch umnik's screencast. He had explained.
How to do D?
Here you go.
you can solve it using dp also
// if (s[i] == '0') { // dp[i][1] = dp[i — 1][0]; // dp[i][0] = dp[i — 1][1] + 1; // } // else { // dp[i][1] = dp[i — 1][1] + 1; // dp[i][0] = dp[i — 1][0]; // } and then just add dp[i][1] for all i
For the people asking for the solution of D:
The XNOR operation is associative, meaning the order of operations doesn't matter. For a string the final character is simply the XNOR sum of all its characters. If you notice carefully, the final sum for a string is '1' if the number of '0's is even, and '0' if the number of '0's is odd. The number of '1's doesn't affect the result.
Now, our task is to calculate the number of indexes $$$[l,r]$$$ such that count of '0's in substring $$$S_l$$$...$$$S_r$$$ is even. A substring from index $$$l$$$ to $$$r$$$ has an even number of '0's if the number of '0's in the prefix up to $$$r$$$ and the number of '0's in the prefix up to $$$l−1$$$ have the same parity.
For for each index $$$i$$$ we will check the parity of the count of '0's till now, and store that value. In the final answer we will choose how many ways we can pick $$$[l,r]$$$ from the odd and even parity respectively which is just $$$C(parityCount,2)$$$ and add them together.
Was anyone able to solve F without BST?
I can see the Japanese Tutorial mentions set or segment tree. But I don't think I completely understand the implementation given there.
Actually it is called DDP (Dynamic DP), which means that you can modify some transactions of a normal DP and get the modified result quickly, without doing the DP again. A typical implementation of DDP is using matrix and segment tree.
Do you have any blog or some classical questions on this so that I can understand the topic better?
It seems that there are only few blogs talking about this topic. I can only find some blogs written in Chinese, like https://oi-wiki.org/dp/dynamic/ and https://zhuanlan.zhihu.com/p/665082087.
thanks!
Unfortunately, I spent too much time on problem E, since at first sight, I didn't pay too much attention to the condition that [No three points are co-linear].
However, fortunately, for problem F, I have met a similar idea (almost the same) just one week ago, which is Codeforces Round 612 (Div. 2) problem F. LCC.
The idea is that, we transform the dp equation into matrix-multiplication form, and for every query, we use segment tree to handle point-updating, so that the total complexity is O(2^3 n logn).
So, you could search how to solve Codeforces Round 612 (Div. 2) problem F, and after that, I think you can surely solve today's F as well.
3100 rated problem.
Yeah.. I think today's problem F is more difficult than usual ABC.
When is the editorial getting published.
Hope it will be published before next contest.
Bad time limit for E